交易策略的原始想法是
1. 當 15根K棒前出現 近20根K棒新高時進場作多
2. 當 15根K棒前出現 近20根K棒新低時進場作空
根據這樣的邏輯我們先作一個指標圖方便進出點位的觀察
{系統參數與變數}
input:EntryType(1),ExitType(2);
inputs:NBarL(25),NBarS(45),TradeProfit(0.05),TradeStopLoss(0.035),ATRs_L(0.75),ATRs_S(3.5),ADXLen(25);
vars: IsBalanceDay(False),MP(0),PF(0),PL(0);
inputs: ChanLenA(8),DelayA(21),ChanLenB(41), DelayB(3),AvgL(3),AvgS(5),HighBar(5),LowBar(5);
Vars: UPChanA(0), DnChanA(0),UPChanB(0), DnChanB(0), PositionFlag(0);
Vars: FilterA(false),FilterB(false),FilterC(false),FilterD(false) ;
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 ;
{建立多空不同的通道}
UPChanA = Highest(High, ChanLenA)[DelayA];
DnChanA = Lowest(Low, ChanLenA)[DelayA];
UPChanB = Highest(High, ChanLenB)[DelayB];
DnChanB = Lowest(Low, ChanLenB)[DelayB];
{確認倉位維持狀況}
If MP = 1 Then PositionFlag = 1; If MP = -1 Then PositionFlag = -1;
{建立 ADX濾網 與 價格濾網作比較 }
FilterA = ADX(ChanLenA) > ADX(ChanLenA)[1] and ADX(ChanLenA) > ADXLen ;
FilterB = ADX(ChanLenB) > ADX(ChanLenB)[1] and ADX(ChanLenB) < ADXLen ;
FilterC = Close < UPChanA ; FilterD = Close > DnChanB ;
{進場方式 1 ,通道界限突破/跌破 進場 }
if EntryType = 1 then Begin
If PositionFlag <> 1 AND MP <> 1 Then Buy Next Bar at UPChanA + 1 Point Stop;
If PositionFlag <> -1 AND MP <> -1 Then Sell Next Bar at DnChanB - 1 Point Stop;
end;
{ 透過回測的進出點位觀察,我加入以下兩個濾網來協助降低交易次數與提高勝率}
{進場方式 2 ,通道界限突破/跌破 + ADX 濾網 + 價格濾網 進場 }
{價格濾網主要是限制進場前的價格必需在通道內 }
if EntryType = 2 then Begin
If FilterA and PositionFlag <> 1 AND MP <> 1 and FilterC Then Buy Next Bar at UPChanA + 1 Point Stop;
If FilterB and PositionFlag <> -1 AND MP <> -1 and FilterD Then Sell Next Bar at DnChanB - 1 Point Stop;
end;
{ 出場選擇 }
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 ;
進場方式 1 - 台指期 30 min K 多空留倉 交易週期 2005/3/1~ 2015/2/28 交易成本 1200
進場方式 2 - 台指期 30 min K 多空留倉 交易週期 2005/3/1~ 2015/2/28 交易成本 1200
策略開發過程中的修正,常常來自於實際進出點位的觀察,以此例而言進場前先確認價格回到通道區間內,主要是避免平倉出場後的下一根K棒立即進場,降低追高殺低的滑價損失。
0 意見:
張貼留言