-
Notifications
You must be signed in to change notification settings - Fork 6
/
Correlation.Indicator.CS
69 lines (56 loc) · 2.05 KB
/
Correlation.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
using System;
using System.Drawing;
namespace PowerLanguage.Indicator
{
public class Correlation : IndicatorObject
{
private VariableSeries<Double> m_correlval;
private IPlotObject Plot1;
private IPlotObject Plot2;
private IPlotObject Plot3;
public Correlation(object ctx) :
base(ctx){
negcorralert = -0.7;
poscorralert = 0.7;
length = 14;
}
private ISeries<double> indepdata { get; set; }
private ISeries<double> depdata { get; set; }
[Input]
public int length { get; set; }
[Input]
public double poscorralert { get; set; }
[Input]
public double negcorralert { get; set; }
protected override void Create(){
m_correlval = new VariableSeries<Double>(this);
Plot1 =
AddPlot(new PlotAttributes("Correl", 0, Color.Yellow,
Color.Empty, 0, 0, true));
Plot2 =
AddPlot(new PlotAttributes("PosCorrAlert", 0, Color.Green,
Color.Empty, 0, 0, true));
Plot3 =
AddPlot(new PlotAttributes("NegCorrAlert", 0, Color.Green,
Color.Empty, 0, 0, true));
}
protected override void StartCalc(){
indepdata = Bars.Close;
depdata = BarsOfData(2).Close;
}
protected override void CalcBar(){
m_correlval.Value = Function.Correlation.CalcCorrelation(indepdata, depdata, length);
Plot1.Set(0, m_correlval.Value);
Plot2.Set(0, poscorralert);
Plot3.Set(0, negcorralert);
if (this.CrossesOver(m_correlval, poscorralert)){
Alerts.Alert("Positive correlation alert");
}
else{
if (this.CrossesUnder(m_correlval, negcorralert)){
Alerts.Alert("Negative correlation alert");
}
}
}
}
}