-
Notifications
You must be signed in to change notification settings - Fork 6
/
Arms_Index_TRIN.Indicator.CS
87 lines (69 loc) · 2.64 KB
/
Arms_Index_TRIN.Indicator.CS
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
83
84
85
86
87
using System;
using System.Drawing;
using PowerLanguage.Function;
namespace PowerLanguage.Indicator
{
public class Arms_Index_TRIN : IndicatorObject
{
private VariableSeries<Double> m_trin;
private VariableSeries<Double> m_avgtrin;
private IPlotObject Plot1;
private IPlotObject Plot2;
private IPlotObject Plot3;
private IPlotObject Plot4;
public Arms_Index_TRIN(object ctx) :
base(ctx){
overbought = 0.7;
oversold = 1.25;
smoothinglength = 4;
}
private ISeries<double> advissues { get; set; }
private ISeries<double> advvol { get; set; }
private ISeries<double> decissues { get; set; }
private ISeries<double> decvol { get; set; }
[Input]
public int smoothinglength { get; set; }
[Input]
public double oversold { get; set; }
[Input]
public double overbought { get; set; }
protected override void Create(){
m_trin = new VariableSeries<Double>(this);
m_avgtrin = new VariableSeries<Double>(this);
Plot1 =
AddPlot(new PlotAttributes("ArmsX", 0, Color.Yellow,
Color.Empty, 0, 0, true));
Plot2 =
AddPlot(new PlotAttributes("ArmsXAvg", 0, Color.Magenta,
Color.Empty, 0, 0, true));
Plot3 =
AddPlot(new PlotAttributes("OverSld", 0, Color.Green,
Color.Empty, 0, 0, true));
Plot4 =
AddPlot(new PlotAttributes("OverBot", 0, Color.Green,
Color.Empty, 0, 0, true));
}
protected override void StartCalc(){
advissues = Bars.Close;
advvol = BarsOfData(2).Close;
decissues = BarsOfData(3).Close;
decvol = BarsOfData(4).Close;
}
protected override void CalcBar(){
m_trin.Value = ArmsIndex.Calc(advissues, advvol, decissues, decvol);
m_avgtrin.Value = m_trin.Average(smoothinglength);
Plot1.Set(0, m_trin.Value);
Plot2.Set(0, m_avgtrin.Value);
Plot3.Set(0, oversold);
Plot4.Set(0, overbought);
if (this.CrossesUnder(m_avgtrin, oversold)){
Alerts.Alert("Indicator exiting oversold zone");
}
else{
if (this.CrossesOver(m_avgtrin, overbought)){
Alerts.Alert("Indicator exiting overbought zone");
}
}
}
}
}