2023年12月11日 星期一

★ 比特幣交易回測篇 [03]

EasyTrader 比特幣測試 03


// Public Variable
vars:MP(0),PF(0),PL(0),LotNum(1),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 ;

PF = MinList(PF,2700) ;
PL = MinList(PL,1350) ;

// ************ CDP *****************
vars:CDP(0),AH(0),NH(0),NL(0),AL(0),CDPrange(0),CrossA(false),CrossB(false),TH1(0),TL1(0),TH2(0),TL2(0) ;
if Date <> Date[1] then begin
   CDP = (HighD(1)+LowD(1)+2*CloseD(1))/4;
   AH = CDP + (HighD(1) - LowD(1));
   NH = CDP*2 - LowD(1);
   NL = 2*CDP - HighD(1);
   AL = CDP - (HighD(1) - LowD(1));
end ; 
CDPrange = HighD(1) - LowD(1) ;

// ************ for week High/Low box *****************
Vars:WeekLong(5),WeekShort(5),WH(0),WL(0),HLWeek(0),WCount(0),WBox33(0),WBox67(0) ;
WH =近週高點 ;
WL = 近週低點 ;

// ************* Time Set Up *************
TimeOK = ((time >= 1000 and time <= 1800)) ;

//***************** BuyPrice & ShortPrice Setup *****************
BuyPrice = NH+Range  ;
ShortPrice = WL+Range  ;

// ********** Main Strategy *********
// ********** Entry Method

// ******** Momentum Entry ***********
vars:SlowA(0),SlowB(0),AvgL(0),AvgS(0),MomCondL(false),MomCondS(false) ;
SlowA = Round(LenA1*(FracA+1),0) ;
SlowB = Round(LenB1*(FracB+1),0) ;
AvgL = Average(Close,LenA1) ;
AvgS = Average(Close,LenB1) ;
MomCondL = Close > Close[LenA1] and Close > Close[SlowA] and AvgL > AvgL[1] ;
MomCondS = Close < Close[LenB1] and Close < Close[SlowB] and AvgS < AvgS[1] ;


   if TimeOK then begin
      if MP <> 1 and MomCondL and Close < BuyPrice 
         then Buy ("LE_MoMT") LotNum Contracts next bar at BuyPrice stop ;
      if MP <> -1 and MomCondS and Close > ShortPrice 
         then Sellshort ("SE_MoMT") LotNum Contracts next bar at ShortPrice Stop ;
   end ;


// ************* Base Exit *************
if MP > 0 then Sell ("Trail_PL1_"+NumtoStr(Absvalue(EntryPrice-(HighSinceEntry-MinList(PL,PF))),2)) 
   All Contracts next bar at HighSinceEntry-MinList(PL,PF) stop ;
if MP > 0 then Sell ("PF1_"+NumtoStr(PF,0)) All Contracts next bar at EntryPrice+PF limit ;
if MP < 0 then BuytoCover ("Trail_PL2_"+NumtoStr(Absvalue(EntryPrice-(LowSinceEntry+MinList(PL,PF))),2)) 
   All Contracts next bar at LowSinceEntry+MinList(PL,PF) stop ;
if MP < 0 then BuytoCover ("PF2_"+NumtoStr(PF,0)) All Contracts next bar at EntryPrice-PF limit ;

比特幣  留倉 交易週期 2017/6/1 ~ 2023 交易成本 交易量*0.1%








沒有留言:

張貼留言