EasyTrader ArtNo 209
原文請參考 Turbo成交量邏輯 ,我根據原始邏輯元素作一點小修改,主要是將常數改為變數,多空參數不同,對台指期作測試測試程式碼
input:EntryType(0),ExitType(6) ;
input:NBarL(28),NBarS(3),TradeProfit(0.045),TradeStopLoss(0.025),ATRs_L(5.4),ATRs_S(10.9);
vars: IsBalanceDay(False),MP(0),PF(0),PL(0),HLRange(100);
input:MaLenL(24),MaLenS(2),EntL(2),EntS(4),FracL(0.05),FracS(0.05);
Vars:AvgVolumeL(0),TurboL(0),InvTurboL(0),MaWeightL(0),TurboMAL(0);
Vars:AvgVolumeS(0),TurboS(0),InvTurboS(0),MaWeightS(0),TurboMAS(0);
Vars:Voldata(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 DataCompression > 1 then VolData = Volume else VolData = Ticks ;
{ 多方環境設定 }
AvgVolumeL = Average(VolData, MaLenL);
if (Highest(AvgVolumeL, MaLenL) - Lowest(AvgVolumeL, MalenL)) <> 0 then
TurboL = (AvgVolumeL - Lowest(AvgVolumeL, MaLenL)) / (Highest(AvgVolumeL, MaLenL) - Lowest(AvgVolumeL, MalenL));
InvTurboL = 1 - TurboL;
If MaLenL > 2 Then MaWeightL = (2 / (1 + MaLenL)) Else MaWeightL = 0.67;
TurboMAL = TurboMAL * InvTurboL + AvgPrice * TurboL;
{ 空方環境設定 }
AvgVolumeS = Average(VolData, MaLenS);
if (Highest(AvgVolumeS, MaLenS) - Lowest(AvgVolumeS, MalenS)) <> 0 then
TurboS = (AvgVolumeS - Lowest(AvgVolumeS, MaLenS)) / (Highest(AvgVolumeS, MaLenS) - Lowest(AvgVolumeS, MalenS));
InvTurboS = 1 - TurboS;
If MaLenS > 2 Then MaWeightS = (2 / (1 + MaLenS)) Else MaWeightS = 0.67;
TurboMAS = TurboMAS * InvTurboS + AvgPrice * TurboS;
{ 多單進場 }
If MarketPosition = 0 and Close < TurboMAL and TurboMAL < TurboMAL[1] Then
Buy next bar at Highest(High, EntL) Stop;
{ 空單進場 }
If MarketPosition = 0 and Close > TurboMAS and TurboMAS > TurboMAS[1] Then
Sell next bar at Lowest(Low, EntS) Stop;
{ 原始出場規則 }
if ExitType = 6 then Begin
If MarketPosition = 1 and Close < TurboMAL Then Begin
ExitLong this bar on close;
ExitLong Tomorrow at EntryPrice * (1-FracL) Stop;
End;
If MarketPosition = -1 and Close > TurboMAS Then Begin
ExitShort this bar on close;
ExitShort Tomorrow at EntryPrice * (1+FracS) Stop;
End;
end;
{ 常用出場測試 }
if ExitType = 1 then SetStopLoss(PF * 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 then setExitonClose ;
台指期 日 K 多空留倉 交易週期 2004/8/31~ 2014/8/29 交易成本 1200
沒有留言:
張貼留言