-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathHPI.Indicator.CS
More file actions
115 lines (96 loc) · 3.66 KB
/
HPI.Indicator.CS
File metadata and controls
115 lines (96 loc) · 3.66 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using System;
using System.Drawing;
using PowerLanguage.Function;
namespace PowerLanguage.Indicator
{
public class HPI : IndicatorObject
{
private Function.HPI m_hpi1;
private NormGradientColor m_normgradientcolor1;
private VariableObject<Int32> m_applicationtype;
private VariableSeries<Double> m_hpivalue;
private Color m_colorlevel;
private IPlotObject Plot1;
private IPlotObject Plot2;
public HPI(object ctx) :
base(ctx){
gridforegroundcolor = Color.Black;
dncolor = Color.Cyan;
upcolor = Color.Yellow;
colornormlength = 14;
alertlength = 14;
smoothingfactor = 0.133;
onecent = 100;
}
[Input]
public double onecent { get; set; }
[Input]
public double smoothingfactor { get; set; }
[Input]
public int alertlength { get; set; }
[Input]
public int colornormlength { get; set; }
[Input]
public Color upcolor { get; set; }
[Input]
public Color dncolor { get; set; }
[Input]
public Color gridforegroundcolor { get; set; }
protected override void Create(){
m_hpi1 = new Function.HPI(this);
m_normgradientcolor1 = new Function.NormGradientColor(this);
m_applicationtype = new VariableObject<Int32>(this);
m_hpivalue = new VariableSeries<Double>(this);
Plot1 =
AddPlot(new PlotAttributes("HPI", 0, Color.Yellow,
Color.Empty, 0, 0, true));
Plot2 =
AddPlot(new PlotAttributes("ZeroLine", 0, Color.Green,
Color.Empty, 0, 0, true));
}
protected override void StartCalc(){
m_hpi1.onecent = onecent;
m_hpi1.smfactor = smoothingfactor;
m_normgradientcolor1.dataseriesvalue = m_hpivalue;
m_normgradientcolor1.crosseszero = true;
m_normgradientcolor1.colornormlength = colornormlength;
m_normgradientcolor1.upcolor = upcolor;
m_normgradientcolor1.dncolor = dncolor;
m_applicationtype.DefaultValue = 0;
m_hpivalue.DefaultValue = 0;
m_colorlevel = Color.Empty;
}
protected override void CalcBar(){
if (Bars.CurrentBar == 1){
m_applicationtype.Value = (Int32) Environment.ApplicationCode;
}
m_hpivalue.Value = m_hpi1[0]*1E-05;
Plot1.Set(0, m_hpivalue.Value);
Plot2.Set(0, 0);
if (Color.Empty != upcolor && Color.Empty != dncolor){
m_colorlevel = m_normgradientcolor1[0];
if (m_applicationtype.Value == 1){
Plot1.Colors[0] = m_colorlevel;
}
else{
if (m_applicationtype.Value > 1){
Plot1.Colors[0] = gridforegroundcolor;
Plot1.BGColor = m_colorlevel;
}
}
}
if (Bars.Close.LowestBar(alertlength) == 0
&& PublicFunctions.DoubleGreater(m_hpivalue.LowestBar(alertlength), 0))
{
Alerts.Alert("Bullish divergence - new low not confirmed");
}
else{
if (Bars.Close.HighestBar(alertlength) == 0
&& PublicFunctions.DoubleGreater(m_hpivalue.HighestBar(alertlength), 0))
{
Alerts.Alert("Bearish divergence - new high not confirmed");
}
}
}
}
}