mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-05 20:47:43 +00:00
250 lines
21 KiB
Plaintext
250 lines
21 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 44,
|
|
"metadata": {
|
|
"dotnet_interactive": {
|
|
"language": "csharp"
|
|
},
|
|
"vscode": {
|
|
"languageId": "dotnet-interactive.csharp"
|
|
}
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<div><div></div><div></div><div></div></div>"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"#r \"nuget: Plotly.NET;\"\n",
|
|
"#r \"nuget: Plotly.NET.ImageExport;\"\n",
|
|
"\n",
|
|
"using Plotly.NET;\n",
|
|
"using Plotly.NET.ImageExport;\n",
|
|
"\n",
|
|
"double ema(double data, double prev_ema, int period, double attenuator = 0.0) {\n",
|
|
" double k = 2.0 / (period + 1);\n",
|
|
" return ((data*k) + (prev_ema*(1-k)))/(1-attenuator);\n",
|
|
"}\n",
|
|
"\n",
|
|
"List<double> data = new() { 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}; \n",
|
|
"List<int> x = new() { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};\n",
|
|
"List<double> es = new();\n",
|
|
"List<double> e1 = new();\n",
|
|
"List<double> e2 = new();\n",
|
|
"List<double> e3 = new();"
|
|
]
|
|
},
|
|
{
|
|
"attachments": {},
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"EMA is a convergent moving average where we don't need to keep a list of past values around; all that is needed to calculate the next value of EMA is a previous value, factor k [ k = 2.0/(period+1) ] and new value.\n",
|
|
"\n",
|
|
"The core question is: how to START the EMA sequence?\n",
|
|
"\n",
|
|
"The most direct way is to start the EMA sequence with an arbitrary number - either zero or the first value are commonly accepted 'igniters' of the calculation. Except both starting values are wrong: \n",
|
|
"- starting EMA with the First Value creates overshooting EMA, requiring 50+ bars to converge to the correct series.\n",
|
|
"- starting EMA with a Zero undershoots the series, requiring 50+ bars to climb back to the correct series.\n",
|
|
"- starting EMA with a short SMA warming sequence at the beginning creates even more problems: transition from SMA to EMA is non-linear and results are not predictable.\n",
|
|
"\n",
|
|
"But there is a better way.\n",
|
|
"\n",
|
|
"I found an article on [David Owen's blog](https://blog.fugue88.ws/archives/2017-01/The-correct-way-to-start-an-Exponential-Moving-Average-EMA) that explains the math behind attenuation of early elements of EMA series.\n",
|
|
"\n",
|
|
"Below is the simple comparison of four approaches:\n",
|
|
"\n",
|
|
"- low EMA (series assumes that pre-value was 0)\n",
|
|
"- high EMA (series assumes that pre-value was same as the first value)\n",
|
|
"- SMA-EMA (series first calculates SMA for the duration of period and then uses the last SMA to calculate EMA)\n",
|
|
"- fixed EMA (uses diminishing attenuation to keep EMA between overshooting and undershooting EMA )\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 47,
|
|
"metadata": {
|
|
"dotnet_interactive": {
|
|
"language": "csharp"
|
|
},
|
|
"vscode": {
|
|
"languageId": "dotnet-interactive.csharp"
|
|
}
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"data\t low\t high\t s_ema fixed\t\r\n",
|
|
"1\t 0.222\t 1.000\t 1.000\t 1.000\t\r\n",
|
|
"0\t 0.173\t 0.778\t 0.500\t 0.560\t\r\n",
|
|
"0\t 0.134\t 0.605\t 0.333\t 0.393\t\r\n",
|
|
"0\t 0.105\t 0.471\t 0.250\t 0.294\t\r\n",
|
|
"0\t 0.081\t 0.366\t 0.200\t 0.226\t\r\n",
|
|
"0\t 0.063\t 0.285\t 0.167\t 0.175\t\r\n",
|
|
"1\t 0.271\t 0.444\t 0.286\t 0.358\t\r\n",
|
|
"1\t 0.433\t 0.567\t 0.375\t 0.501\t\r\n",
|
|
"1\t 0.559\t 0.663\t 0.514\t 0.611\t\r\n",
|
|
"1\t 0.657\t 0.738\t 0.622\t 0.698\t\r\n",
|
|
"1\t 0.733\t 0.796\t 0.706\t 0.765\t\r\n",
|
|
"0\t 0.570\t 0.619\t 0.549\t 0.595\t\r\n",
|
|
"0\t 0.444\t 0.482\t 0.427\t 0.463\t\r\n",
|
|
"0\t 0.345\t 0.375\t 0.332\t 0.360\t\r\n",
|
|
"0\t 0.268\t 0.291\t 0.258\t 0.280\t\r\n",
|
|
"0\t 0.209\t 0.227\t 0.201\t 0.218\t\r\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"int period = 18;\n",
|
|
"\n",
|
|
"double k = 2.0 / (period + 1);\n",
|
|
"double attenuator = ( 1 - k ) * 0.5;\n",
|
|
"double factor = 1;\n",
|
|
"double ema1 = 0; // start too low\n",
|
|
"double ema2 = data[0]; // start too high\n",
|
|
"double ema3 = data[0]*(1-k-attenuator)/(1-k); \n",
|
|
"double emas = data[0];\n",
|
|
"Console.WriteLine($\"data\\t low\\t high\\t s_ema fixed\\t\");\n",
|
|
"for (int i=0; i<data.Count; i++) {\n",
|
|
" factor *= attenuator;\n",
|
|
" ema1 = ema(data[i], ema1, period); e1.Add(ema1);\n",
|
|
" ema2 = ema(data[i], ema2, period); e2.Add(ema2);\n",
|
|
" ema3 = ema(data[i], ema3, period); e3.Add(ema3/(1-factor));\n",
|
|
" emas = (i<period)?data.GetRange(0, i+1).Average():ema(data[i], emas, period); es.Add(emas);\n",
|
|
" Console.WriteLine($\"{data[i]}\\t {e1[i]:f3}\\t {e2[i]:f3}\\t {es[i]:f3}\\t {e3[i]:f3}\\t\");\n",
|
|
"}"
|
|
]
|
|
},
|
|
{
|
|
"attachments": {},
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"dotnet_interactive": {
|
|
"language": "csharp"
|
|
}
|
|
},
|
|
"source": [
|
|
"Chart below shows different EMA calculations; note how \n",
|
|
"- SMA-EMA line abruptly breaks when it switches from SMA to EMA\n",
|
|
"- high EMA and low EMA form a converging channel; the higher the period, the longer is the channel\n",
|
|
"- fixed EMA starts with the value[0] but immediately attenuates to the middle of the channel (between high and low EMA)\n",
|
|
"\n",
|
|
"Feel free to play with parameters above (period and attenuator) and see how various EMAs react."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 48,
|
|
"metadata": {
|
|
"dotnet_interactive": {
|
|
"language": "csharp"
|
|
},
|
|
"vscode": {
|
|
"languageId": "dotnet-interactive.csharp"
|
|
}
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"\n",
|
|
"<div>\n",
|
|
" <div id=\"8f374733-c81c-4bdb-98b8-d52f22269b85\"><!-- Plotly chart will be drawn inside this DIV --></div>\r\n",
|
|
"<script type=\"text/javascript\">\r\n",
|
|
"\r\n",
|
|
" var renderPlotly_8f374733c81c4bdb98b8d52f22269b85 = function() {\r\n",
|
|
" var fsharpPlotlyRequire = requirejs.config({context:'fsharp-plotly',paths:{plotly:'https://cdn.plot.ly/plotly-2.6.3.min'}}) || require;\r\n",
|
|
" fsharpPlotlyRequire(['plotly'], function(Plotly) {\r\n",
|
|
"\r\n",
|
|
" var data = [{\"type\":\"scatter\",\"name\":\"Data\",\"mode\":\"lines+markers\",\"x\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16],\"y\":[1.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0],\"marker\":{},\"line\":{\"color\":\"blue\",\"width\":4.0}},{\"type\":\"scatter\",\"name\":\"s_ema\",\"mode\":\"lines+markers\",\"x\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16],\"y\":[1.0,0.5,0.3333333333333333,0.25,0.2,0.16666666666666666,0.2857142857142857,0.375,0.5138888888888888,0.6219135802469136,0.7059327846364883,0.5490588324950465,0.4270457586072584,0.33214670113897876,0.2583363231080946,0.20092825130629582,1.0,0.5,0.3333333333333333,0.25,0.2,0.16666666666666666,0.2857142857142857,0.375,0.4444444444444444,0.5,0.5454545454545454,0.5,0.46153846153846156,0.42857142857142855,0.4,0.375],\"marker\":{},\"line\":{\"color\":\"green\",\"width\":2.0}},{\"type\":\"scatter\",\"name\":\"low\",\"mode\":\"lines+markers\",\"x\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16],\"y\":[0.2222222222222222,0.1728395061728395,0.13443072702331962,0.1045572321292486,0.08132229165608225,0.06325067128806397,0.2714171887796053,0.4333244801619152,0.5592523734592674,0.6571962904683191,0.7333748925864704,0.5704026942339214,0.44364653995971665,0.3450584199686685,0.2683787710867422,0.20873904417857725,0.10526315789473684,0.09418282548476453,0.08426884385478932,0.07539843923849571,0.06746176142391722,0.06036052337929435,0.15926994197094757,0.24776784281611097,0.3269501751512572,0.3977975251353354,0.46118725933161586,0.412641232033551,0.3692053128721246,0.33034159572769045,0.2955687961774072,0.2644562913166275],\"marker\":{},\"line\":{\"color\":\"red\",\"width\":2.0}},{\"type\":\"scatter\",\"name\":\"high\",\"mode\":\"lines+markers\",\"x\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16],\"y\":[1.0,0.7777777777777778,0.6049382716049383,0.4705075445816187,0.3659503124523701,0.28462802079628785,0.44359957173044606,0.5672441113459025,0.6634120866023685,0.738209400690731,0.7963850894261242,0.6194106251092077,0.4817638195293838,0.37470519296729854,0.29143737230789885,0.22667351179503245,1.0,0.8947368421052632,0.8005540166204986,0.7162851727657094,0.6408867335272136,0.5734249721032963,0.6183276066187389,0.6585036480272927,0.6944506324454723,0.7266137237670016,0.7553912265283699,0.6758763605780151,0.6047314805171714,0.5410755351995744,0.4841202157048824,0.4331601929991053],\"marker\":{},\"line\":{\"color\":\"red\",\"width\":2.0}},{\"type\":\"scatter\",\"name\":\"fixed\",\"mode\":\"lines+markers\",\"x\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16],\"y\":[1.0,0.56,0.39278557114228463,0.2942627345844504,0.22564331487039727,0.1745430942857375,0.35798993932397283,0.5005461432339575,0.611456622894959,0.6977580482647523,0.7649035245617886,0.5949137777119198,0.46270733271632275,0.3598824576736433,0.2799082686667159,0.21770633756394203,1.0,0.6181818181818182,0.4859184531315678,0.41235902009127623,0.36063668755368716,0.3194536904220648,0.3901981763541162,0.4538639414038456,0.5110672347406993,0.5623862120453165,0.6083766388385358,0.5442937761012219,0.4869823978052273,0.43571416969724225,0.3898467491710628,0.34880914006837166],\"marker\":{},\"line\":{\"color\":\"purple\",\"width\":3.0}}];\r\n",
|
|
" var layout = {\"width\":\"100%\",\"height\":\"100%\",\"template\":{\"layout\":{\"title\":{\"x\":0.05},\"font\":{\"color\":\"rgba(42, 63, 95, 1.0)\"},\"paper_bgcolor\":\"rgba(255, 255, 255, 1.0)\",\"plot_bgcolor\":\"rgba(229, 236, 246, 1.0)\",\"autotypenumbers\":\"strict\",\"colorscale\":{\"diverging\":[[0.0,\"#8e0152\"],[0.1,\"#c51b7d\"],[0.2,\"#de77ae\"],[0.3,\"#f1b6da\"],[0.4,\"#fde0ef\"],[0.5,\"#f7f7f7\"],[0.6,\"#e6f5d0\"],[0.7,\"#b8e186\"],[0.8,\"#7fbc41\"],[0.9,\"#4d9221\"],[1.0,\"#276419\"]],\"sequential\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"sequentialminus\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]},\"hovermode\":\"closest\",\"hoverlabel\":{\"align\":\"left\"},\"coloraxis\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}},\"geo\":{\"showland\":true,\"landcolor\":\"rgba(229, 236, 246, 1.0)\",\"showlakes\":true,\"lakecolor\":\"rgba(255, 255, 255, 1.0)\",\"subunitcolor\":\"rgba(255, 255, 255, 1.0)\",\"bgcolor\":\"rgba(255, 255, 255, 1.0)\"},\"mapbox\":{\"style\":\"light\"},\"polar\":{\"bgcolor\":\"rgba(229, 236, 246, 1.0)\",\"radialaxis\":{\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\",\"ticks\":\"\"},\"angularaxis\":{\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\",\"ticks\":\"\"}},\"scene\":{\"xaxis\":{\"ticks\":\"\",\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\",\"gridwidth\":2.0,\"zerolinecolor\":\"rgba(255, 255, 255, 1.0)\",\"backgroundcolor\":\"rgba(229, 236, 246, 1.0)\",\"showbackground\":true},\"yaxis\":{\"ticks\":\"\",\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\",\"gridwidth\":2.0,\"zerolinecolor\":\"rgba(255, 255, 255, 1.0)\",\"backgroundcolor\":\"rgba(229, 236, 246, 1.0)\",\"showbackground\":true},\"zaxis\":{\"ticks\":\"\",\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\",\"gridwidth\":2.0,\"zerolinecolor\":\"rgba(255, 255, 255, 1.0)\",\"backgroundcolor\":\"rgba(229, 236, 246, 1.0)\",\"showbackground\":true}},\"ternary\":{\"aaxis\":{\"ticks\":\"\",\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\"},\"baxis\":{\"ticks\":\"\",\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\"},\"caxis\":{\"ticks\":\"\",\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\"},\"bgcolor\":\"rgba(229, 236, 246, 1.0)\"},\"xaxis\":{\"title\":{\"standoff\":15},\"ticks\":\"\",\"automargin\":true,\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\",\"zerolinecolor\":\"rgba(255, 255, 255, 1.0)\",\"zerolinewidth\":2.0},\"yaxis\":{\"title\":{\"standoff\":15},\"ticks\":\"\",\"automargin\":true,\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\",\"zerolinecolor\":\"rgba(255, 255, 255, 1.0)\",\"zerolinewidth\":2.0},\"annotationdefaults\":{\"arrowcolor\":\"#2a3f5f\",\"arrowhead\":0,\"arrowwidth\":1},\"shapedefaults\":{\"line\":{\"color\":\"rgba(42, 63, 95, 1.0)\"}},\"colorway\":[\"rgba(99, 110, 250, 1.0)\",\"rgba(239, 85, 59, 1.0)\",\"rgba(0, 204, 150, 1.0)\",\"rgba(171, 99, 250, 1.0)\",\"rgba(255, 161, 90, 1.0)\",\"rgba(25, 211, 243, 1.0)\",\"rgba(255, 102, 146, 1.0)\",\"rgba(182, 232, 128, 1.0)\",\"rgba(255, 151, 255, 1.0)\",\"rgba(254, 203, 82, 1.0)\"]},\"data\":{\"bar\":[{\"marker\":{\"line\":{\"color\":\"rgba(229, 236, 246, 1.0)\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"error_x\":{\"color\":\"rgba(42, 63, 95, 1.0)\"},\"error_y\":{\"color\":\"rgba(42, 63, 95, 1.0)\"}}],\"barpolar\":[{\"marker\":{\"line\":{\"color\":\"rgba(229, 236, 246, 1.0)\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}}}],\"carpet\":[{\"aaxis\":{\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\",\"endlinecolor\":\"rgba(42, 63, 95, 1.0)\",\"minorgridcolor\":\"rgba(255, 255, 255, 1.0)\",\"startlinecolor\":\"rgba(42, 63, 95, 1.0)\"},\"baxis\":{\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\",\"endlinecolor\":\"rgba(42, 63, 95, 1.0)\",\"minorgridcolor\":\"rgba(255, 255, 255, 1.0)\",\"startlinecolor\":\"rgba(42, 63, 95, 1.0)\"}}],\"choropleth\":[{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"contour\":[{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"contourcarpet\":[{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}}],\"heatmap\":[{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"heatmapgl\":[{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"histogram\":[{\"marker\":{\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}}}],\"histogram2d\":[{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"histogram2dcontour\":[{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"mesh3d\":[{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}}],\"parcoords\":[{\"line\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}}}],\"pie\":[{\"automargin\":true}],\"scatter\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}}}],\"scatter3d\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}},\"line\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}}}],\"scattercarpet\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}}}],\"scattergeo\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}}}],\"scattergl\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}}}],\"scattermapbox\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}}}],\"scatterpolar\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}}}],\"scatterpolargl\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}}}],\"scatterternary\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}}}],\"surface\":[{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"table\":[{\"cells\":{\"fill\":{\"color\":\"rgba(235, 240, 248, 1.0)\"},\"line\":{\"color\":\"rgba(255, 255, 255, 1.0)\"}},\"header\":{\"fill\":{\"color\":\"rgba(200, 212, 227, 1.0)\"},\"line\":{\"color\":\"rgba(255, 255, 255, 1.0)\"}}}]}},\"margin\":{\"l\":30,\"r\":10,\"t\":40,\"b\":30,\"pad\":1,\"autoexpand\":false},\"xaxis\":{\"rangeslider\":{\"visible\":false,\"yaxis\":{}}}};\r\n",
|
|
" var config = {\"responsive\":true};\r\n",
|
|
" Plotly.newPlot('8f374733-c81c-4bdb-98b8-d52f22269b85', data, layout, config);\r\n",
|
|
"});\r\n",
|
|
" };\r\n",
|
|
" if ((typeof(requirejs) !== typeof(Function)) || (typeof(requirejs.config) !== typeof(Function))) {\r\n",
|
|
" var script = document.createElement(\"script\");\r\n",
|
|
" script.setAttribute(\"src\", \"https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js\");\r\n",
|
|
" script.onload = function(){\r\n",
|
|
" renderPlotly_8f374733c81c4bdb98b8d52f22269b85();\r\n",
|
|
" };\r\n",
|
|
" document.getElementsByTagName(\"head\")[0].appendChild(script);\r\n",
|
|
" }\r\n",
|
|
" else {\r\n",
|
|
" renderPlotly_8f374733c81c4bdb98b8d52f22269b85();\r\n",
|
|
" }\r\n",
|
|
"</script>\r\n",
|
|
"\n",
|
|
" \n",
|
|
"</div> \n"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"var d = Chart2D.Chart.Line<int,double,bool>(x, data, true, \"Data\").WithLineStyle(Width: 4, Color: Color.fromString(\"blue\"));\n",
|
|
"var le = Chart2D.Chart.Line<int,double,bool>(x, es, true, \"s_ema\").WithLineStyle(Width: 2, Color: Color.fromString(\"green\"));\n",
|
|
"var le1 = Chart2D.Chart.Line<int,double,bool>(x, e1, true, \"low\").WithLineStyle(Width: 2, Color: Color.fromString(\"red\"));\n",
|
|
"var le2 = Chart2D.Chart.Line<int,double,bool>(x, e2, true, \"high\").WithLineStyle(Width: 2, Color: Color.fromString(\"red\"));\n",
|
|
"var le3 = Chart2D.Chart.Line<int,double,bool>(x, e3, true, \"fixed\").WithLineStyle(Width: 3, Color: Color.fromString(\"purple\"));\n",
|
|
"var chart = Chart.Combine(new []{d,le,le1,le2,le3})\n",
|
|
" .WithSize(1200,600)\n",
|
|
" .WithMargin(Margin.init<int, int, int, int, int, bool>(30,10,40,30,1,false))\n",
|
|
" .WithXAxisRangeSlider(RangeSlider.init(Visible:false));\n",
|
|
"\n",
|
|
"chart.SavePNG(\"ema_study\");\n",
|
|
"chart"
|
|
]
|
|
},
|
|
{
|
|
"attachments": {},
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"dotnet_interactive": {
|
|
"language": "csharp"
|
|
},
|
|
"vscode": {
|
|
"languageId": "dotnet-interactive.csharp"
|
|
}
|
|
},
|
|
"source": [
|
|
""
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": ".NET (C#)",
|
|
"language": "C#",
|
|
"name": ".net-csharp"
|
|
},
|
|
"language_info": {
|
|
"file_extension": ".cs",
|
|
"mimetype": "text/x-csharp",
|
|
"name": "C#",
|
|
"pygments_lexer": "csharp",
|
|
"version": "9.0"
|
|
},
|
|
"orig_nbformat": 4,
|
|
"vscode": {
|
|
"interpreter": {
|
|
"hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
|
|
}
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|