|
相隔一段时间,这次再来介绍一个趋势策略,用大家熟悉的布林通道所组成,**学习参考
策略原理:
模型通过红绿三兵进行形态识别、利用布林通道上下轨确定价格的相对位置、辅以布林中轨均线过滤及设定价格高低点突破作为开仓信号。出场采用之前的移动停利出场方式,可以自己拓展出场模式。
此策略未做任何优化,参数都是默认常用值,自己可以调整,适合商品趋势行情。
策略源码如下:- inputs:
- BollingerPrice( Close ),
- TestPriceUBand( Close ),
- TestPriceLBand( Close ),
- Length( 20 ),
- NumDevsUp( 2 ),
- NumDevsDn( -2 ),
- Displace( 0 ) ,
- mm(10);
- variables:
- var0( 0 ),
- var1( 0 ),
- var2( 0 ),
- var3( 0 ) ;
- var0 = AverageFC( BollingerPrice, Length ) ;
- var1 = StandardDev( BollingerPrice, Length, 1 ) ;
- var3 = var0 + NumDevsUp * var1 ;
- var2 = var0 + NumDevsDn * var1 ;
- /////////////////////////////////////////////布林轨道
- condition1=CountIf(close>open,3)>=3;
- condition2=CountIf(close>close[1],3)>=3;
- condition3=CountIf(open>open[1],3)>=3;
- condition4=open>open[1] and open[1]>open[2]and close>close[1] and close[1]>close[2];
- condition10=CountIf(var3>var3[1],5)>=5;
- if condition1 and condition2 and condition3 and condition4
- and marketposition=0 and close>=Average(var0,mm) and condition10 then buy("BK") next bar at Highest(high,3) stop;
- ///////////////////////////////////////判别白三兵加boll轨道过滤进场
- condition5=CountIf(close<open,3)>=3;
- condition6=CountIf(close<close[1],3)>=3;
- condition7=CountIf(open<open[1],3)>=3;
- condition8=close<close[1] and close[1]<close[2] and open<open[1] and open[1]<open[2];
- condition11=CountIf(var3<var3[1],5)>=5;
- if condition5 and condition6 and condition7 and condition8
- and marketposition=0 and close<Average(var0,mm) and condition11 then sellshort("SK") next bar at lowest(low,3) stop;
- ///////////////////////////////////判别黑三兵加boll过滤进场
- input:stoppoint(10);
- var:longstop(0),barHH(0);
- if barssinceentry=0 then begin
- longstop=minlist(low,low[1])-stoppoint;
- barHH=high;
- end;
- if high>barHH then barHH=high;
- if barssinceentry>0 then begin
- if c>barHH[1] then longstop=minlist(low,low[1])-stoppoint;
- end;
- if marketposition=1 then sell("EL") next bar at longstop stop ;
- input:stoppoint1(10);
- var:longstop1(0),barll(0);
- if barssinceentry=0 then begin
- longstop1=maxlist(high,high[1])+stoppoint;
- barll=low;
- end;
- if low<barll then barll=low;
- if barssinceentry>0 then begin
- if c<barll[1] then longstop1=maxlist(high,high[1])+stoppoint;
- end;
- if marketposition=-1 then buytocover("EX") next bar at longstop1 stop ;
- ////////////////////////////////////////////移动止盈出场
复制代码
|
|