2014年6月16日 星期一

三連發交易策略 Three In a Row [程式碼]

EasyTrader ArtNo 165
在Lars Kestner所著的 《QUANTITATIVE TRADING STRATEGIES》內介紹了很多不錯的交易新概念,本篇介紹 Three in a Row,是一個很簡單的交易策略

Three in a Row
You might be surprised at how well very simple ideas work. The principle of three in a row sounds simple, yet the results are very powerful. We buy when three conditions are met:
  • Today’s close is greater than the close five days ago. 
  • The close 5 days ago is greater than the close 10 days ago. 
  • The close 10 days ago is greater than the close 15 days ago. 
Short entries are similar, also requiring three conditions:
  • Today’s close is less than the close five days ago. 
  • The close 5 days ago is less than the close 10 days ago. 
  • The close 10 days ago is less than the close 15 days ago. 
接下來我們一起將這樣的描述轉成策略,並作台指期的應用測試

inputs: BarNo(5),NBarL(2),NBarS(2),TradeProfit(0.05),TradeStopLoss(0.02) ;
inputs: ATRs_L(2),ATRs_S(2);
vars: IsBalanceDay(False),MP(0),PF(0),PL(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 ;

if Close > Close[BarNo] and Close[BarNo] > Close[BarNo*2] and Close[BarNo*2] > Close[BarNo*3] then Buy next bar at Market ;

if Close < Close[BarNo] and Close[BarNo] < Close[BarNo*2] and Close[BarNo*2] < Close[BarNo*3] then Sell next bar at Market ;

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 ExitType = 5 then Begin

  {Inputs: ATRs_L(3);}
  Variables: PosHigh(0), ATRVal_L(0);
   ATRVal_L = AvgTrueRange(10) * ATRs_L;

   If BarsSinceEntry = 0 Then PosHigh = High;
   If MarketPosition = 1 Then Begin
      If High > PosHigh Then PosHigh = High;
      ExitLong ("ATR") Next Bar at PosHigh - ATRVal_L Stop;
   End else ExitLong ("ATR eb") Next bar at High - ATRVal_L Stop;
  {Inputs: ATRs_S(3);}
   Variables: PosLow(0), ATRVal_S(0);
   ATRVal_S = AvgTrueRange(10) * ATRs_S;

   If BarsSinceEntry = 0 Then PosLow = Low;

   If MarketPosition = -1 Then Begin
      If Low < PosLow Then PosLow = Low;
       ExitShort ("ATR_1") Next Bar at PosLow + ATRVal_S Stop;
    End else ExitShort ("ATR_1 eb") Next bar at Low + ATRVal_S Stop;
end;

if IsBalanceDay then setExitonClose ;

台指期 30分K 留倉 2004/5/31 ~2014/5/31 交易成本 1200 [原始策略]



是否有其他方式可以修正呢 ? 試試時間的濾網吧 !

台指期 30分K 留倉 2004/5/31 ~2014/5/31 交易成本 1200 [原始策略+時間濾網]



還不錯績效增加約一倍 ,次數下降約 25% ,可惜的是 MDD 沒什麼大變動

再加個平盤上才作多,平盤下才作空的濾網試試
台指期 30分K 留倉 2004/5/31 ~2014/5/31 交易成本 1200 [原始策略+時間濾網+平盤多空]



整體的效果在績效及交易次數與 MDD都有改善!不斷的嘗試總會給我們新的體驗
MagicQS084

沒有留言:

張貼留言