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:

  1. Today’s close is greater than the close five days ago.
  2. The close 5 days ago is greater than the close 10 days ago.
  3. The close 10 days ago is greater than the close 15 days ago.
Short entries are similar, also requiring three conditions:
  1. Today’s close is less than the close five days ago.
  2. The close 5 days ago is less than the close 10 days ago.
  3. 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都有改善!不斷的嘗試總會給我們新的體驗

0 留言:

張貼留言

如果有私人問題想請教,請透過網站右方『與站長聯絡』之表單,謝謝!

----------------------------------------------------------------------------------------------------
網站聲明(Disclaimer)
本教學網站內所提供之程式碼(包括函數、指標、訊號)屬開放程式碼,用意在於讓使用者學習程式語法之撰寫,使用者可以任意修改語法內容並調整參數。本網站所有之內容(包括文章、影片、歷史紀錄、程式碼、教材)限用於個人學習使用,請勿轉寄、濫用,嚴禁私自串接帳戶交易。
-------------------------------------------------------------------------------------------------