-
Notifications
You must be signed in to change notification settings - Fork 6
/
ATR_Trgt_And_Trail_LX.Strategy.CS
60 lines (49 loc) · 1.8 KB
/
ATR_Trgt_And_Trail_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
54
55
56
57
58
59
60
using System;
using PowerLanguage.Function;
namespace PowerLanguage.Strategy
{
[IOGMode(IOGMode.Disabled)]
public class ATR_Trgt_And_Trail_LX : SignalObject
{
private VariableSeries<int> m_mp;
private VariableObject<Double> m_TargetPrice;
private IOrderPriced m_ATTLX_Tgt;
private IOrderPriced m_ATTLX_Trl;
public ATR_Trgt_And_Trail_LX(object ctx) :
base(ctx){
NumBars = 5;
NumAtrs = 2;
AtrLength = 5;
}
[Input]
public int AtrLength { get; set; }
[Input]
public int NumAtrs { get; set; }
[Input]
public int NumBars { get; set; }
protected override void Create(){
m_mp = new VariableSeries<int>(this);
m_ATTLX_Tgt =
OrderCreator.Limit(new SOrderParameters(Contracts.Default, "ATTLX-Tgt", EOrderAction.Sell,
OrderExit.FromAll));
m_ATTLX_Trl =
OrderCreator.Stop(new SOrderParameters(Contracts.Default, "ATTLX-Trl", EOrderAction.Sell,
OrderExit.FromAll));
m_TargetPrice = new VariableObject<double>(this);
}
protected override void CalcBar(){
m_mp.Value = StrategyInfo.MarketPosition;
if (m_mp.Value > 0){
if (m_mp[1] <= 0){
m_TargetPrice.Value = this.EntryPrice() + this.AverageTrueRange(AtrLength) *NumAtrs;
}
if (this.BarsSinceEntry() < NumBars){
m_ATTLX_Tgt.Send(m_TargetPrice.Value);
}
else{
m_ATTLX_Trl.Send(Bars.Low[0]);
}
}
}
}
}