已經(jīng)通過編譯的開拓者順勢模型源碼 已經(jīng)在做paper的壓力測試[開拓者公式]
- 讓大家不要再在這里坑掉,浪費寶貴時間去查信號消失,能專心寫策略.
說明:這是一個很簡單的順勢模型,已經(jīng)通過編譯,沒有 IF while的問題.
進程:已經(jīng)在做paper的壓力測試,所以offset我一般會設(shè)置大點,或者極端點. 老外一般都很喜歡把事情做極端,這樣才不會出問題,一般問題都小CASE了.中國人都喜歡把問題往好了改.
問題:paper測試中出現(xiàn)的問題. 1.出現(xiàn)最后的bar的交易時間提示,模型算法無效. 2. KD信號消失,提示與模型不符,要我檢查算法.
排查:1.基本的公式計算. 2.系統(tǒng)的函數(shù).
針對:1.RSV這個是標準的KD代碼,我只是簡單的移植,這個出問題的概率不大.
我查了下資料,有2種說法,一是說是crossover有問題,我看了下別人的源碼,也有用crossover.為了避免K=D的假信號,我用必須'大于'(或者是小于)來過濾假信號.
2.就是大家詬病的close函數(shù),這個我正在換算法.或者換其它函數(shù). 現(xiàn)在用的是open等結(jié)果.
//源碼:
Params
Numeric Length(30); //N 30
Numeric SlowLength(10); //M1
Numeric SmoothLength(10); //M2
Numeric lots(1);
Numeric offset(2);
Numeric Stoploss(40);
Vars
NumericSeries HighestValue;
NumericSeries LowestValue;
NumericSeries KValue;//TB中的K值
NumericSeries DValue;//TB中的K值
NumericSeries RSV;
NumericSeries K1;//正規(guī)的K值
NumericSeries D1;//正規(guī)的D值
Numeric i_offset;
Numeric BuyPosition;
Numeric SellPosition;
Numeric myEntryPrice;
Numeric myExitPrice;
Begin
{
HighestValue = HighestFC(High, Length);
LowestValue = LowestFC(Low, Length);
RSV = (Close-LowestValue)/(HighestValue-LowestValue)*100;
K1 = SMA(RSV,SlowLength,1);
D1 = SMA(K1,SmoothLength,1);
KValue = SummationFC(Close - LowestValue,SlowLength)/SummationFC(HighestValue-LowestValue,SlowLength)*100;
DValue = AverageFC(KValue,SmoothLength);
PlotNumeric("RSV",RSV);
if(MarketPosition == 0)
{
if(K1 > D1)
{
buy(lots,high); //<---原來這里用的buy(lots,close[1]);
Return;
}
}
else if (MarketPosition == 1) //平多
{
if(K1 < D1)
{
sell(lots,open);//<--這里用的是sell(lots,close);
Return;
}
}
//止損
If(MarketPosition == 1)
{
If(Low < EntryPrice - StopLoss * MinMove*PriceScale)
{
myExitPrice = EntryPrice - (StopLoss+1) * MinMove*PriceScale;
myExitPrice = max(low,myExitPrice);
Sell(lots,myExitPrice);
}
}
Else If(MarketPosition == -1)
{
If(High > EntryPrice + StopLoss * MinMove*PriceScale)
{
myExitPrice = EntryPrice + (StopLoss+1) * MinMove*PriceScale;
myExitPrice = min(high,myExitPrice);
BuyToCover(lots,myExitPrice);
}
}
}
end
有思路,想編寫各種指標公式,程序化交易模型,選股公式,預警公式的朋友
可聯(lián)系技術(shù)人員 QQ: 262069696 進行 有償 編寫!(不貴!點擊查看價格!)
相關(guān)文章
-
沒有相關(guān)內(nèi)容