2015年5月15日 星期五

簡單的 RSI 逆勢策略測試 [程式碼]

EasyTrader ArtNo 264
Wen大部落格分享了一個RSI逆勢策略,是利用RSI的動量來作為進出場依據,我覺得這動量的概念不錯,利用這個元素對台指期作了簡單的測試,結果還不錯。
指標程式碼 
inputs: periodL(3),periodS(3), momperiodL(10), momperiodS(10),buylevel(-15), selllevel(15);
vars: MomL(0),MomS(0),RSIGapL(0),RSIGapS(0);

MomL = RSI(close,periodL);
MomS = RSI(close,periodS);

RSIGapL = MomL - MomL[momperiodL] ;
RSIGapS = MomS - MomS[momperiodS] ;

Plot1(RSIGapL,"RSIGL") ;
Plot2(RSIGapS,"RSIGS") ;
Plot3(buylevel,"BL") ;
Plot4(SellLevel,"SL") ;


{系統參數與變數}
input:ExitType(0);
inputs:NBarL(10),NBarS(10),TradeProfit(0.035),TradeStopLoss(0.04),ATRs_L(12),ATRs_S(5);
vars: IsBalanceDay(False),MP(0),PF(0),PL(0);
inputs: periodL(3),periodS(3), momperiodL(10), momperiodS(10),buylevel(-15), selllevel(15),HighBar(12),LowBar(15);
vars: MomL(0),MomS(0),RSIGapL(0),RSIGapS(0);

MP = MarketPosition ;
if DAYofMonth(Date) > 14 and DAYofMonth(Date) < 22 and DAYofWeek(Date)= 3 then isBalanceDay = True else isBalanceDay =False ;

PF = AvgPrice*TradeProfit ;
PL = AvgPrice*TradeStopLoss ;

{分別計算多空不同的 RSI動量}
MomL = RSI(close,periodL);
MomS = RSI(close,periodS);

RSIGapL = MomL - MomL[momperiodL] ;
RSIGapS = MomS - MomS[momperiodS] ;

{ 只引用核心的元素邏輯作為進出場參考 }
if MP <> 1 and RSIGapL < BuyLevel then buy next bar at Highest(High,NBarS) stop ;
if MP <> -1 and RSIGapS > SellLevel then sell next bar at Lowest(Low,NBarL) stop;

if ExitType = 1 then SetStopLoss(PL * BigPointValue) ;

if ExitType = 2 then Begin
SetStopLoss(PL * BigPointValue) ;
setProfitTarget(PF * BigPointValue) ;
end;

if ExitType = 3 then Begin
if MP > 0 and BarsSinceEntry = NBarL then ExitLong next bar at Market ;
if MP < 0 and BarsSinceEntry = NBarS then ExitShort next bar at Market ;
end;

if ExitType = 4 then Begin
SetStopLoss(PL * BigPointValue) ;
setProfitTarget(PF * BigPointValue) ;
if MP > 0 and BarsSinceEntry = NBarL then {Sell } ExitLong next bar at Market ;
if MP < 0 and BarsSinceEntry = NBarS then {Buy} ExitShort next bar at Market ;
end;

if IsBalanceDay or date = 1150224 then setExitonClose ;
台指期 30 min K 多空留倉 交易週期 2005/2/1~ 2015/1/31 交易成本 1200

加上如意多空網台指期 30 min K 多空留倉 交易週期 2005/2/1~ 2015/1/31 交易成本 1200
MagicQS174

沒有留言:

張貼留言