风控模块Word格式.docx
- 文档编号:17475035
- 上传时间:2022-12-01
- 格式:DOCX
- 页数:12
- 大小:17.41KB
风控模块Word格式.docx
《风控模块Word格式.docx》由会员分享,可在线阅读,更多相关《风控模块Word格式.docx(12页珍藏版)》请在冰豆网上搜索。
=MyEntryPrice+TakeProfitSet*MinPoint)//止赢条件表达式
MyExitPrice=MyEntryPrice+TakeProfitSet*MinPoint;
If(Open>
MyExitPrice)MyExitPrice=Open;
//如果该Bar开盘价有跳空触发,则用开盘价代替
Sell(0,MyExitPrice);
}elseif(Low<
=MyEntryPrice-StopLossSet*MinPoint)//止损条件表达式
MyExitPrice=MyEntryPrice-StopLossSet*MinPoint;
If(Open<
}
}elseif(MarketPosition==-1)//有空仓的情况
If(Low<
=MyEntryPrice-TakeProfitSet*MinPoint)//止赢条件表达式
MyExitPrice=MyEntryPrice-TakeProfitSet*MinPoint;
BuyToCover(0,MyExitPrice);
}elseif(High>
=MyEntryPrice+StopLossSet*MinPoint)//止损条件表达式
MyExitPrice=MyEntryPrice+StopLossSet*MinPoint;
End
注意事项:
1.因无法确认开仓Bar最高/低价和开仓价的先后顺序,因此以上写法一般忽略开仓Bar的处理。
2.如果某个Bar最高/低价相差很大,可能出现止赢止损同时满足的情况,这种情况下需要切换到更小的周期进行交易,或者扩大止赢/损幅度。
二、比例止损止盈
NumericTakeProfitSet;
NumericStopLossSet;
...
MyEntryPrice=AvgEntryPrice;
TakeProfitSet=MyEntryPrice+MyEntryPrice*8%;
//止盈设置,本例为低于开仓价格的8%
StopLossSet=MyEntryPrice-MyEntryPrice*8%;
//止损设置,本例为低于开仓价格的8%
三、基于ATR的止盈
Params
NumericATRs(3);
//几倍ATR止盈,本例为3倍
NumericATRLength(10);
//ATR周期,本例为10
NumericMyExitPrice;
NumericATRVal;
//计算ATR
ATRVal=AvgTrueRange(ATRLength);
//开仓时根据开仓bar的ATR计算止盈价
If(MarketPosition==1AndBarsSinceEntry==0)
{
MyExitPrice=MyEntryPrice+ATRVal*ATRs;
}
ElseIf(MarketPosition==-1AndBarsSinceEntry==0)
MyExitPrice=MyEntryPrice-ATRVal*ATRs;
If(MarketPosition==1AndBarsSinceEntry>
0AndVol>
0)//有多仓的情况
=MyExitPrice)//止赢条件表达式
Sell(0,MAX(MyExitPrice,Open))
BuyToCover(0,MIN(Open,MyExitPrice));
}
ATR棘轮止损法
NumericLots
(1);
NumericnOffset(3);
NumericHLength(5);
NumericLLength(5);
NumericAtrLength(0.05);
NumericmyBarsSinceEntry(9);
NumericSeriesHHH;
NumericSeriesLLL;
NumericSeriesHHH1;
NumericSeriesLLL1;
NumericSeriesAtr;
NumericmyPrice;
NumericSeriesStopLine;
NumericSeriesLastPrice;
HHH=Highest(High,HLength);
LLL=Lowest(Low,LLength);
HHH1=Highest(High,10);
LLL1=Lowest(Low,10);
Atr=AvgTrueRange(10);
If(MarketPosition==1)
//LLL1=Max(LLL1,LastPrice);
LLL1=Max(LLL1,LLL1[1]);
//PlotNumeric("
LLL1"
LLL1);
If(BarsSinceEntry>
myBarsSinceEntry||High>
LastPrice+Atr[1])
StopLine=Max(StopLine,LLL1[1]+(BarsSinceEntry)*Atr[1]*AtrLength);
PlotNumeric("
多头止损:
"
StopLine);
If(Low<
StopLine)
myPrice=Min(Open,StopLine)-MinPoint*nOffset;
Sell(Lots,myPrice);
If(MarketPosition==-1)
//HHH1=Min(HHH1,LastPrice);
HHH1=Min(HHH1,HHH1[1]);
HHH1"
HHH1);
myBarsSinceEntry||Low<
LastPrice-Atr[1])
StopLine=Min(StopLine,HHH1[1]-(BarsSinceEntry)*Atr[1]*AtrLength);
空头止损:
If(High>
myPrice=Max(Open,StopLine)+MinPoint*nOffset;
BuyToCover(Lots,myPrice);
If(MarketPosition<
>
1)
HHH[1])
myPrice=Max(Open,HHH[1]);
Buy(Lots,myPrice+MinPoint*nOffset);
LastPrice=myPrice;
StopLine=myPrice-Atr[1]*1.5;
Return;
-1)
LLL[1])
myPrice=Min(Open,LLL[1]);
SellShort(Lots,myPrice-MinPoint*nOffset);
StopLine=myPrice+Atr[1]*1.5;
If(time==0.1510)
Sell(Lots,Open-MinPoint*nOffset);
BuyToCover(Lots,Open+MinPoint*nOffset);
跟踪止损
跟踪止损有很多种方式,本模板的规则如下:
当盈利达到50跳之后启动第一级跟踪止损,止损的回撤值为30跳,当盈利达到80跳之后启动第二级的跟踪止损,止损的回撤值为20跳。
您也可以将这些固定的设置修改为盈利百分比,或者是某个价格的百分比。
NumericTrailingStart1(50);
//跟踪止损启动设置1
NumericTrailingStart2(80);
//跟踪止损启动设置2
NumericTrailingStop1(30);
//跟踪止损设置1
NumericTrailingStop2(20);
//跟踪止损设置2
NumericStopLossSet(50);
NumericSeriesHighestAfterEntry;
//开仓后出现的最高价
NumericSeriesLowestAfterEntry;
//开仓后出现的最低价
If(BarsSinceentry==0)
HighestAfterEntry=Close;
LowestAfterEntry=Close;
If(MarketPosition<
0)
HighestAfterEntry=Max(HighestAfterEntry,AvgEntryPrice);
//开仓的Bar,将开仓价和当时的收盘价的较大值保留到HighestAfterEntry
LowestAfterEntry=Min(LowestAfterEntry,AvgEntryPrice);
//开仓的Bar,将开仓价和当时的收盘价的较小值保留到LowestAfterEntry
}else
HighestAfterEntry=Max(HighestAfterEntry,High);
//记录下当前Bar的最高点,用于下一个Bar的跟踪止损判断
LowestAfterEntry=Min(LowestAfterEntry,Low);
//记录下当前Bar的最低点,用于下一个Bar的跟踪止损判断
Commentary("
HighestAfterEntry="
+Text(HighestAfterEntry));
LowestAfterEntry="
+Text(LowestAfterEntry));
If(HighestAfterEntry[1]>
=MyEntryPrice+TrailingStart2*MinPoint)//第二级跟踪止损的条件表达式
=HighestAfterEntry[1]-TrailingStop2*MinPoint)
MyExitPrice=HighestAfterEntry[1]-TrailingStop2*MinPoint;
}elseif(HighestAfterEntry[1]>
=MyEntryPrice+TrailingStart1*MinPoint)//第一级跟踪止损的条件表达式
=HighestAfterEntry[1]-TrailingStop1*MinPoint)
MyExitPrice=HighestAfterEntry[1]-TrailingStop1*MinPoint;
=MyEntryPrice-StopLossSet*MinPoint)//可以在这里写上初始的止损处理
If(LowestAfterEntry[1]<
=MyEntryPrice-TrailingStart2*MinPoint)//第二级跟踪止损的条件表达式
=LowestAfterEntry[1]+TrailingStop2*MinPoint)
MyExitPrice=LowestAfterEntry[1]+TrailingStop2*MinPoint;
}elseif(LowestAfterEntry[1]<
=MyEntryPrice-TrailingStart1*MinPoint)//第一级跟踪止损的条件表达式
=LowestAfterEntry[1]+TrailingStop1*MinPoint)
MyExitPrice=LowestAfterEntry[1]+TrailingStop1*MinPoint;
}elseIf(High>
=MyEntryPrice+StopLossSet*MinPoint)//可以在这里写上初始的止损处理
2.如果某个Bar最高/低价相差很大,可能出现创新高之后跟踪止损的情况,但系统无法确认最高价和最低价的先后顺序,因此本模板只用前一个Bar的最高/低价计算最大赢利位置。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 模块