-
Notifications
You must be signed in to change notification settings - Fork 6
/
Consecutive_Ups_Downs.Strategy.CS
71 lines (58 loc) · 1.97 KB
/
Consecutive_Ups_Downs.Strategy.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
using System;
namespace PowerLanguage.Strategy
{
[IOGMode(IOGMode.Disabled)]
public class Consecutive_Ups_Downs : SignalObject
{
private ISeries<Double> m_price;
private VariableObject<int> m_ups_cnt;
private VariableObject<int> m_downs_cnt;
private IOrderMarket m_ConsUpLE;
private IOrderMarket m_ConsDnSE;
public Consecutive_Ups_Downs(object ctx) :
base(ctx)
{
ConsecutiveBarsUp = 3;
ConsecutiveBarsDown = 3;
}
private ISeries<Double> price{
get { return m_price; }
}
[Input]
public int ConsecutiveBarsUp { get; set; }
[Input]
public int ConsecutiveBarsDown { get; set; }
protected override void Create(){
m_ConsUpLE =
OrderCreator.MarketNextBar(new SOrderParameters(Contracts.Default, "ConsUpLE", EOrderAction.Buy));
m_ConsDnSE =
OrderCreator.MarketNextBar(new SOrderParameters(Contracts.Default, "ConsDnSE",
EOrderAction.SellShort));
m_ups_cnt = new VariableObject<int>(this);
m_downs_cnt = new VariableObject<int>(this);
}
protected override void StartCalc(){
m_price = Bars.Close;
}
protected override void CalcBar(){
if (PublicFunctions.DoubleGreater(price[0], price[1])){
++m_ups_cnt.Value;
}
else{
m_ups_cnt.Value = 0;
}
if (PublicFunctions.DoubleLess(price[0], price[1])){
++m_downs_cnt.Value;
}
else{
m_downs_cnt.Value = 0;
}
if (m_ups_cnt.Value >= ConsecutiveBarsUp){
m_ConsUpLE.Send();
}
if (m_downs_cnt.Value >= ConsecutiveBarsDown){
m_ConsDnSE.Send();
}
}
}
}