策略說明: 基于通道突破的判斷
系統(tǒng)要素:
1. 計算50根k線最高價的區(qū)間
2. 計算30根k線最低價的區(qū)間
入場條件:
1.價格高于50根K線最高價的區(qū)間入場
出場條件:
1. 當(dāng)前價格低于30根K線最低價的區(qū)間出場
2. 當(dāng)前價格低于入場價一定ATR波動率幅度出場
做多代碼及解讀如下:
Params
Numeric Length1(50); //聲明數(shù)值參數(shù)Length1鳞绕,初值50,即長周期區(qū)間參數(shù)萄焦。//
Numeric Length2(30); //聲明數(shù)值參數(shù)Length2冤竹,初值30,即短周期區(qū)間參數(shù)冒签。//
Numeric IPS(4);//聲明數(shù)值參數(shù)IPS钟病,初值4刚梭,保護止損波動率參數(shù)票唆。//
Numeric AtrVal(10);//聲明數(shù)值參數(shù)AtrVal走趋,初值10,波動率參數(shù)簿煌。//
Vars?
NumericSeries ProtectStopL;//聲明數(shù)值序列變量ProtectStopL姨伟。//
NumericSeries ATR;//聲明數(shù)值序列變量ATR。//
NumericSeries Upperband;//聲明數(shù)值序列變量Upperband琳水。//
NumericSeries Lowerband;?//聲明數(shù)值序列變量Lowerband般堆。//
NumericSeries Exitlong;//聲明數(shù)值序列變量Exitlong诚啃。//
NumericSeries Exitshort;//聲明數(shù)值序列變量Exitshort始赎。//
Numeric L2;//聲明數(shù)值變量L2.//
Numeric L1;//聲明數(shù)值變量L1.//
Numeric Minpoint;//聲明數(shù)值變量Minpoint。//
Begin
If(!CallAuctionFilter()) Return;// 集合競價和小節(jié)休息過濾造垛。//
Minpoint = Minmove*PriceScale;//一跳的固定公式五辽。//
??ATR = AvgTrueRange(AtrVal); //計算ATR值。//
L1 = Max(Length1,Length2); //進場周期選擇較大的區(qū)間參數(shù)乡翅。//
L2 = Min(Length1,Length2); //出場周期選擇較小的區(qū)間參數(shù)罪郊。//
Upperband = Highest(High, L1); //長周期最高價區(qū)間。//
Lowerband = lowest(Low,L1); //長周期最低價區(qū)間靶累。//
Exitlong = Lowest(Low,L2); //短周期最低價區(qū)間。//
Exitshort = Highest(high,L2); //短周期最高價區(qū)間潮酒。//
//系統(tǒng)入場?凛忿。//
If(Marketposition == 0 and High >= Upperband[1] + Minpoint And Vol > 0) ???//當(dāng)前沒有持倉,且當(dāng)前最高價格大于長周期最高價區(qū)間入場做多叁熔。//
{
Buy(0, Max(Open, Upperband[1] + Minpoint));//開多床牧。//
ProtectStopL = Entryprice - IPS*ATR[1];//保護性止損計算公式戈咳。//
}
//系統(tǒng)出場。//
If(MarketPosition == 1 and BarsSinceEntry >0 And Vol > 0)//當(dāng)前持有多單删铃,且建倉數(shù)位大于0踏堡,且成交量大于0。//
{
If( Low <= ProtectStopL[1] and ProtectStopL[1] >= Exitlong[1])?//最低價格小于等于前一個保護性止損诫隅,且前一個保護性止損大于等于前一個短周期最低價區(qū)間帐偎。//
{
Sell (0,Min(Open,ProtectStopL[1]));//平倉削樊。//
}
Else if (Low <= Exitlong[1] - Minpoint)???//價格低于短周期最低價區(qū)間出場。//
{
Sell(0, Min( Open, Exitlong[1] - Minpoint));//平倉沛硅。//
}
}
End
做空代碼及結(jié)果如下:
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
我個人感覺這個系統(tǒng)還是不錯的,那些參數(shù)要是不符合你仪际,可以根據(jù)個人意愿修改的昵骤。