開拓者 TB 按比例止損 源碼范例
作者:開拓者 TB 來源:cxh99.com 發布時間:2012年12月07日
- 內容源碼:
Params
Numeric trailingstop(0.5);
Numeric TrailingStart(2);
。。。。。
Vars
NumericSeries HigherAfterEntry;
NumericSeries LowerAfterEntry;
BoolSeries bLongTrailingStoped;
BoolSeries bShortTrailingStoped;
。。。。。。
Else If(MarketPosition<>0)
{
If(MarketPosition==1)
{
If(Close[1]<AvgValue[1])
{
MyPrice=Open;
Sell(0,MyPrice);
}
Else If(HigherAfterEntry>=AvgEntryPrice+AvgEntryPrice*TrailingStart*0.01)
{
If(Low <= HigherAfterEntry -(HigherAfterEntry-AvgEntryPrice)*TrailingStop*0.01)
{
MyPrice = HigherAfterEntry -(HigherAfterEntry-AvgEntryPrice)*TrailingStop*0.01;
If(Open < MyPrice) MyPrice = Open;
Sell(1,MyPrice);
bLongTrailingStoped = True;
}
}
}
Else if(MarketPosition==-1)
{
if(Close[1]>AvgValue[1])
{
MyPrice=Open;
BuyToCover(0,MyPrice);
}
Else If(LowerAfterEntry<=AvgEntryPrice-AvgEntryPrice*TrailingStart*0.01)
{
If(High >= LowerAfterEntry + (AvgEntryPrice-LowerAfterEntry)*TrailingStop*0.01)
{
MyPrice = LowerAfterEntry + (AvgEntryPrice-LowerAfterEntry)*TrailingStop*0.01;
If(Open > MyPrice) MyPrice = Open;
BuyToCover(1,MyPrice);
bShortTrailingStoped= True;
}
}
}
}
End