- 精华
- 0
- 在线时间
- 243 小时
- UID
- 222769
- 积分
- 175
- 帖子
- 104
- 阅读权限
- 40
- 注册时间
- 2015-11-7
- 最后登录
- 2021-2-26
- 精华
- 0
- UID
- 222769
- 积分
- 175
- 帖子
- 104
- 主题
- 41
- 阅读权限
- 40
- 注册时间
- 2015-11-7
- 最后登录
- 2021-2-26
|
本帖最后由 cts2015deng 于 2016-3-16 17:38 编辑
在ZN 上最大亏损为20跳在当天,依然是执行了最后一条语句
Params
Numeric ceilingAmt(60); // 自适应参数的上限
Numeric floorAmt(20); // 自适应参数的下限
Numeric bolBandTrig(1.5); // 布林通道参数
Numeric Lots(2); // 交易手数
Numeric a(2);
Numeric jx(120);
Numeric b(14);
Numeric StopLossSet(20); // 止损设置
Numeric rsi2(80);
Vars
Numeric MyEntryPrice; // 开仓价格,本例是开仓均价,也可根据需要设置为某次入场的价格
Numeric TakeProfitSet(30); // 止赢设置
NumericSeries rsi1(0);
Numeric MyExitPrice; // 平仓价格
Numeric Minpoint;
Numeric lookBackDays(20); // 自适应参数
NumericSeries todayVolatility(0); // 当日市场波动
Numeric yesterDayVolatility(0); // 昨日市场波动
Numeric deltaVolatility(0); // 市场波动的变动率
NumericSeries buyPoint(0); // 自适应唐奇安通道上轨
NumericSeries sellPoint(0); // 自适应唐奇安通道下轨
NumericSeries LiqPoint(0); // 自适应出场均线
NumericSeries Value1;
NumericSeries MidLine(0); // 布林通道中轨
Numeric Band(0);
NumericSeries upBand(0); // 布林通道上轨
NumericSeries dnBand(0); // 布林通道下轨
NumericSeries StandardDev1(8);
BoolSeries con1;
BoolSeries con2;
Begin
// 集合竞价和小节休息过滤
If(!CallAuctionFilter()) Return;
Minpoint=MinMove*PriceScale;
// 当日市场波动
todayVolatility = StandardDev(Close,30,1);
//If(c[1]>o[1])
//PlotString("a",Text(todayVolatility),h[3]+5,red,4);
// 昨日市场波动
yesterDayVolatility = todayVolatility[1];
// 市场波动的变动率
deltaVolatility = (todayVolatility - yesterDayVolatility)/todayVolatility;
// 计算自适应参数
lookBackDays = lookBackDays*(1 + deltaVolatility);
lookBackDays = Round(lookBackDays,0);
lookBackDays = Min(lookBackDays,ceilingAmt);
lookBackDays = Max(lookBackDays,floorAmt);
// 自适应布林通道中轨
MidLine = sma(Close,lookBackDays);
Band = StandardDev(Close,lookBackDays,2);
// 自适应布林通道上轨
upBand = MidLine + bolBandTrig*Band;
// 自适应布林通道下轨
dnBand = MidLine - bolBandTrig*Band;
//PlotNumeric("up",upband,green);
//PlotNumeric("midline",midline,red);
//PlotNumeric("up",dnBand,blue);
// 自适应唐奇安通道上轨
buyPoint = Highest(High,lookBackDays);
// 自适应唐奇安通道下轨
sellPoint = Lowest(Low,lookBackDays);
// 自适应出场均线
LiqPoint = MidLine;
StandardDev1=todayVolatility;
// 昨日价格大于布林通道上轨,并且当日价格大于唐奇安通道上轨,开多单and StandardDev1[1]<band
If(MarketPosition != 1 And Close[1] > upBand[1] And High >= buyPoint[1] ) Buy(Lots,Max(Open+Minpoint,buyPoint[1]+Minpoint) );
// 持有多单时,昨日价格小于布林通道下轨,并且当日价格小于唐奇安通道下轨,平多单
MyExitPrice=AvgEntryPrice;
If(MarketPosition == 1 And Close[1] < dnBand[1] And Low <= sellPoint[1]-a*minpoint) Sell(0,Min(Open-Minpoint,sellPoint[1]-Minpoint));
// 持有多单时,价格小于自适应出场均线,平多单
If(MarketPosition==1) // 有多仓的情况
{ if(Low <= MyEntryPrice - StopLossSet*MinPoint)// 限制最大亏损
{
MyExitPrice = MyEntryPrice - StopLossSet*MinPoint;
If(Open < MyExitPrice) MyExitPrice = Open; // 如果该Bar开盘价有跳空触发,则用开盘价代替
Sell(0,MyExitPrice);
}}
If(MarketPosition == 1 And BarsSinceEntry >= 1 And Low <= LiqPoint[1]-a*minpoint) {Sell(0,Min(Open-Minpoint,LiqPoint[1]-Minpoint));}
End
|
|