Strategy XXDJI-M5-EngulfingGap

Viewing 15 posts - 1 through 15 (of 35 total)
  • Author
    Posts
  • #131368 quote
    Dow Jones
    Participant
    Veteran

    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.

    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 =====
    
    swedshare, keewee and Piston_Broke thanked this post
    #131386 quote
    swedshare
    Participant
    Senior

    I don’t get a single trade… regardless of time settings.

    #131401 quote
    Sebastian Arsjo
    Participant
    Junior

    Strange works fine for me

    #131468 quote
    swedshare
    Participant
    Senior

    It worked after a reboot. Thanks!

    #131611 quote
    darbes
    Participant
    Average

    Back testing over 10000 occurrences  from today is very negative. Did I miss something ? How about you ?

    #131677 quote
    discomusic
    Participant
    Junior

    wow! Great work! Thanks…

    Where can I change the time zone? I do not know well Prorealtime yet..

    #131727 quote
    Dow Jones
    Participant
    Veteran

    Where can I change the time zone?

    You can change the Time Zone from Options -> Platform options -> Time zones & Trading hours -> Display all data in this time zone: <select the UTC+0800>

    #134071 quote
    Piston_Broke
    Participant
    Junior

    Hi…

    I can’t get much more than 8% on total return. I have changed the PR Time to read UTC+8. Is there anything else I may be doing wrong?

     

    I am in UK using Spread bet demo if that helps?

     

    Thanks

    #134083 quote
    thhonyy
    Participant
    New

    Hi,

    Well done!….but i got a syntaxe message asking me to define : bolltrendperiod/bolltrendperiod2 and strdperiod….

    They are written at the top of the code…I tried to write them in the lines but it doesn’work.

     

    Regards

    Tono

    #134086 quote
    Dow Jones
    Participant
    Veteran

    i got a syntaxe message

    These are variables, if you are copying the code manually, then you need to add them into variable window. Otherwise, you can just import the .itf attached in the first thread. It includes the variables, spread, etc…

    #134087 quote
    Dow Jones
    Participant
    Veteran

    I may be doing wrong

    Hard to say what problem, do you define the unit to 100k or 200k bar? Maybe post some screen shots to help.

    #134610 quote
    thhonyy
    Participant
    New

    Thanks for your help,I’ve made a copy/paste of the page,I’ll try the import….

    #143249 quote
    Anonymous
    Inactive
    New

    Ca gave, quelquesoit le code qu’on copie y’a toujours une merde…

    #143251 quote
    Anonymous
    Inactive
    New

    même chose en téléchargeant directement le fichier .ITF

    #143271 quote
    Léo
    Participant
    Average

    Hi Lino,

    I would asume you have to replace line 4/5/6 as below (remove the /):

    //atrperiod = 18
    //bolltrendperiod2 = 24
    //bolltrendperiod2 = 80
    by
    atrperiod = 18
    bolltrendperiod2 = 24
    bolltrendperiod2 = 80
    On my side, when I want to launch the code I have the error message below “The code is invalide, please correct it” (translated from french), while i have no issues highlighted in the code itself.
    Can anyone explain me the task of lines 167 to 172 ? I have the feeling that some conditions are missing.
    //====== Enter market - end =====
    
    //====== Exit market - start =====
    IF NOT ONMARKET THEN
    
    ENDIF

    Thank you Dow Jones for your work.

    Alex.
    thanked this post
Viewing 15 posts - 1 through 15 (of 35 total)
  • You must be logged in to reply to this topic.

Strategy XXDJI-M5-EngulfingGap


ProOrder support

New Reply
Author
author-avatar
Dow Jones @yahootew3000 Participant
Summary

This topic contains 34 replies,
has 13 voices, and was last updated by ProRealAlgos
2 years, 6 months ago.

Topic Details
Forum: ProOrder support
Language: English
Started: 05/12/2020
Status: Active
Attachments: 14 files
Logo Logo
Loading...