[ Infinity, 0.6666666666666666, 0.3333333333333333, 0.2, 0.14285714285714285, 0.1111111111111111, 0.09090909090909091, 0.07692307692307693, 0.06666666666666667, 0.058823529411764705, 0.25 ]
"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"TSeries t1 = new() {0,1,2,3,4,5,6,7,8,9}; // t1 is loaded with data and activated as a publisher\n",
"EMA_Series t2 = new(t1, 3); // t2 will auto-load all history of t1 and wait for events from t1\n",
"ADD_Series t3 = new(t1, t2); // t3 is an ADDition of t1 and t2 - will also load history and wait for t2 events\n",
"DIV_Series t4 = new(1, t3); // t4 is calculating 1/t3 - and waiting for t3 events\n",
"\n",
"TSeries t5 = new(); // a wild indicator appeared! And it is empty!\n",
"t4.Pub += t5.Sub; // let us add a manual subscription to events coming from t4 - t5 is now listening to t4\n",
"t1.Add(0); // we add one new value to t1 - and trigger the full cascade of calculation! t5 is now full!\n",
"\n",
"t5.v"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# MACD compounded indicator\n",
"\n",
"With QuanTAlib we can chain indicators together, creating complex compounded indicators. For example, we can create Moving Average Convergence/Divergence (MACD) indicators by chaining all required operations in a sequence:"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"dotnet_interactive": {
"language": "csharp"
}
},
"outputs": [
{
"data": {
"text/html": [
"[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -0.000974358974349343, -0.03456027049873228, -0.13792617985566447, -0.4729486712049916, -0.825402881197467, -0.8902360596814031, -0.9360607784903126, -0.7333381872239422 ... (79 more) ]
"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"Yahoo_Feed aapl = new(\"AAPL\", 100);\n",
"TSeries close = aapl.Close; // close will get data from history\n",
"EMA_Series slow = new(close,26); // slow gets data from slow through pub-sub eventing\n",
"EMA_Series fast = new(close,12); // fast gets data from slow (via eventing)\n",
"SUB_Series macd = new(fast,slow); // macd is a SUBtraction: fast-slow\n",
"EMA_Series signal = new(macd,9); // signal is EMA of macd\n",
"SUB_Series histogram = new(macd, signal); // histogram is SUBtraction macd-signal\n",
"\n",
"histogram.v\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".NET (C#)",
"language": "C#",
"name": ".net-csharp"
},
"language_info": {
"name": "polyglot-notebook"
},
"polyglot_notebook": {
"kernelInfo": {
"defaultKernelName": "csharp",
"items": [
{
"aliases": [
"C#",
"c#"
],
"languageName": "C#",
"name": "csharp"
},
{
"aliases": [],
"languageName": "KQL",
"name": "kql"
},
{
"aliases": [
"frontend"
],
"name": "vscode"
}
]
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}