EasyTrader ArtNo 089
之前在國外網站上有看到用最高價對最低價的比例當作隔日買賣點位的參考,而我以前最常學習的網站除了 Wen大的[程式交易≠Holy Grail] ,還有一個是 痞客邦 Ray大的 Ray's Blog ,也有一篇 台指期 30K波段策略 運用同樣的方式,只是程式使用了一個蠻特別的邏輯,歷史回測的績效曲線相當不錯.本篇依據 Ray大所提示的邏輯規則,作成測試程式碼並加上如意多空網與出場規則
基本設定: 台指期 留倉 回測週期 2001/1~2013/10/31 交易成本 1200
input:ExitType(1),upratio(1),dnratio(1),TradeStopLoss(0.01),TradeProfit(0.03),NBarL(2),NBarS(2) ;
vars:SQHigh(0),SQLow(0),LongRatio(0),ShortRatio(0),PL(0),PF(0);
vars:BuyPoint(0),SellPoint(0),MP(0),isBalanceDay(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 ;
if DataCompression <= 1 then Begin
if HighD(1) > 0 then SQHigh=SquareRoot(HighD(1));
if LowD(1) > 0 then SQLow=SquareRoot(LowD(1));
end else Begin
if High[1] > 0 then SQHigh=SquareRoot(High[1]);
if Low[1] > 0 then SQLow=SquareRoot(Low[1]);
end;
if SQHigh <>0 and SQLow <>0 then begin
LongRatio=SQHigh/SQLow;
ShortRatio=SQLow/SQHigh;
end;
if DataCompression <= 1 then Begin
BuyPoint=LongRatio*CloseD(1)*upratio;
SellPoint=ShortRatio*CloseD(1)*dnratio;
end else begin
BuyPoint=LongRatio*Close[1]*upratio;
SellPoint=ShortRatio*Close[1]*dnratio;
end;
if _MagicQF001(1) > 0 and EntriesToday(date) = 0 then
buy next bar at BuyPoint+1 Stop;
if _MagicQF001(1) < 0 and EntriesToday(date) = 0 then
sell next bar at SellPoint-1 stop ;
if _MagicQF001(1) < 0 and EntriesToday(date) = 0 then
sell next bar at BuyPoint-1 stop;
if _MagicQF001(1) > 0 and EntriesToday(date) = 0 then
buy next bar at SellPoint+1 stop;
SetStopLoss(PL * BigPointValue) ;
if ExitType = 1 then SetProfitTarget(PF * BigPointValue) ;
if ExitType = 2 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 = 3 then begin
SetProfitTarget(PF * BigPointValue) ;
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 IsBalanceDay = True then SetExitonClose ;
60 分K回測結果
30 分K回測結果
跟上一篇一樣,加入如意多空網,整體績效助益不少,特別是 60分K的 MDD 降低約 40%
60 分K回測結果
30 分K回測結果
跟上一篇一樣,加入如意多空網,整體績效助益不少,特別是 60分K的 MDD 降低約 40%
MagicQS033
hi, _MagicQF001(1) , 你能提供嗎
回覆刪除不好意思 沒提供喔
回覆刪除