欢迎来到天天文库
浏览记录
ID:38539860
大小:407.50 KB
页数:28页
时间:2019-06-14
《B公式高级应用2(布林通道和恒温器系统)-黄柳》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、TB公式高级应用黄柳深圳市拓瑞邦泽科技有限公司PartI:BollingerBanditSystemBollingerBanditSystem系统名字的字面翻译为【布林强盗】,我们这里简称为BBS;基于BollingerBands(布林通道)的趋势跟踪系统;根据持仓周期调整跟踪止损。BollingerBanditSystem该系统包含以下四个要素:布林带均线ROC计数器BollingerBanditSystem入场条件:价格突破布林带上轨即做多;价格跌破布林带下轨即做空;ROC为正的情况下才能做多;ROC为负的情况下才能做空。BollingerBanditSyste
2、m出场条件:持多仓的情况下,N周期的收盘价小于布林带上轨,即在下个Bar平仓。持空仓的情况下,N周期的收盘价大于布林带下轨,即在下个Bar平仓。N的值根据持仓周期变化。刚开仓为50,每持仓Bar,即将N值减1,最小到10。BollingerBanditSystem参数定义:布林带的周期数50;布林带标准差的倍数1.25;ROC的周期数30;跟踪止损算法的周期数50;BollingerBanditSystem参数定义代码:ParamsNumericBBLength(50);NumericNumsStdDev(1.25);NumericROCLength(30);Num
3、ericExitLength(50);BollingerBanditSystem布林带算法:定义上轨为UpBand,下轨为DnBand;UpBand=AverageFC(Close,BBLength)+StandardDev(Close,BBLength,2)*NumsStdDev;DnBand=AverageFC(Close,BBLength)-StandardDev(Close,BBLength,2)*NumsStdDev;这里使用的样本标准差。BollingerBanditSystem实际交易讯号的产生是根据上一周期的布林带,因为我们将算法中的Close修改为
4、Close[1];也可以将UpBand和DnBand设为序列变量,判断UpBand[1]]的值讯号条件;UpBand=AverageFC(Close[1],BBLength)+StandardDev(Close[1],BBLength,2)*NumsStdDev;DnBand=AverageFC(Close[1],BBLength)-StandardDev(Close[1],BBLength,2)*NumsStdDev;BollingerBanditSystem计算Roc值定义变量RocValueNumericRocValue;RocValue=Close-Clos
5、e[RocLength];BollingerBanditSystem开多仓条件写法:If(MarketPosition<>1&&RocValue>0){If(High>=UpBand){MyPrice=UpBand;If(Open>MyPrice)MyPrice=Open;Buy(1,MyPrice);}}BollingerBanditSystem开空仓条件的写法类似:If(MarketPosition<>-1&&RocValue<0){If(Low<=DnBand){MyPrice=DnBand;If(Open6、hort(1,MyPrice);}}BollingerBanditSystem动态计算跟踪止损的周期数:先定义一个变量:NumericSeriesexBars;在公式开始部分添加如下代码:If(MarketPosition==0){exBars=ExitLength;}else{exBars=exBars[1]-1;}BollingerBanditSystem根据动态计算的周期数,求出前一周期的均线:StopAvgClose=Average(Close[1],exBars);持有多仓的情况下,当前价格如果跌破StopAvgClose即止损。If(MarketPosi7、tion==1&&Low<=StopAvgClose){MyPrice=StopAvgClose;If(Open=StopAvgClose){MyPrice=StopAvgClose;If(Open>MyPrice)MyPrice=Open;BuyToCover(1,MyPrice);}BollingerBanditSyst
6、hort(1,MyPrice);}}BollingerBanditSystem动态计算跟踪止损的周期数:先定义一个变量:NumericSeriesexBars;在公式开始部分添加如下代码:If(MarketPosition==0){exBars=ExitLength;}else{exBars=exBars[1]-1;}BollingerBanditSystem根据动态计算的周期数,求出前一周期的均线:StopAvgClose=Average(Close[1],exBars);持有多仓的情况下,当前价格如果跌破StopAvgClose即止损。If(MarketPosi
7、tion==1&&Low<=StopAvgClose){MyPrice=StopAvgClose;If(Open=StopAvgClose){MyPrice=StopAvgClose;If(Open>MyPrice)MyPrice=Open;BuyToCover(1,MyPrice);}BollingerBanditSyst
此文档下载收益归作者所有