2023年3月1日 星期三

台指期全時段交易回測篇 [7]

EasyTrader TestNo 007

參考文章 簡單特別的交易系统 Part 2
// Public Variable
vars:MP(0),PF(0),PL(0),DayLast(1345),NightLast(0500),BuyPrice(0),ShortPrice(0),BasePF(150),BasePL(100),FilterA(0),FilterB(0) ;
vars:BarPass(5),HLRange(0),WinPoint(0),HBarPos(0),LBarPos(0),ExitH(0),ExitL(0),TimeOK(false),EntryExitCond(false),SelectNo(0) ;

//****************** Basic Setup ****************************************
MP = MarketPosition ;
if MP <> 0 then Begin
PF = EntryPrice*TradeProfit ;
PL = EntryPrice*TradeStopLoss ;
end else begin
PF = AvgPrice*TradeProfit ;
PL = AvgPrice*TradeStopLoss ;
end ;

// 依據目前指數來設定最大停利與停損點數
if Close > 10000 then begin
BasePF = BasePF+IntPortion((Close-10000)/1000)*30 ;
BasePF = MinList(BasePF,450) ;
BasePL = BasePL+IntPortion((Close-10000)/1000)*15 ;
BasePL = MinList(BasePL,225) ;
end ;

PF = MinList(PF,BasePF) ;
PL = MinList(PL,BasePL)*iff(CurrentContracts=1,1,0.67) ;

// ************* Time Set Up *************
TimeOK = ((time >= 0900 and time <= 1200) or (time >= 2130) or time <= 0300) ;

// ********** Main Strategy *********
//依據前一日振幅大小與K棒實體比例做多或做空
{ Volatility ExPansion System }

vars: VED(0),DBody(0) ;

VED = HighD(1)-LowD(1) ;
if absvalue(CloseD(1)-OpenD(1)) <> 0 then DBody = absvalue(CloseD(1)-OpenD(1))/VED ;

if TimeOK then begin
//前一日振幅<150且K棒實體比例 > 0.65 則在下根K棒開盤價加前日振幅比例做多
if MP <> 1 and VED < 150 and DBody > 0.65 then Buy ("MQS12_LE2T") next bar at Open next bar + MaxList(VED*FracA/6,21) stop ;
//前一日振幅<150且K棒實體比例 > 0.65 則在下根K棒開盤價減前日振幅比例做空
if MP <> -1 and VED < 150 and DBody > 0.65 then SellShort ("MQS12_SE2T") next bar at Open next bar - MaxList(VED*FracB/6,34) stop ;
end ;

if TimeOK then begin
//前一日振幅<150且K棒實體比例 < 0.35 則在當日K棒開盤價加前日振幅比例做多
if MP <> 1 and VED < 150 and DBody < 0.35 then Buy ("MQS12_LE8T") next bar at OpenD(0) + MaxList(VED*FracA/3,13) stop ;
//前一日振幅<150且K棒實體比例 < 0.35 則在當日K棒開盤價減前日振幅比例做空
if MP <> -1 and VED < 150 and DBody < 0.35 then SellShort ("MQS12_SE8T") next bar at OpenD(0) - MaxList(VED*FracB/3,21) stop ;
end ;


//基本停利停損出場
// ************* Base Exit *************
if MP > 0 then Sell ("PL1_"+NumtoStr(PL,0)) next bar at EntryPrice-PL stop ;
if MP > 0 then Sell ("PF1_"+NumtoStr(PF,0)) next bar at EntryPrice+PF limit ;
if MP < 0 then BuytoCover ("PL2_"+NumtoStr(PL,0)) next bar at EntryPrice+PL stop ;
if MP < 0 then BuytoCover ("PF2_"+NumtoStr(PF,0)) next bar at EntryPrice-PF limit ;

//進場後部位獲利小於預期則出場
if MP < 0 and (BarsSinceEntry >= 300/Barinterval and MaxPositionprofit/currentcontracts < 5000)
then Buytocover ("WrongEntryS5") next bar at Close stop ;

//賽塔支撐壓力 做反手單
// ************* Rev Saita Range Exit *************
vars:vSupport(0),vResistance(99999),LXtemp(0),SXtemp(0);
if ExtNum01 = 16 or ExtNum02 = 16 then Begin
if MP <> MP[1] and MP > 0 then vSupport = EntryPrice-PL ;
if MP <> MP[1] and MP < 0 then vResistance = EntryPrice+PL ;
if Close Cross over Average(High,HBar) then vSupport = Lowest(Close,HBar) ;
if Close Cross under Average(Low,LBar) then vResistance = Highest(Close,LBar) ;

LXtemp = MinList(EntryPrice-PL,vSupport-Range) ;
If MP > 0 and BarsSinceEntry > 0 and Close > LXtemp then SellShort ("rLX_Saita") Next Bar at LXtemp Stop ;

SXtemp = MaxList(EntryPrice+PL,vResistance+Range) ;
If MP < 0 and BarsSinceEntry > 0 and Close < SXtemp then Buy ("rSX_Saita") Next Bar at SXtemp Stop ;
end ;

//每日固定時間若符合條件則出場
// ************* FixTime Exit *************
vars:FT033(0),Condition33(false) ;
FT033 = IntPortion((1200/Barinterval)*0.33) ;
Condition33 = (time = CalcTime(0000,FT033*BarInterVal)) ;

if MP < 0 and Condition33 and Close > HighD(1) then buytocover ("SX_FT033") next bar at High stop;
if MP > 0 and Condition33 and Close < LowD(1) then Sell ("LX_FT033") next bar at Low stop;

//結算日出場
if _IsSettlementDay and time >= CalcTime(1300,-1*BarInterVal) and Time <= 1330 then begin
if MP > 0 then Sell ("LX_Bal") next bar at market ;
if MP < 0 then BuyToCover ("SX_Bal") next bar at market ;
end;

台指期  留倉 交易週期 2018/1/1 ~ 2022/12/31 交易成本 1200





沒有留言:

張貼留言