动态突破系统,TB里其实也做了大量解读,大家自己打开也可以看到,我这里也就多加一点解读,完善一下而已。策略说明我直接复制过来了,主要做的是解读代码,而不是这个系统好坏的判断。
策略说明:
基于自适应的布林通道与自适应的唐奇安通道的突破系统
系统要素:
1、自适应布林通道
2、自适应唐奇安通道
3、自适应出场均线
入场条件:
1、昨日价格大于布林通道上轨,并且当日周期价格大于唐奇安通道上轨,开多单
2、昨日价格小于布林通道下轨,并且当日周期价格小于唐奇安通道下轨,开空单
出场条件:
1、持有多单时,价格小于自适应出场均线,平多单
2、持有空单时,价格大于自适应出场均线,平空单
注 意:
此公式仅做多
以上这些就是系统的策略说明了,对我来说,基本没啥用的,但是对唐奇安通道我是很上心的,以前刚看海归交易代码,一直不怎么理解,也不知道这通道用来干嘛的,这回解读了才明白了。
好了,不说废话,我们直接看代码及解读吧,如下:
Params
Numeric ceilingAmt(60); // 声明数值参数ceilingAmt,初值60,即自适应参数的上限。//
Numeric floorAmt(20); // 声明数值参数floorAmt,初值20,即自适应参数的下限。//
Numeric bolBandTrig(2); // 声明数值参数bolBandTrig,初值2,即布林通道参数。//
Numeric Lots(0); // 声明数值参数Lots,初值0,即交易手数。//
Vars
Numeric lookBackDays(20); // 声明数值变量lookBackDays,初值20,即自适应参数。//
NumericSeries todayVolatility(0); // 声明数值序列变量todayVolaility,初值0,即当日市场波动。//
Numeric yesterDayVolatility(0); // 声明数值变量yesterDayVolatility,初值0,即昨日市场波动。//
Numeric deltaVolatility(0); // 声明数值变量deltaVolatility,初值0,即市场波动的变动率。//
NumericSeries buyPoint(0); // 声明数值序列变量buyPoint,初值0,即自适应唐奇安通道上轨。//
NumericSeries sellPoint(0); //声明数值序列变量sellPoint,初值0,即 自适应唐奇安通道下轨。//
NumericSeries LiqPoint(0); // 声明数值序列变量LiqPoint,初值0,即自适应出场均线。//
NumericSeries MidLine(0); // 声明数值序列变量MidLine,初值0,即布林通道中轨。//
Numeric Band(0); //声明数值变量Band,初值0,即标准偏差。//
NumericSeries upBand(0); // 声明数值序列变量upBand,初值0,即布林通道上轨。//
NumericSeries dnBand(0); // 声明数值序列变量dnBand,初值0,即布林通道下轨。//
Begin
If(!CallAuctionFilter()) Return; // 集合竞价和小节休息过滤。//
todayVolatility = StandardDev(Close,30,1); // 当日市场波动算法,利用求标准差函数StandardDev,把收盘价,周期30,步长1返回去求值了,再把值反馈回来赋值给变量todayVolatility。//
yesterDayVolatility = todayVolatility[1] ; // 昨日市场波动,就前一个变量todayVolatility值了。//
deltaVolatility = (todayVolatility - yesterDayVolatility)/todayVolatility;// 市场波动的变动率,代入的值就是昨日波动值与今日波动值了。//
lookBackDays = lookBackDays*(1 + deltaVolatility); // 代码的解读都是一步步按先后顺序来的,这计算自适应变量lookBackDays,先用初值20代入计算,得到的值,再赋值给变量lookBackDays,下个代码用的就是这个新值。//
lookBackDays = Round(lookBackDays,0);//这里接触一个新系统自带函数Round,意思为返回某个数字按指定位数舍入后的数字。比如这两Round (2.15, 1) = 2.2与Round (2.149, 1) = 2.1;很明了的意思吧,这个代入上一代码新值就行,取0位,就是不拿小数部分了,再次求得第三个新的变量lookBackDays值了。//
lookBackDays = Min(lookBackDays,ceilingAmt);//把第三个新值与60对比了,取小值,赋值给变量lookBackDays,变成第四个新值了。//
lookBackDays = Max(lookBackDays,floorAmt);//第五个新值,就是利用第四个新值与20对比,取大值了。//
MidLine = Average(Close,lookBackDays);// 自适应布林通道中轨,把收盘价与第五个新值返回求均值了。//
Band = StandardDev(Close,lookBackDays,2); //这也是求标准差的了,这回代入的是收盘价,第五个新lookBackDays值,步长2,即求得变量Band值。//
upBand = MidLine + bolBandTrig*Band;// 自适应布林通道上轨,也就是把相应值代入进去求得了。//
dnBand = MidLine - bolBandTrig*Band; // 自适应布林通道下轨,同理代入值求得。//
buyPoint = Highest(High,lookBackDays);// 自适应唐奇安通道上轨,求最高价函数,即把高价与第五个新lookBackDays值代入求值了,即可得buyPoint值。//
sellPoint = Lowest(Low,lookBackDays);// 同上求得自适应唐奇安通道下轨。//
LiqPoint = MidLine;// 自适应出场均线。//
If(MarketPosition != 1 And Close[1] > upBand[1] And High >= buyPoint[1]) // 假如当前没有持多仓,并且前一个收盘价大于布林通道上轨,并且当日高价大于唐奇安通道上轨的。//
Buy(Lots,Max(Open,buyPoint[1]));//开多单,价格就是取开盘价与前一个唐奇安通道上轨值对比的大值了。//
If(MarketPosition == 1 And Close[1] < dnBand[1] And Low <= sellPoint[1]) // 持有多单时,昨日价格小于布林通道下轨,并且当日价格小于唐奇安通道下轨。//
Sell(0,Min(Open,sellPoint[1]));//平多单。开盘价与前一唐奇安通道下轨的对比,取小值平仓。//
If(MarketPosition == 1 And BarsSinceEntry >= 1 And Low <= LiqPoint[1]) // 持有多单时,价格小于自适应出场均线。//
Sell(0,Min(Open,LiqPoint[1]));//平多单,开盘价与前一自适应均线值对比,取小值。//
End
做多结果一般的,我直接附上做空代码,及相应结果吧,喜欢与否就看自己的理解了,如下:
Params
Numeric ceilingAmt(60);
Numeric floorAmt(20);
Numeric bolBandTrig(2);
Numeric Lots(0);
Vars
Numeric lookBackDays(20);
NumericSeries todayVolatility(0);
Numeric yesterDayVolatility(0);
Numeric deltaVolatility(0);
NumericSeries buyPoint(0);
NumericSeries sellPoint(0);
NumericSeries LiqPoint(0);
NumericSeries MidLine(0);
Numeric Band(0);
NumericSeries upBand(0);
NumericSeries dnBand(0);
Begin
If(!CallAuctionFilter()) Return;
todayVolatility = StandardDev(Close,30,1);
yesterDayVolatility = todayVolatility[1];
deltaVolatility = (todayVolatility - yesterDayVolatility)/todayVolatility;
lookBackDays = lookBackDays*(1 + deltaVolatility);
lookBackDays = Round(lookBackDays,0);
lookBackDays = Min(lookBackDays,ceilingAmt);
lookBackDays = Max(lookBackDays,floorAmt);
MidLine = Average(Close,lookBackDays);
Band = StandardDev(Close,lookBackDays,2);
upBand = MidLine + bolBandTrig*Band;
dnBand = MidLine - bolBandTrig*Band;
buyPoint = Highest(High,lookBackDays);
sellPoint = Lowest(Low,lookBackDays);
LiqPoint = MidLine;
If(MarketPosition == -1 And Close[1] > upBand[1] And High >= buyPoint[1]) BuyToCover(0,Max(Open,buyPoint[1]));
If(MarketPosition != -1 And Close[1] < dnBand[1] And Low <= sellPoint[1]) SellShort(Lots,Min(Open,sellPoint[1]));
If(MarketPosition == -1 And BarsSinceEntry >= 1 And High >= LiqPoint[1]) BuyToCover(0,Max(Open,LiqPoint[1]));
End