-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathCrossovers_per_Bar.Indicator.CS
More file actions
59 lines (50 loc) · 1.92 KB
/
Crossovers_per_Bar.Indicator.CS
File metadata and controls
59 lines (50 loc) · 1.92 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
using System;
using System.Drawing;
namespace PowerLanguage.Indicator
{
public class Crossovers_per_Bar : IndicatorObject
{
private VariableObject<Int32> m_mycurrentbar;
private VariableObject<Double> m_crossovers;
private VariableObject<Boolean> m_lastbelow;
private IPlotObject Plot1;
public Crossovers_per_Bar(object ctx) :
base(ctx){
datanum = 1;
}
private ISeries<double> formula1 { get; set; }
[Input]
public double datanum { get; set; }
protected override void Create(){
m_mycurrentbar = new VariableObject<Int32>(this);
m_crossovers = new VariableObject<Double>(this);
m_lastbelow = new VariableObject<Boolean>(this);
Plot1 =
AddPlot(new PlotAttributes("Crossovers", EPlotShapes.Histogram,
Color.Cyan, Color.Empty, 0, 0,
true));
}
protected override void StartCalc(){
formula1 = Bars.Close;
}
protected override void CalcBar(){
var m_formula2 = Bars.Close.Average(9);
if ((Bars.LastBarOnChart && (Bars.Status != EBarState.Close))){
if (Bars.CurrentBar > m_mycurrentbar.Value){
m_crossovers.Value = 0;
m_mycurrentbar.Value = Bars.CurrentBar;
}
if ((PublicFunctions.DoubleGreater(formula1[0], m_formula2) && m_lastbelow.Value)){
m_crossovers.Value = (m_crossovers.Value + 1);
m_lastbelow.Value = false;
}
else{
if (PublicFunctions.DoubleLess(formula1[0], m_formula2)){
m_lastbelow.Value = true;
}
}
Plot1.Set(0, m_crossovers.Value);
}
}
}
}