-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathLindaMACD_QT.cs
More file actions
82 lines (64 loc) · 2.36 KB
/
LindaMACD_QT.cs
File metadata and controls
82 lines (64 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Drawing;
using TradingPlatform.BusinessLayer;
namespace Oscillators;
public sealed class IndicatorMovingAverageConvergenceDivergence : Indicator, IWatchlistIndicator
{
private Indicator fastSMA;
private Indicator slowSMA;
private Indicator signal;
[InputParameter("Fast SMA Period", 0, 1, 999, 1, 0)]
public int FastPeriod = 3;
[InputParameter("Slow SMA Period", 1, 1, 999, 1, 0)]
public int SlowPeriod = 9;
[InputParameter("Signal SMA Period", 2, 1, 999, 1, 0)]
public int SignalPeriod = 16;
public int MinHistoryDepths => this.MaxEMAPeriod + this.SignalPeriod;
private int MaxEMAPeriod => Math.Max(this.FastPeriod, this.SlowPeriod);
public IndicatorMovingAverageConvergenceDivergence()
: base()
{
this.Name = "Linda MACD";
this.AddLineSeries("MACD", Color.DodgerBlue, 1, LineStyle.Solid);
this.AddLineSeries("HistogramPos", Color.Green, 10, LineStyle.Columns);
this.AddLineSeries("HistogramNeg", Color.Red, 10, LineStyle.Columns);
this.SeparateWindow = true;
}
protected override void OnInit()
{
this.fastSMA = Core.Indicators.BuiltIn.SMA(this.FastPeriod, PriceType.Typical);
this.slowSMA = Core.Indicators.BuiltIn.SMA(this.SlowPeriod, PriceType.Typical);
this.signal = Core.Indicators.BuiltIn.SMA(this.SignalPeriod, PriceType.Typical);
this.AddIndicator(this.fastSMA);
this.AddIndicator(this.slowSMA);
this.AddIndicator(this.signal);
}
protected override void OnUpdate(UpdateArgs args)
{
if (this.Count < 100)
return;
try
{
double fast = this.fastSMA.GetValue();
double slow = this.slowSMA.GetValue();
double sig = this.signal.GetValue();
double macdLine = fast - slow;
double histogram = macdLine - sig;
if (macdLine >= 0)
{
//this.SetValue(0);
this.SetValue(macdLine, 1);
this.SetValue(0, 2);
}
else
{
//this.SetValue(0);
this.SetValue(0, 1);
this.SetValue(Math.Abs(macdLine), 2);
}
}
catch (Exception)
{
}
}
}