Files
QuanTAlib/docs/macd_example.ipynb
T
2022-11-06 17:20:57 -08:00

73 KiB

In [ ]:
// This is .NET Interactive Notebook. It can run in VS.Code with .NET interactive extension installed

#r "nuget: Plotly.NET, 2.0.0"
#r "nuget: Plotly.NET.Interactive, 2.0.0"
#r "nuget: QuanTAlib"

using Plotly.NET;
using Plotly.NET.LayoutObjects;
using QuanTAlib;
Installed Packages
  • Plotly.NET, 2.0.0
  • Plotly.NET.Interactive, 2.0.0
  • QuanTAlib, 0.1.13
In [ ]:
// defining the MACD model through clasess that connect to each other with Events

RND_Feed tsla = new(380);
TSeries close = tsla.Close;                 // close will get data from YAHOO tsla feed
EMA_Series slow = new(close,26);            // slow gets data from slow through pub-sub eventing
EMA_Series fast = new(close,12);            // fast gets data from slow (via eventing)
SUB_Series macd = new(fast,slow);           // macd is a SUBtraction of fast-slow
EMA_Series signal = new(macd,9);            // signal is EMA of macd
SUB_Series histogram = new(macd, signal);   // histogran is SUBtraction macd-signal

slow.Count
380
In [ ]:
tsla.Open.v
indexvalue
0
99.6
1
100.93
2
100.36
3
96.83
4
95.39
5
96.34
6
97.6
7
98.7
8
100.11
9
101.38
10
101.09
11
100.31
12
97.19
13
96.13
14
93.34
15
91.46
16
91.65
17
91.63
18
90.39
19
91.69
(360 more)
In [ ]:
//this is just a visualization of MACD using the (preview of) Plotly.NET

var candles = Chart2D.Chart.Candlestick<double, double, double, double, DateTime, string>(tsla.Open.v, tsla.High.v, tsla.Low.v, tsla.Close.v, tsla.Open.t, "candles");
var ch1 = Chart2D.Chart.Line<DateTime,double,bool>(macd.t,macd.v,false,"macd").WithLineStyle(Width: 2, Color: Color.fromString("red"));
var ch2 = Chart2D.Chart.Line<DateTime,double,bool>(signal.t,signal.v,false,"signal").WithLineStyle(Width: 1.5, Color: Color.fromString("green"));
//GenericChart.GenericChart hist = Chart2D.Chart.Column<DateTime,double,string,bool,bool>(histogram.t,histogram.v).WithLineStyle(Width: 1.5, Color: Color.fromString("green"));

var chart = Chart.Combine(new []{candles,ch1,ch2}).WithSize(1200,400).WithMargin(Margin.init<int, int, int, int, int, bool>(1,1,60,1,1,false)).WithTitle("MACD using EMA");

chart