策略說明:
本策略是基于市場強(qiáng)弱指標(biāo)和動(dòng)量的通道突破系統(tǒng)?
系統(tǒng)要素:
1. 根據(jù)N根K線的收盤價(jià)相對前一根K線的漲跌計(jì)算出市場強(qiáng)弱指標(biāo)
2. 最近9根K線的動(dòng)量變化趨勢
3. 最近N根K線的高低點(diǎn)形成的通道
入場條件:
1. 市場強(qiáng)弱指標(biāo)為多頭,且市場動(dòng)量由空轉(zhuǎn)多時(shí)充甚,突破通道高點(diǎn)做多
2. 市場強(qiáng)弱指標(biāo)為空頭以政,且市場動(dòng)量由多轉(zhuǎn)空時(shí),突破通道低點(diǎn)做空
出場條件:?
1. 開多以開倉BAR的最近N根BAR的低點(diǎn)作為止損價(jià)伴找,反過來的開空以開倉BAR的最近N根BAR的高點(diǎn)作為止損價(jià)
2. 盈利超過止損額的一定倍數(shù)止盈
3. 出現(xiàn)反向信號止損
做多的代碼及解讀如下:
Params
Numeric Length(5); // 聲明數(shù)值參數(shù)Length盈蛮,初值5,即強(qiáng)弱指標(biāo)和通道計(jì)算的周期值技矮。//
Numeric Stop_Len(5); // 聲明數(shù)值參數(shù)Stop_Len抖誉,初值5,即止損通道的周期值衰倦。//
Numeric ProfitFactor(3); // 聲明數(shù)值參數(shù)ProfitFactor袒炉,初值3,即止盈相對止損的倍數(shù)耿币。//
Numeric EntryStrength(95); // 聲明數(shù)值參數(shù)EntryStrength梳杏,初值95,即強(qiáng)弱指標(biāo)的進(jìn)場值淹接。//
Vars
NumericSeries CloseChange; //聲明數(shù)值序列變量CloseChange十性,即 收盤價(jià)變動(dòng)值。//
Numeric i; //聲明數(shù)值變量 i 塑悼,即 循環(huán)控制變量劲适。//
Numeric UpCloses; //聲明數(shù)值變量UpCloses, 收盤價(jià)上漲累計(jì)值厢蒜。//
Numeric DnCloses; // 聲明數(shù)值變量DnCloses霞势,收盤價(jià)下跌累計(jì)值。//
Numeric SumChange; // 聲明數(shù)值變量SumChange斑鸦, 收盤價(jià)變動(dòng)累計(jì)值愕贡。//
NumericSeries MarketStrength; // 聲明數(shù)值序列變量MarketStrength, 市場強(qiáng)弱指標(biāo)巷屿。//
NumericSeries Momentum1; //? 聲明數(shù)值序列變量Momentum1固以,即當(dāng)前Bar相對前4根BAR的動(dòng)量。//
NumericSeries Momentum2; //? 聲明數(shù)值序列變量Momentum2嘱巾,即前4根BAR相對前8根BAR的動(dòng)量憨琳。//
NumericSeries HH; //聲明數(shù)值序列變量HH, N周期高點(diǎn)?旬昭。//
NumericSeries LL1; // 聲明數(shù)值序列變量LL1篙螟,N周期低點(diǎn)。//
NumericSeries LL2; // 聲明數(shù)值序列變量LL2问拘,N周期低點(diǎn)遍略。//
NumericSeries StopLoss; // 聲明數(shù)值序列變量StopLoss,止損位骤坐。//
NumericSeries ProfitTarget; // 聲明數(shù)值序列變量ProfitTarget绪杏,止盈位。//
Begin
If(!CallAuctionFilter()) Return;// 集合競價(jià)和小節(jié)休息過濾或油。//
// 計(jì)算市場強(qiáng)弱指標(biāo)寞忿。//
CloseChange = Close - Close[1];//變量CloseChange = 當(dāng)前收盤價(jià)Close - 前一收盤價(jià)Close[1]。//
UpCloses = 0; //初值賦0.//
DnCloses = 0;//初值賦0.//
For i = 0 To Length-1//循環(huán)從0到4.//
{
If(CloseChange[i] > 0)?//假如變量CloseChange[i]大于0.//
UpCloses = UpCloses + CloseChange[i];// 收盤價(jià)上漲計(jì)入漲幅累計(jì)顶岸。//
Else //否則假如變量CloseChange[i]小于0 腔彰,則計(jì)入跌幅累計(jì)。//
DnCloses = DnCloses + CloseChange[i];//計(jì)入跌幅累計(jì)辖佣。//
}
// 計(jì)算周期內(nèi)漲跌霹抛。//
SumChange = Summation(CloseChange,Length);//計(jì)算5周期內(nèi)變量CloseChange總值,賦值給變量SumChange值卷谈。//
// 周期內(nèi)上漲杯拐,計(jì)算上漲強(qiáng)度,0-100之間。//
If(SumChange >= 0)//假如變量SumChange>=0端逼。//
{
MarketStrength = SumChange/UpCloses*100;//市場強(qiáng)弱指標(biāo)的計(jì)算朗兵,代入上面求得的數(shù)值即可。//
}
// 周期內(nèi)下跌顶滩,計(jì)算下跌強(qiáng)度余掖,0-100之間。//
Else//假如變量SumChange<0礁鲁。//
{
MarketStrength = SumChange/Abs(DnCloses)*100;//市場強(qiáng)弱指標(biāo)的計(jì)算.//
}
// 計(jì)算動(dòng)量.//
Momentum1 =?Close - Close[4];//變量Momentum1 = 當(dāng)前收盤價(jià) - 前4數(shù)位收盤價(jià)盐欺。//
Momentum2 =?Close[4] - Close[8]; //變量Momentum2 = 前4數(shù)位收盤價(jià) - 前8數(shù)位收盤價(jià)。//
// 計(jì)算周期高低點(diǎn)仅醇,開倉突破用冗美。//
HH = Highest(High,Length);//計(jì)算5周期內(nèi)最高價(jià)。//
LL1 = Lowest(Low,Length);//計(jì)算5周期內(nèi)最低價(jià)析二。//
LL2 = Lowest(Low,Stop_Len); // 計(jì)算周期低點(diǎn)粉洼,開倉后止損用。//
// 開倉甲抖。//
If(MarketPosition == 0 And MarketStrength[1] >= EntryStrength And Momentum1[1] >= 0 And Momentum2[1] < 0 And High >= HH[1] And Vol > 0)//假如當(dāng)前沒有持倉漆改,且前一強(qiáng)弱指標(biāo)大于等于95,且前一變量Momentum1大于等于0准谚,前一變量Momentum2小于0挫剑,且當(dāng)前最高價(jià)大于前一最高價(jià),成交量大于0.//
{
Buy(0, Max(Open,HH[1]));//開多單柱衔,值為開盤價(jià)與前一最高價(jià)的比較樊破,取較大值。//
StopLoss = LL2;// 記錄開倉BAR的周期低點(diǎn)作為止損位唆铐。//
// 根據(jù)止損位計(jì)算止盈位哲戚。//
ProfitTarget = EntryPrice + (EntryPrice - StopLoss) * ProfitFactor;//代入相應(yīng)數(shù)值了,函數(shù)EntryPrice即開倉價(jià)意思艾岂。//
Commentary("ProfitTarget="+text(ProfitTarget));//在超級圖表上注釋 止盈數(shù)值顺少。//
}
// 平倉。//
If(MarketPosition == 1 And BarsSinceEntry > 0 And Vol > 0)//假如當(dāng)前持有多單王浴,且建倉數(shù)位大于0脆炎,成交量大于0。//
{
If(High >= ProfitTarget)//假如當(dāng)前最高價(jià)大于等于止盈位氓辣。//
{
Sell(0,Max(Open,ProfitTarget));//平倉秒裕,價(jià)格為開盤價(jià)與止盈位的比較,取較大值钞啸。//
Commentary("止盈");//注釋止盈几蜻。//
}
Else If(Low <= StopLoss)//假如當(dāng)前最低價(jià)Low 小于等于止損位喇潘。//
{
Sell(0,Min(Open,StopLoss));//平倉,價(jià)格為開盤價(jià)與止損價(jià)的比較梭稚,取較小值颖低。//
Commentary("止損");//注釋止損。//
}
Else If(MarketStrength[1] <= -1*EntryStrength And Momentum1[1] < 0 And Momentum2[1] >= 0 And Low <= LL1[1])//假如前一強(qiáng)弱指標(biāo)小于等于-95哨毁,且前一變量Momentum1小于0枫甲,且前一變量Momentum2大于等于0源武,且當(dāng)前最低價(jià)小于等于前一最低價(jià)扼褪。//
{
Sell(0,Min(Open,LL1[1]));//平倉,價(jià)格為開盤價(jià)與前一最低價(jià)的比較粱栖,取較小值话浇。//
Commentary("反向出場");//注釋為反向出場。//
}
}
End
做空代碼及結(jié)果如下:
Params
Numeric Length(5);
Numeric Stop_Len(5);
Numeric ProfitFactor(3);
Numeric EntryStrength(95);
Vars
NumericSeries CloseChange;
Numeric i;
Numeric UpCloses;
Numeric DnCloses;
Numeric SumChange;
NumericSeries MarketStrength;
NumericSeries Momentum1;
NumericSeries Momentum2;
NumericSeries HH1; ?
NumericSeries HH2; ?
NumericSeries LL;
NumericSeries StopLoss;
NumericSeries ProfitTarget;
Begin
If(!CallAuctionFilter()) Return;
CloseChange = Close - Close[1];
UpCloses = 0;
DnCloses = 0;
For i = 0 To Length-1
{
If(CloseChange[i] > 0)?
UpCloses = UpCloses + CloseChange[i];
Else
DnCloses = DnCloses + CloseChange[i];
}
SumChange = Summation(CloseChange,Length);
If(SumChange >= 0)
{
MarketStrength = SumChange/UpCloses*100;
}
Else
{
MarketStrength = SumChange/Abs(DnCloses)*100;
}
Momentum1 =?Close - Close[4];
Momentum2 =?Close[4] - Close[8];
HH1 = Highest(High,Length);
LL = Lowest(Low,Length);
HH2 = Highest(High,Stop_Len);
If(MarketPosition == 0 And MarketStrength[1] <= -1*EntryStrength And Momentum1[1] <= 0 And Momentum2[1] > 0 And Low <= LL[1] And Vol > 0)
{
SellShort(0, Min(Open,LL[1]));
StopLoss = HH2;
ProfitTarget = EntryPrice - (StopLoss - EntryPrice) * ProfitFactor;
Commentary("ProfitTarget="+text(ProfitTarget));
}
If(MarketPosition == -1 And BarsSinceEntry > 0 And Vol > 0)
{
If(Low <= ProfitTarget)
{
BuyToCover(0,Min(Open,ProfitTarget));
Commentary("止盈");
}
Else If(High >= StopLoss)
{
BuyToCover(0,Max(Open,StopLoss));
Commentary("止損");
}
Else If(MarketStrength[1] >= EntryStrength And Momentum1[1] > 0 And Momentum2[1] <= 0 And High >= HH1[1])
{
BuyToCover(0,Max(Open,HH1[1]));
Commentary("反向出場");
}
}
End