-
Notifications
You must be signed in to change notification settings - Fork 6
/
ATR_Trailing_SX.Strategy.CS
58 lines (47 loc) · 1.72 KB
/
ATR_Trailing_SX.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
using System;
using PowerLanguage.Function;
namespace PowerLanguage.Strategy
{
[IOGMode(IOGMode.Disabled)]
public class ATR_Trailing_SX : SignalObject
{
private VariableSeries<int> m_mp;
private VariableObject<Double> m_PosLow;
private IOrderPriced m_AtrSX;
private IOrderPriced m_AtrSX_eb;
public ATR_Trailing_SX(object ctx) :
base(ctx){
NumAtrs = 3;
AtrLength = 10;
}
[Input]
public int AtrLength { get; set; }
[Input]
public int NumAtrs { get; set; }
protected override void Create(){
m_mp = new VariableSeries<int>(this);
m_PosLow = new VariableObject<Double>(this);
m_AtrSX =
OrderCreator.Stop(new SOrderParameters(Contracts.Default, "AtrSX", EOrderAction.BuyToCover,
OrderExit.FromAll));
m_AtrSX_eb =
OrderCreator.Stop(new SOrderParameters(Contracts.Default, "AtrSX-eb", EOrderAction.BuyToCover,
OrderExit.FromAll));
}
protected override void CalcBar(){
double AtrVal = this.AverageTrueRange(AtrLength) * NumAtrs;
m_mp.Value = StrategyInfo.MarketPosition;
if (m_mp.Value < 0)
{
if (m_mp[1] >= 0 || PublicFunctions.DoubleLess(Bars.Low[0], m_PosLow.Value))
{
m_PosLow.Value = Bars.Low[0];
}
m_AtrSX.Send(m_PosLow.Value + AtrVal);
}
else{
m_AtrSX_eb.Send(Bars.Low[0] + AtrVal);
}
}
}
}