EasyTrader ArtNo 255
延續前文根據行情趨勢的觀察,發表了一篇若當日行情出現上沖下洗約 0.5% 的後市可能會有一段短暫行情,借用該文章的圖如下,我們來看看能否發展成策略 !測試程式碼
input:EntryType(1),ExitType(4);
inputs:NBarL(22),NBarS(21),TradeProfit(0.05),TradeStopLoss(0.01),ATRs_L(10.7),ATRs_S(6.4);
vars: IsBalanceDay(False),MP(0),PF(0),PL(0),HLRange(100);
inputs:Pcnt(0.5),AvgLen(8),EntLen(8),ExtLen(2),ATRLen(3),ATRPcntS(3),HighBar(3),LowBar(3);
Vars: Counter(0),HighA(0),HighB(0),LowA(0),LowB(0),Trigger(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 ;
{ 變數Counter用來計算振幅符合條件的次數 }
if Date <> date[1] then Counter = 0 ;
{ 利用 HighA/LowA , HighB/LowB 記錄最近兩次的K棒高低點 , 在初步測試中 ,由於符合條件的兩根K棒高低差的差距有可能太近造成交易次數很多,因此加上近幾根振幅的平均值來調整}
{ 初始值設定 }
if BarNumber = 1 then begin
HighA = High+Average(Range,EntLen) ;
HighB = High+Average(Range,EntLen) ;
LowA = Low-Average(Range,ExtLen) ;
LowB = Low-Average(Range,ExtLen) ;
end;
{ 當K棒振幅大於過去 N 根振幅平均值時 ,儲存高低點變數值 }
{ 計數器 Counter + 1 }
if Range >= Average(Range,AvgLen)[1] * Pcnt then Begin
HighA = HighB ;
LowA = LowB ;
HighB = High+Average(Range,EntLen) ;
LowB = Low-Average(Range,ExtLen);
Counter = Counter + 1 ;
end;
{ 策略一 當日計數器達到二次時,進場 Trigger成立 ,一直到有進場部位後 Trigger才取消}
if EntryType = 1 then begin
if Counter = 2 then Trigger = true ;
if Trigger then begin
if MP = 0 then Buy next bar at MaxList(HighA,HighB) stop ; {以最近兩組K棒的最高值作多 }
if MP = 0 then Sell next bar at at MinList(LowA,LowB) stop ; {以最近兩組K棒的最低值作空 }
end;
if MP <> MP[1] then Trigger = false ;
end;
{ 策略二 直接以最近兩組的K棒高低點作進場依據 }
if EntryType = 2 then begin
if MP = 0 then Buy next bar at MaxList(HighA,HighB) stop ;
if MP = 0 then Sell next bar at at MinList(LowA,LowB) stop ;
end;
{Exits}
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 ;
策略一台指期 60 min K 留倉 交易期間 2005/3/21 ~ 2015/3/20 交易成本 1200
策略二台指期 60 min K 留倉 交易期間 2005/3/21 ~ 2015/3/20 交易成本 1200
0 留言:
張貼留言
如果有私人問題想請教,請透過網站右方『與站長聯絡』之表單,謝謝!