取名為幽靈交易者的系統(tǒng),名字霸氣随抠,效果,大家自己測(cè)試看看了繁涂,照例還是先看策略說(shuō)明吧:
策略說(shuō)明:
模擬交易產(chǎn)生一次虧損后才啟動(dòng)真實(shí)下單交易拱她。
系統(tǒng)要素:
1、兩條指數(shù)平均線
2扔罪、RSI指標(biāo)
3秉沼、唐奇安通道
入場(chǎng)條件:
1、模擬交易產(chǎn)生一次虧損矿酵、短期均線在長(zhǎng)期均線之上唬复、RSI低于超買值、創(chuàng)新高全肮,則開多單
2敞咧、模擬交易產(chǎn)生一次虧損、短期均線在長(zhǎng)期均線之下倔矾、RSI高于超賣值妄均、創(chuàng)新低,則開空單
出場(chǎng)條件:
1哪自、持有多單時(shí)小于唐奇安通道下軌丰包,平多單
2、持有空單時(shí)大于唐奇安通道上軌壤巷,平空單
做多代碼及解讀如下:
Params
Numeric FastLength(9); // 聲明數(shù)值參數(shù)FastLength邑彪,初值9,即短期指數(shù)平均線參數(shù)胧华。//
Numeric SlowLength(19); // 聲明數(shù)值參數(shù)SlowLength寄症,初值19,即長(zhǎng)期指數(shù)平均線參數(shù)矩动。//
Numeric Length(9); // 聲明數(shù)值參數(shù)Length有巧,初值9,即RSI參數(shù)悲没。//
Numeric OverSold(30); // 聲明數(shù)值參數(shù)OverSold篮迎,初值30,即超賣。//
Numeric OverBought(70); // 聲明數(shù)值參數(shù)OverBought甜橱,初值70逊笆,即超買。//
Numeric Lots(0); // 聲明數(shù)值參數(shù)Lots岂傲,初值0难裆,即交易手?jǐn)?shù)設(shè)置。//
Vars
NumericSeries AvgValue1; // 聲明數(shù)值序列變量AvgValue1镊掖,即短期指數(shù)平均線?乃戈。//
NumericSeries AvgValue2; // 聲明數(shù)值序列變量AvgValue2,即長(zhǎng)期指數(shù)平均線亩进。//
NumericSeries NetChgAvg(0);//聲明數(shù)值序列變量NetChgAvg偏化,初值0。//
NumericSeries TotChgAvg(0);//聲明數(shù)值序列變量TotChgAvg镐侯,初值0.//
Numeric SF(0);//聲明數(shù)值變量SF,初值0.//
Numeric Change(0); //聲明數(shù)值變量Change驶冒,初值0.//
Numeric ChgRatio(0);//聲明數(shù)值變量ChgRatio苟翻,初值0.//
NumericSeries RSIValue; // 聲明數(shù)值序列變量RSIValue,即RSI指標(biāo)骗污。//
NumericSeries ExitHiBand(0); // 聲明數(shù)值序列變量ExitHiBand崇猫,初值0,唐奇安通道上軌需忿。//
NumericSeries ExitLoBand(0); //聲明數(shù)值序列變量ExitLoBand诅炉,初值0, 唐奇安通道下軌屋厘。//
NumericSeries myEntryPrice(0); //聲明數(shù)值序列變量myEntryPrice涕烧,初值0, 進(jìn)場(chǎng)價(jià)格汗洒。//
NumericSeries myExitPrice(0); // 聲明數(shù)值序列變量myExitPrice议纯,初值0,出場(chǎng)價(jià)格溢谤。//
NumericSeries myProfit(0); // 聲明數(shù)值序列變量myProfit瞻凤,初值0,即利潤(rùn)世杀。//
NumericSeries myPosition(0); // 聲明數(shù)值序列變量myPosition阀参,初值0,即多空標(biāo)志瞻坝。//
Begin
If(!CallAuctionFilter()) Return;// 集合競(jìng)價(jià)和小節(jié)休息過(guò)濾蛛壳。//
AvgValue1 = Xaverage(Close,FastLength);// 計(jì)算短期指數(shù)平均線,即把收盤價(jià)與周期9返回函數(shù)Xaverage求值。//
AvgValue2 = Xaverage(Close,SlowLength);//同理炕吸,計(jì)算長(zhǎng)期指數(shù)平均線參數(shù)伐憾。//
// 計(jì)算RSI。//
If(CurrentBar <= Length - 1)//假如當(dāng)前索引k線數(shù)位值小于等于周期8(9-1)的赫模。//
{
NetChgAvg = (Close - Close[Length])/Length;//代入相應(yīng)數(shù)值計(jì)算树肃,即得NetChgAvg = (close - close[9])/ 9的。//
TotChgAvg = Average(Abs(Close - Close[1]),Length);//先算絕對(duì)值函數(shù)Abs里的瀑罗,再把絕對(duì)值與周期9返回均值函數(shù)Average求均值胸嘴,最后賦值給變量TotChgAvg。//
}Else//就是k線數(shù)位值大于周期8的斩祭。//
{
SF = 1/Length;//代入相應(yīng)數(shù)值劣像,即SF= 1/9 了.//
Change = Close - Close[1];//同理,代入當(dāng)期k線收盤價(jià)與前一k線收盤價(jià)即可摧玫。//
NetChgAvg = NetChgAvg[1] + SF*(Change - NetChgAvg[1]);//這里也是代入上邊求得的相應(yīng)數(shù)值即可耳奕。//
TotChgAvg = TotChgAvg[1] + SF*(Abs(Change) - TotChgAvg[1]); //同上解讀。//
}
If(TotChgAvg <> 0)//假如變量TotChgAvg不等于0.//
{
ChgRatio = NetChgAvg/TotChgAvg;//則兩變量相除了诬像。//
}Else//等于0的屋群。//
{
ChgRatio = 0;//變量ChgRatio=0了。//
}
RSIValue = 50*(ChgRatio + 1);//指標(biāo)RSI的計(jì)算結(jié)果坏挠。//
ExitHiBand = Highest(High,20); // 唐奇安通道上軌芍躏。//
ExitLoBand = Lowest(Low,20);// 唐奇安通道下軌。//
If(myPosition == 1 And myPosition[1] == 1 and Low <= ExitLoBand[1])// 持有多單時(shí)降狠,下破唐奇安通道下軌对竣,平多單。//
{
myExitPrice = Min(Open,ExitLoBand[1]);//出場(chǎng)價(jià)的計(jì)算榜配,開盤價(jià)與前一個(gè)唐奇安通道下軌的比較否纬,取較小值。//
Sell(0,myExitPrice);//平倉(cāng)芥牌。//
myProfit = myExitPrice - MyEntryPrice;//利潤(rùn)算法烦味。//
????myPosition = 0;//持倉(cāng)多空標(biāo)志myPosition = 0.//
}
If(myPosition == 0 And myPosition[1] == 0 And AvgValue1[1] > AvgValue2[1] And RSIValue[1] < OverBought and High >= High[1])// 模擬交易產(chǎn)生一次虧損、短期均線在長(zhǎng)期均線之上壁拉、RSI低于超買值谬俄、創(chuàng)新高,則開多單弃理。//
{
myEntryPrice = Max(Open,High[1]);//進(jìn)場(chǎng)價(jià)計(jì)算溃论,即開盤價(jià)與前一個(gè)最高價(jià)的比較,取較大值痘昌。//
myPosition = 1;//持倉(cāng)多空標(biāo)志myPosition = 1.//
If(myProfit < 0) Buy(Lots,myEntryPrice);//假如利潤(rùn)myProfit <0的钥勋,以進(jìn)場(chǎng)價(jià)開倉(cāng)炬转。//
}
End
做空代碼及結(jié)果如下:
Params
Numeric FastLength(9);
Numeric SlowLength(19);
Numeric Length(9);
Numeric OverSold(30);
Numeric OverBought(70);
Numeric Lots(0);
Vars
NumericSeries AvgValue1; ?
NumericSeries AvgValue2;
NumericSeries NetChgAvg(0);
NumericSeries TotChgAvg(0);
Numeric SF(0);
Numeric Change(0);
Numeric ChgRatio(0);
NumericSeries RSIValue;
NumericSeries ExitHiBand(0);
NumericSeries ExitLoBand(0);
NumericSeries myEntryPrice(0);
NumericSeries myExitPrice(0);
NumericSeries myProfit(0);
NumericSeries myPosition(0);
Begin
If(!CallAuctionFilter()) Return;
AvgValue1 = Xaverage(Close,FastLength);
AvgValue2 = Xaverage(Close,SlowLength);
If(CurrentBar <= Length - 1)
{
NetChgAvg = (Close - Close[Length])/Length;
TotChgAvg = Average(Abs(Close - Close[1]),Length);
}Else
{
SF = 1/Length;
Change = Close - Close[1];
NetChgAvg = NetChgAvg[1] + SF*(Change - NetChgAvg[1]);
TotChgAvg = TotChgAvg[1] + SF*(Abs(Change) - TotChgAvg[1]);
}
If(TotChgAvg <> 0)
{
ChgRatio = NetChgAvg/TotChgAvg;
}Else
{
ChgRatio = 0;
}
RSIValue = 50*(ChgRatio + 1);
ExitHiBand = Highest(High,20);
ExitLoBand = Lowest(Low,20);
If(myPosition == -1 And myPosition[1] == -1 and High >= ExitHiBand[1])
{
myExitPrice = Max(Open,ExitHiBand[1]);
BuyToCover(0,myExitPrice);
myProfit = myEntryPrice - MyExitPrice;
????myPosition = 0;
}
If(myPosition == 0 And myPosition[1] == 0 And AvgValue1[1] < AvgValue2[1] And RSIValue[1] > OverSold and Low <= Low[1])
{
myEntryPrice = Min(Open,Low[1]);
myPosition = -1;
If(myProfit < 0) SellShort(Lots,myEntryPrice);
}
End