期货软件TB系统源代码解读系列52-基于平移通道的交易系统

没什么好说的,这个也是TB里自带编写好的程序化系统,先看它的买卖规则如下:

策略说明:

本策略基于平移后的高低点通道判断入场条件,结合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

整体看来也挺一般的,还是老话了,这是我也没仔细对这系统做研究,也没法给做个修改,但看这平移通道的理念,也是一个趋势追踪的,在横盘阶段就是一个打脸时期。

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2018年8月7日
下一篇 2018年8月7日

相关推荐