-
Notifications
You must be signed in to change notification settings - Fork 6
/
ATR_Trailing_LX.Strategy.CS
53 lines (43 loc) · 1.66 KB
/
ATR_Trailing_LX.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
using System;
using PowerLanguage.Function;
namespace PowerLanguage.Strategy
{
[IOGMode(IOGMode.Disabled)]
public class ATR_Trailing_LX : SignalObject
{
private VariableSeries<int> m_mp;
private VariableObject<Double> m_PosHigh;
private IOrderPriced m_AtrLX;
private IOrderPriced m_AtrLX_eb;
public ATR_Trailing_LX(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_PosHigh = new VariableObject<Double>(this);
m_AtrLX =
OrderCreator.Stop(new SOrderParameters(Contracts.Default, "AtrLX", EOrderAction.Sell,
OrderExit.FromAll));
m_AtrLX_eb =
OrderCreator.Stop(new SOrderParameters(Contracts.Default, "AtrLX-eb", EOrderAction.Sell,
OrderExit.FromAll));
}
protected override void CalcBar(){
var AtrValue = this.AverageTrueRange(AtrLength) *NumAtrs;
m_mp.Value = StrategyInfo.MarketPosition;
if (m_mp.Value > 0){
if (m_mp[1] <= 0 || PublicFunctions.DoubleGreater(Bars.High[0], m_PosHigh.Value))
m_PosHigh.Value = Bars.High[0];
m_AtrLX.Send(m_PosHigh.Value - AtrValue);
}
else
m_AtrLX_eb.Send(Bars.High[0] - AtrValue);
}
}
}