Strategy XXDJI-M5-EngulfingGap

Category: Strategies By: Dow Jones Created: May 14, 2020, 8:12 AM
May 14, 2020, 8:12 AM
Strategies
1 Comment

Hi everyone,

Here is a new strategy on Wall Street/DJI 5 min TF based on the engulfing bar with range at least 1 ATR. Incorporated 2 Bollinger Band as trend filter.

DLS code is added to avoid high spread period and for skipping trade during major market open to avoid less reliable engulfing bar. Time Zone used is UTC+08:00, please change the time zone in PRT to obtain same result.

Variables atrperiod, bolltrendperiod and bolltrendperiod2 are used for optimization. Other variables are just taking moderate value, not being fully optimized.

Looking forward for your suggestion and ideas of improvement. Discussion here, https://www.prorealcode.com/topic/strategy-xxdji-m5-engulfinggap/

DEFPARAM CumulateOrders = false
DEFPARAM PRELOADBARS = 5000

//atrperiod = 18
//bolltrendperiod2 = 24
//bolltrendperiod2 = 80

SL = 100
stepfactor1 = 1
stepfactor2 = 0.25
RR = 4
longbar = 0
shortbar = 0
longbarmultiplier = 1
shortbarmultipler = 1.5
strend = 2
strend2 = 2
bollBullLevel = 50
bollBearLevel = 50
bolltrendMAType = 5
bolltrendMAType2 = 5

//// ---------   UK DAY LIGHT SAVINGS MONTHS      ---------------- //
mar = month = 3 // MONTH START
oct = month = 10 // MONTH END

IF ( dayofweek >= 0 and mar AND 31-day<7 ) OR ( month > 3 AND month < 10 ) OR ( oct AND 31-day > 6 )  OR  (dayofweek = 4 AND oct AND day<31) OR (dayofweek = 3 AND oct AND day+1<31) OR  (dayofweek = 2 AND oct AND day+2<31) OR (dayofweek = 1 AND oct AND day+3<31) OR (dayofweek = 0 AND oct AND day+4<31)  OR (dayofweek = 5 AND oct AND 31-day<7) THEN
UKDLS=1
ELSE
UKDLS=0
ENDIF
//GRAPH UKDLS as "UKDLS"

// ---------   US DAY LIGHT SAVINGS MONTHS      ---------------- //
mar = month = 3 // MONTH START
nov = month = 11 // MONTH END
IF (month > 3 AND month < 11) OR (mar AND day>14) OR (mar AND day-dayofweek>7) OR (nov AND day<=dayofweek AND day<7) THEN
USDLS=010000
ELSE
USDLS=0
ENDIF
//GRAPH USDLS as "USDLS"

// ---------   AU DAY LIGHT SAVINGS MONTHS      ---------------- //
oct = month = 10 // MONTH START
apr = month = 4 // MONTH END
IF (month > 10 OR month < 4) OR (apr AND day <=7 AND day<=dayofweek) OR (oct AND day > 7) OR (oct AND day <= 7 AND day>dayofweek) THEN
AUDLS=010000
ELSE
AUDLS=0
ENDIF
//GRAPH AUDLS as "AUDLS"
//GRAPH dayofweek
//GRAPH day

//Time in UTC+8
Rest0Minutes = 000000
Rest15Minutes = 001500
HighSpread1Start = 051500- USDLS
HighSpread1End = 053000 - USDLS
HighSpread2Start = 060000 - USDLS
HighSpread2End = 070000 - USDLS
IGAlmostClose = 054500 - USDLS
IGOpen = 070000 - USDLS
ASXOpen = 080000 - AUDLS
TSEOpen = 080000
SSEOpen = 091500
HKEOpen = 093000
FWBOpen = 150000 - UKDLS
LSEOpen = 160000 - UKDLS
NYSEOpen = 223000 - USDLS

//Skip high spread
timeok = NOT(time >=HighSpread1Start AND time <=HighSpread1End) AND NOT(time >=HighSpread2Start AND time <=HighSpread2End)
//Skip 15 mins when IG almost close
timeok = timeok AND NOT (time >=IGAlmostClose AND time <= IGAlmostClose + Rest15Minutes)
//Skip when IG just open the market
timeok = timeok AND NOT (time >=IGOpen AND time <=IGOpen + Rest0Minutes)

//Skip when ASX (first market) just open the market
timeok = timeok AND NOT (time >=ASXOpen AND time <=ASXOpen + Rest0Minutes)
//Skip when TSE (first major) just open the market
timeok = timeok AND NOT (time >=TSEOpen AND time <=TSEOpen + Rest0Minutes)

//Skip when SSE just open the market
timeok = timeok AND NOT (time >=SSEOpen AND time <=SSEOpen + Rest0Minutes)
//Skip when HKE just open the market
timeok = timeok AND NOT (time >=HKEOpen AND time <=HKEOpen + Rest0Minutes)

//Skip when FWB just open the market
timeok = timeok AND NOT (time >=FWBOpen AND time <=FWBOpen + Rest0Minutes)
//Skip when LSE just open the market
timeok = timeok AND NOT (time >=LSEOpen AND time <=LSEOpen + Rest0Minutes)

//Skip when NYSEjust open the market
timeok = timeok AND NOT (time >=NYSEOpen AND time <=NYSEOpen + Rest0Minutes)

once bolltrendBull = 1
once bolltrendBear = 1
//bolltrendperiod = 50
//strend = 2
bolltrendMA = average[bolltrendperiod, bolltrendMAType](close)//50,1
STDDEVtrend = STD[bolltrendperiod]
bolltrendUP = bolltrendMA + strend * STDDEVtrend
bolltrendDOWN = bolltrendMA - strend * STDDEVtrend
IF bolltrendUP = bolltrendDOWN THEN
bolltrendPercent = 50
ELSE
bolltrendPercent = 100 * (close - bolltrendDOWN) / (bolltrendUP - bolltrendDOWN)
ENDIF

//bolltrendperiod = 50
//strend = 2
bolltrendMA2 = average[bolltrendperiod2, bolltrendMAType2](close)//50,1
STDDEVtrend2 = STD[bolltrendperiod2]
bolltrendUP2 = bolltrendMA2 + strend2 * STDDEVtrend2
bolltrendDOWN2 = bolltrendMA2 - strend2 * STDDEVtrend2
IF bolltrendUP2 = bolltrendDOWN2 THEN
bolltrendPercent2 = 50
ELSE
bolltrendPercent2 = 100 * (close - bolltrendDOWN2) / (bolltrendUP2 - bolltrendDOWN2)
ENDIF


bolltrendBull = bolltrendPercent > bollBullLevel OR bolltrendPercent2 > bollBullLevel
bolltrendBear = bolltrendPercent < bollBearLevel OR bolltrendPercent2 < bollBearLevel

//====== Enter market - start =====

timeframe(5 minutes, updateonclose)

atr14 = AverageTrueRange[atrperiod](close)
C1 = bolltrendBull AND close[1] < open[1] AND close > open AND close > open[1] AND close - open > longbarmultiplier * atr14 + longbar
C2 = bolltrendBear AND close[1] > open[1] AND close < open AND close < open[1] AND open - close > shortbarmultipler * atr14 + shortbar

timeframe(default)

samebarsignal = 0

IF C1 THEN //when a pullback occurs...

IF timeok AND Not OnMarket AND samebarsignal = 0 THEN
BUY 1 CONTRACT AT MARKET
SET STOP   pLOSS   SL    //50
TP = RR * SL
SET TARGET pPROFIT TP   //300
ENDIF

samebarsignal = 1

ENDIF

//  SHORT side
IF C2  THEN //when a pullback occurs...

IF timeok AND Not OnMarket AND samebarsignal = 0 THEN
SELLSHORT 1 CONTRACT AT MARKET
SET STOP   pLOSS   SL    //50
TP = RR * SL
SET TARGET pPROFIT TP   //300
ENDIF

samebarsignal = 1

ENDIF

//====== Enter market - end =====

//====== Exit market - start =====
IF NOT ONMARKET THEN

ENDIF



//====== Exit market - end =====

//====== Trailing Stop mechanism - start =====


trailingstart = (stepfactor1 * SL ) / pointsize
trailingstep = (stepfactor2 * SL ) / pointsize

//resetting variables when no trades are on market
if not onmarket then
priceexit = 0
endif

//case LONG order
if longonmarket then

//first move (breakeven)
IF priceexit=0 AND close-tradeprice(1) >= trailingstart*pointsize THEN

priceexit = tradeprice(1) + trailingstep*pointsize

ENDIF
//next moves
IF priceexit>0 THEN
P2 = close-priceexit >= trailingstart*pointsize

IF P2 THEN
priceexit = priceexit + trailingstep*pointsize
ENDIF

ENDIF
endif

//case SHORT order
if shortonmarket then

//first move (breakeven)
IF priceexit=0 AND tradeprice(1)-close >= trailingstart*pointsize THEN

priceexit = tradeprice(1) - trailingstep*pointsize

ENDIF
//next moves
IF priceexit>0 THEN

P2 = priceexit-close >= trailingstart*pointsize

IF P2 THEN
priceexit = priceexit - trailingstep*pointsize
ENDIF

ENDIF

endif

//exit on trailing stop price levels
if onmarket and priceexit>0 then
EXITSHORT AT priceexit STOP
SELL AT priceexit STOP
endif
//====== Trailing Stop mechanism - end =====

 

Download
Filename: XXDJI-M5-EngulfingGap_wfa.png
Downloads: 267
Download
Filename: XXDJI-M5-EngulfingGap_result.png
Downloads: 509
Download
Filename: XXDJI-M5-EngulfingGapv1.itf
Downloads: 1347
Download
Filename: XXDJI-M5-EngulfingGap.png
Downloads: 306
Dow Jones Veteran
This author is like an anonymous function, present but not directly identifiable. More details on this code architect as soon as they exit 'incognito' mode.
Author’s Profile

Comments

Logo Logo
Loading...