时间:2020-04-14 | 栏目:TB交易开拓者策略 | 点击:次
策略说明: 基于通道突破的判断
系统要素:
1. 计算50根k线最高价的区间
2. 计算30根k线最低价的区间
入场条件:
1.价格高于50根K线最高价的区间入场
出场条件:
1. 当前价格低于30根K线最低价的区间出场
2. 当前价格低于入场价一定ATR波动率幅度出场
做多代码及解读如下:
Params
Numeric Length1(50); //声明数值参数Length1,初值50,即长周期区间参数。//
Numeric Length2(30); //声明数值参数Length2,初值30,即短周期区间参数。//
Numeric IPS(4);//声明数值参数IPS,初值4,保护止损波动率参数。//
Numeric AtrVal(10);//声明数值参数AtrVal,初值10,波动率参数。//
Vars
NumericSeries ProtectStopL;//声明数值序列变量ProtectStopL。//
NumericSeries ATR;//声明数值序列变量ATR。//
NumericSeries Upperband;//声明数值序列变量Upperband。//
NumericSeries Lowerband; //声明数值序列变量Lowerband。//
NumericSeries Exitlong;//声明数值序列变量Exitlong。//
NumericSeries Exitshort;//声明数值序列变量Exitshort。//
Numeric L2;//声明数值变量L2.//
Numeric L1;//声明数值变量L1.//
Numeric Minpoint;//声明数值变量Minpoint。//
Begin
If(!CallAuctionFilter()) Return;// 集合竞价和小节休息过滤。//
Minpoint = Minmove*PriceScale;//一跳的固定公式。//
ATR = AvgTrueRange(AtrVal); //计算ATR值。//
L1 = Max(Length1,Length2); //进场周期选择较大的区间参数。//
L2 = Min(Length1,Length2); //出场周期选择较小的区间参数。//
Upperband = Highest(High, L1); //长周期最高价区间。//
Lowerband = lowest(Low,L1); //长周期最低价区间。//
Exitlong = Lowest(Low,L2); //短周期最低价区间。//
Exitshort = Highest(high,L2); //短周期最高价区间。//
//系统入场 。//
If(Marketposition == 0 and High >= Upperband[1] + Minpoint And Vol > 0) //当前没有持仓,且当前最高价格大于长周期最高价区间入场做多。//
{
Buy(0, Max(Open, Upperband[1] + Minpoint));//开多。//
ProtectStopL = Entryprice - IPS*ATR[1];//保护性止损计算公式。//
}
//系统出场。//
If(MarketPosition == 1 and BarsSinceEntry >0 And Vol > 0)//当前持有多单,且建仓数位大于0,且成交量大于0。//
{
If( Low <= ProtectStopL[1] and ProtectStopL[1] >= Exitlong[1]) //最低价格小于等于前一个保护性止损,且前一个保护性止损大于等于前一个短周期最低价区间。//
{
Sell (0,Min(Open,ProtectStopL[1]));//平仓。//
}
Else if (Low <= Exitlong[1] - Minpoint) //价格低于短周期最低价区间出场。//
{
Sell(0, Min( Open, Exitlong[1] - Minpoint));//平仓。//
}
}
End
做空代码及结果如下:
Params
Numeric Length1(50);
Numeric Length2(30);
Numeric IPS(4);
Numeric AtrVal(10);
Vars
NumericSeries ProtectStopS;
NumericSeries ATR;
NumericSeries Upperband;
NumericSeries Lowerband;
NumericSeries Exitlong;
NumericSeries Exitshort;
Numeric L2;
Numeric L1;
Numeric Minpoint;
Begin
If(!CallAuctionFilter()) Return;
Minpoint = Minmove*PriceScale;
ATR = AvgTrueRange(AtrVal);
L1 = Max(Length1,Length2);
L2 = Min(Length1,Length2);
Upperband = Highest(High, L1);
Lowerband = lowest(Low,L1);
Exitlong = Lowest(Low,L2);
Exitshort = Highest(High,L2);
If(Marketposition ==0 and Low <= Lowerband[1] - Minpoint And Vol > 0)
{
Sellshort(0, Min(Open , Lowerband[1] - Minpoint));
ProtectStopS = Entryprice + IPS*ATR[1];
}
If(MarketPosition == -1 and BarsSinceEntry>0 And Vol > 0)
{
If(High >= ProtectStopS[1] and ProtectStopS[1] <= Exitshort[1] )
{
BuyToCover(0, Max(Open , ProtectStopS[1]));
}
Else if ( High >= Exitshort[1] + Minpoint)
{
BuyToCover(0, Max(Open , Exitshort[1] + Minpoint));
}
}
End
十年专业期货服务平台,全国最低手续费保证金开户,咨询微信:cclk88