-
Notifications
You must be signed in to change notification settings - Fork 1
/
ez_PATI.Indicator.CS
59 lines (48 loc) · 1.47 KB
/
ez_PATI.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
using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;
namespace PowerLanguage.Indicator{
public class ez_PATI : IndicatorObject {
[Input]
public int period { get; set; }
public ez_PATI(object _ctx):base(_ctx){
period = 10;
}
private IPlotObject plot1;
protected override void Create() {
// create variable objects, function objects, plot objects etc.
plot1 = AddPlot(new PlotAttributes("", EPlotShapes.Line, Color.Blue));
}
protected override void StartCalc() {
// assign inputs
}
protected override void CalcBar(){
// indicator logic
int numDojisOrMarubozus = 0;
for (int off = 0; off < period; off++)
{
if (isDoji(off) || isMarubozu(off))
{
numDojisOrMarubozus++;
}
}
double pati = (double)numDojisOrMarubozus / period;
if (pati > 0.5) {
Alerts.Alert("PATI over 0.5");
}
plot1.Set(0, pati, pati <= 0.5 ? Color.Blue : Color.Red);
}
private Boolean isDoji(int offset) {
return Bars.Open[offset] == Bars.Close[offset];
}
private Boolean isMarubozu(int offset)
{
double hi = Bars.High[offset];
double lo = Bars.Low[offset];
double clz = Bars.Close[offset];
double opn = Bars.Open[offset];
return hi == clz && lo == opn || lo == clz && hi == opn;
}
}
}