EasyTrader ArtNo 099
在 EasyTrader程式交易入門教材 裡有放了國外知名指標 Dual Thrust的指標程式碼,近日觀盤篇-箱型指標系列文章點閱次數突然增加,因此將 Dual Thrust的策略程式碼拿來作測試提供讀者參考! Dual Thrust,曾長期排名 Future Trust雜誌最賺錢的策略。該策略在形式上和開盤區間突破(RangeBreak)策略類似。不同點主要在兩方面:
1.Dual Thrust在Range的設定上,引入前N日的四個價位,使得一定時期內的Range相對穩定
2.Dual Thrust對於多空的觸發點,考慮了非對稱的方式,多空參考的振幅可以選擇不同的日數,也可以通過參數K1和K2來確定。
交易者在使用該策略時,可以參考歷史回測的最佳化參數,動態調整K1和K2的值。
測試程式碼如下
Inputs: K1(.5),K2(.5),Mday(1),Nday(1);
Vars: BuyRange(0), SellRange(0);
Vars: BuyTrig(0),SellTrig(0);
Vars: HH(0),LL(0),HC(0),LC(0);
vars: IsBalanceDay(False),MP(0) ;
MP = MarketPosition ;
if DAYofMonth(Date) > 14 and DAYofMonth(Date) < 22 and DAYofWeek(Date)= 3 then isBalanceDay = True else isBalanceDay =False ;
If CurrentBar > 1 Then Begin
HH = Highest(High,Mday);
HC = Highest(Close,Mday);
LL = Lowest(Low,Mday);
LC = Lowest(Close,Mday);
If (HH - LC) >= (HC - LL) Then Begin
SellRange = HH - LC;
End Else Begin
SellRange = HC - LL;
End;
HH = Highest(High,Nday);
HC = Highest(Close,Nday);
LL = Lowest(Low,Nday);
LC = Lowest(Close,Nday);
If (HH - LC) >= (HC - LL) Then Begin
BuyRange = HH - LC;
End Else Begin
BuyRange = HC - LL;
End;
BuyTrig = K1*BuyRange;
SellTrig = K2*SellRange;
If MarketPosition = 0 Then Begin
Buy at Open of next bar + BuyTrig Stop;
Sell at Open of next bar - SellTrig Stop;
End;
If MarketPosition = -1 Then Begin
Buy at Open of next bar + Buytrig Stop;
End;
If MarketPosition = 1 Then Begin
Sell at Open of next bar - SellTrig Stop;
End;
End;
{ 停損 / 停利 }
PF = AvgPrice*TradeProfit ;
PL = AvgPrice*TradeStopLoss ;
if MP <> 0 then Begin
if MP > 0 and Low < EntryPrice*(1-TradeStopLoss) then
ExitLong next bar at EntryPrice*(1-TradeStopLoss) stop ;
if MP > 0 and High > EntryPrice*(1+TradeProfit) then
if MP > 0 and High > EntryPrice*(1+TradeProfit) then
ExitLong next bar at EntryPrice*(1+TradeProfit) stop ;
if MP < 0 and High > EntryPrice*(1+TradeStopLoss) then
if MP < 0 and High > EntryPrice*(1+TradeStopLoss) then
ExitShort next bar at EntryPrice*(1+TradeStopLoss) stop ;
if MP < 0 and Low < EntryPrice*(1-TradeProfit) then
if MP < 0 and Low < EntryPrice*(1-TradeProfit) then
請問如意多空網是什麼指標阿?
回覆刪除自訂義的濾網
回覆刪除