2024年8月23日 星期五

小那斯達克(NQ)全時段交易回測篇 [01]

EasyTrader NQ_Test 01

CDP系統在計算時,首先以前一日行情的平均價值(即需求值CDP)及高低價的振盪波幅,來估算出今日的極高價AH、極低價AL及近高價NH、近低價NL等四個參考值來,依此再與今日的盤中走勢行情搭配分析,來判斷今日行情走勢的強弱度,作為短線進出的依據。

// Public Variable
vars:MP(0),PF(0),PL(0),BuyPrice(0),ShortPrice(0),BasePF(600),BasePL(300) ;
vars:BarPass(5),HLRange(0),WinPoint(0),HBarPos(0),LBarPos(0),ExitH(0),ExitL(0),TimeOK(false),EntryExitCond(false),SelectNo(0) ;
vars:jumpPoint(0) ;
jumpPoint = MinMove/PriceScale ;

//計算停損利參考值
//****************** 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,2500/BigPointValue) ;
PL = MinList(PL,1000/BigPointValue) ;

//計算 Macd 值
// ************ Macd *****************
vars:uDif(0),uMacd(0),uOsc(0),MacdLen(0) ;
MacdLen = MaxList(LenA1,LenB1) ;
if MacdLen > 12 then MacdLen = 12 ;
uDif = Macd((High+Low+Close*2)/4,IntPortion(MacdLen*1.3),MacdLen*3) ;
uMacd = Xaverage(uDif,MacdLen) ;
uOsc = uDif-uMacd ;

//計算 CDP 值
// ************ 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) ;

//計算 RSI 值
// ************ RSI *****************
vars:vRSIA(0),vRSIB(0),DivRSICondA(false),DivRSICondB(false) ;
vRSIA = RSI(Close,LenA1) ;
vRSIB = RSI(Close,LenB1) ;

//***************** BuyPrice & ShortPrice Setup *****************
if BuyMode = 50 then BuyPrice = HighW(1) ;
if ShortMode = 32 then ShortPrice = HighD(0)+MaxList(TrueRange*RatioS/10,6*jumpPoint) ;

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

// ******** CDP Entry ***********
//收盤價大於 NL值 且 MACD 多方趨勢 則收盤價突破設定價位做多
if MP <> 1 and Close > NL and uDif > 0 and uOsc > uOsc[1] and Close < BuyPrice then
Buy ("LE_CDP1") next bar at BuyPrice stop ;

//收盤價大於 NH值 且RSI值大於設定值 則收盤價突破設定價位做多
if MP <> 1 and Close > NH and vRSIA > HighBand*4 and Close < BuyPrice then
Buy ("LE_CDP2") next bar at BuyPrice stop ;

//基本停利/移動停損出場
// ************* Base Exit *************
if MP <> 0 then WinPoint = MaxPositionProfit/BigPointValue else WinPoint = 0 ;
if Mod(SE01,2) = 1 then begin

if MP > 0 then Sell ("1Trail_PL2_"+NumtoStr(Absvalue(EntryPrice-(HighSinceEntry-MinList((PL+PF)*0.5,PL))),0))
All Contracts next bar at HighSinceEntry-MinList((PL+PF)*0.5,PL) stop ;
if MP > 0 then Sell ("1LPF1_"+NumtoStr(PF,0)) All Contracts next bar at EntryPrice+PF limit ;;

//多單部位虧損大於預期 平倉出場
if MP > 0 and (BarsSinceEntry <= 300/Barinterval and maxpositionloss/currentcontracts < -700)
then Sell ("WrongEntryL14") next bar at Close stop ;

小那斯達克 留倉 交易週期 2018/1/1 ~ 2024/5/31 交易成本 USD 60









沒有留言:

張貼留言