中孚期货期权网
返回首页

期货软件TB系统源代码解读:基于平移通道的交易系统策略

admin未知

策略说明:

本策略基于平移后的高低点通道判断入场条件,结合ATR止损

系统要素:

1. 平移后的高低点通道

2. atr止损

入场条件:

1.当高点上穿平移通道高点时,开多仓

2.当低点下穿平移通道低点时,开空仓

出场条件:

1.ATR跟踪止盈

2.通道止损

直接看做多系统的代码解读如下了:

Params

Numeric ChanLength(20);   // 声明数值参数ChanLength,初值20,即通道周期。//

Numeric ChanDelay(15);  // 声明数值参数ChanDelay,初值15,即通道平移周期。//

Numeric TrailingATRs(3); // 声明数值参数TrailingATRs,初值3,即ATR跟踪止损倍数。//

Numeric ATRLength(10);  //声明数值参数ATRLength,初值10,即 ATR计算周期。//

Vars 

NumericSeries UpperChan(0);    // 声明数值序列变量UpperChan,初值0,即通道上轨。//

NumericSeries LowerChan(0);   //声明数值序列变量LowerChan,初值0,即通道下轨。//

NumericSeries PosHigh(0);   // 声明数值序列变量PosHigh,初值0,即记录开仓后高点 。//    

NumericSeries ATRVal(0);    // 声明数值序列变量ATRVal,初值0,即atr均值。//

bool con;      // 声明布尔型变量con。//

Numeric minpoint;      //声明数值变量minpoint,即 最小变动价位。//

NumericSeries stopline; // 声明数值序列变量stopline,即止损线计算。//

 

Begin

If(!CallAuctionFilter()) Return;// 集合竞价和小节休息过滤。//

// 指标计算。//

minpoint = Minmove*PriceScale;    // 固定公式,最小变动价位。//

UpperChan = Highest(High,ChanLength); // UpperChan=20周期高点.//

LowerChan = Lowest(Low,ChanLength);   // LowerChan=20周期低点。//

// 系统入场。//

con = High >= UpperChan[ChanDelay+1] and High[1] < UpperChan[ChanDelay+1];// 价格向上突破ChanDelay周期前的UpperChan,开多仓。//

If(MarketPosition == 0)//没有持仓。//

{

If(con) //假如布尔型变量con条件成立。//

{

Buy(0,max(Open,UpperChan[ChanDelay+1]));//开多单仓。//

}

}

// 系统出场。//

If(BarsSinceEntry == 0 )//假如进场数位等于0.//

PosHigh = High;//记录当前进场k线最高。//

Else if(High > PosHigh[1] ) //进场k线数位大于0的,假如当前最高价大于前一个最高价。//

PosHigh = High; //则赋值变量PosHigh为当前最高价。//

// ATR跟踪止损,通道止损。//

ATRVal = AvgTrueRange(ATRLength)*TrailingATRs;//这是ATRVal算法,前面说过了,这里也不再说了,都是代入相应参数返回求值的。//

If(MarketPosition == 1 and BarsSinceEntry > 0) //假如当前持有多单,并且进场k线数位大于0.//

{

stopline = Max(PosHigh[1] - ATRVal[1],LowerChan[ChanDelay+1] - minpoint);//止损价的具体算法,代入相应数值了,这些变量上边公式都具体求出来了。//

If(Low <= stopline )//假如最低价低于止损价的。//

{

Sell(0,min(Open,stopline));//平仓于止损价。//

}

}

End

 
 

 

还好,看做空的代码及结果如下了:

Params

Numeric ChanLength(20);  

Numeric ChanDelay(15);  

Numeric TrailingATRs(3); 

Numeric ATRLength(10);  

Vars 

NumericSeries UpperChan(0);   

NumericSeries LowerChan(0);  

NumericSeries PosLow(0);    

NumericSeries ATRVal(0);    

bool con;            

Numeric minpoint;       

NumericSeries stopline;   

Begin

If(!CallAuctionFilter()) Return;

minpoint = Minmove*PriceScale;      

UpperChan = Highest(High,ChanLength);  

LowerChan = Lowest(Low,ChanLength);   

con = Low <= LowerChan[ChanDelay+1] and Low[1] > LowerChan[ChanDelay+1];

If(MarketPosition == 0)

{

If(con) 

{

SellShort(0,min(Open,LowerChan[ChanDelay+1]));

}

If(BarsSinceEntry == 0 )

PosLow = Low;

Else if(Low < PosLow[1] )

PosLow = Low;

ATRVal = AvgTrueRange(ATRLength)*TrailingATRs;

If(MarketPosition == -1 and BarsSinceEntry > 0) 

{

stopline = Min(PosLow[1] + ATRVal[1],UpperChan[ChanDelay+1] + minpoint);

If(High >= stopline)

{

BuyToCover(0,max(Open,stopline));

}

}

End


 

版权声明:本网未注明“来源:中国期货期权网”的稿件均为转载稿,本网转载出于传递更多信息之目的,并不意味着赞同其观点或证实其内容的真实性。如对稿件内容有疑议,认为转载稿涉及版权等问题,请在两周内来电或来函与中孚期货期权网联系,我们将在第一时间处理



微信扫码二维码 “零佣金”期货开户