时间:2020-04-14 | 栏目:TB交易开拓者策略 | 点击:次
策略说明:
1.计算价格通道
2.收盘价加上ATR的一定倍数作为进场价
入场条件:
1.上一根Bar创新高
2.当前Bar最高价突破上一根Bar收盘价加上ATR的一定倍数
出场条件:
1.记录多头进场后的跟踪止损价
2.价格向下突破跟踪止损价多头出场
买卖规则就这样了,先直接看做多的具体代码吧,解读如下:
Params
Numeric Length(10); //声明数值参数Length,初值10,用于计算ATR和新高价的Bar数。//
Numeric Trigger(0.79); //声明数值参数Trigger,初值0.79,用于计算多头进场价的驱动系数。//
Numeric Acceleration(0.05); //声明数值参数Acceleration,初值0.05,抛物线的加速系数。//
Numeric FirstBarMultp(5); //声明数值参数FirstBarMultp,初值5,用于计算在进场Bar设置止损价的系数。//
Vars
NumericSeries ATR;//声明数值序列变量ATR。//
NumericSeries StopPrice; //声明序列变量StopPrice,即跟踪止损价。//
NumericSeries HighValue; //声明数值序列变量HighValue,即多头进场之后的盈利峰值价。//
NumericSeries AF; //声明数值序列变量AF。//
BoolSeries Condition1(False); //声明布尔型序列变量Condition1,初值为假。//
Numeric StopATR;//声明数值变量StopATR。//
Begin
If(!CallAuctionFilter()) Return;// 集合竞价和小节休息过滤。//
//初始设置。//
ATR=AvgTrueRange(Length);//变量ATR的求法,就是之前解读的抛物线了。//
Condition1=High>Highest(High[1],Length);//先求Highest(High[1],Length)值,再与当前High比较,判断当前最高价大于成立的,则把值赋值给布尔型变量Condition1值。//
//上一根Bar创新高后且当前Bar最高价突破上一根Bar收盘价加上ATR的一定倍数多头入场。//
If(Condition1[1])//假如前一个布尔型序列变量Condition1[1]为真。//
{
If(High>=Close[1]+ATR[1]*Trigger And Vol > 0)//假如当前最高价 >= 前一收盘价Close[1] + 前一ATR[1] * 0.79,并且成交量Vol>0.//
{
Buy(0,Max(Open,Close[1]+ATR[1]*Trigger));//开仓买入了。//
}
}
//记录盈利峰值价和跟踪止损价。//
StopATR = Average(TrueRange,3);//函数TrueRange,求真实波动值了。函数Average,求平均值。这些都是前面解读过的,都是把相应数值代回去求值就行。//
If(MarketPosition==1 And BarsSinceEntry==0)//假如持有多单,并且建仓位等于0.//
{
StopPrice=Low-StopATR*FirstBarMultp;//止损价StopPrice = 最低价Low - 变量StopATR * 5.//
AF=Acceleration;//代入值,即AF = 0.05//
HighValue=High;//序列变量HighValue = 当前最高价High。//
}
Else If(MarketPosition==1 And BarsSinceEntry>0)//假如持有多单,并且建仓位大于0.//
{
If(High>HighValue) HighValue=High;//假如当前最高价大于变量HighValue值,则变量HighValue = 当前High值。//
If(HighValue>HighValue[1] And AF<0.2)//假如当前变量HighValue值大于前一个HighValue[1]值的,并且AF < 0.2//
{
AF=AF+Min(Acceleration,0.2-AF);//代入相应值了,依据起始建仓位AF = Acceleration = 0.05,这代码意思先求括号里的最小值,再加上AF值,最后再赋值给系数AF了。//
}
StopPrice=StopPrice+AF*(HighValue-StopPrice);//这个StopPrice也是依据起始建仓位算得的值,这里也就是把相应值给代进去算了。//
}
PlotNumeric("StopPrice",StopPrice);//画出跟踪止损价。//
//向下突破跟踪止损价多头出场。//
If(MarketPosition==1 And BarsSinceEntry>0 And Low<=StopPrice[1] And Vol > 0)//假如持有多单,并且建仓位大于0,并且最低价小于等于前一个止损价StopPrice值,并且成交量大于0.//
{
Sell(0,Min(Open,StopPrice[1]));//卖出平仓。//
}
End
写完具体的,下面就是它做空的代码了:
Params
Numeric Length(10);
Numeric Trigger(0.5);
Numeric Acceleration(0.06);
Numeric FirstBarMultp(2);
Vars
NumericSeries ATR;
NumericSeries StopPrice;
NumericSeries LowValue;
NumericSeries AF;
BoolSeries Condition2(False);
Numeric StopATR;
Begin
If(!CallAuctionFilter()) Return;
ATR=AvgTrueRange(Length);
Condition2=Low
If(Condition2[1])
{
If(Low<=Close[1]-ATR[1]*Trigger And Vol > 0)
{
SellShort(0,Min(Open,Close[1]-ATR[1]*Trigger));
}
}
StopATR = Average(TrueRange,3);
If(MarketPosition==-1 And BarsSinceEntry==0)
{
StopPrice=High+StopATR*FirstBarMultp;
AF=Acceleration;
LowValue=Low;
}Else If(MarketPosition==-1 And BarsSinceEntry>0)
{
If(Low
If(LowValue
{
AF=AF+Min(Acceleration,0.2-AF);
}
StopPrice=StopPrice-AF*(StopPrice-LowValue);
}
PlotNumeric("StopPrice",StopPrice);
If(MarketPosition==-1 And BarsSinceEntry>0 And High>=StopPrice[1] And Vol > 0)
{
BuyToCover(0,Max(Open,StopPrice[1]));
}
End
十年专业期货服务平台,全国最低手续费保证金开户,咨询微信:cclk88