Strategy XXDJI-M5-EngulfingGap

Viewing 5 posts - 31 through 35 (of 35 total)
  • Author
    Posts
  • #169817 quote
    Roberto BlázquezRoberto Blázquez
    Participant
    New

    Thank you. On my charting artist I can only have a history of 1 year. If anyone could prove it for many more years, I’d appreciate it if you’d pass the statistics. Greetings.

    #176233 quote
    johnjamesmarshjohnjamesmarsh
    Participant
    New

    Excellent bit of code. I’m not getting the same results as you so I guess I need to understand it now and work out what changes are required to make it work today.

     

    Thanks for sharing.

    #206329 quote
    thomas2004chthomas2004ch
    Participant
    Senior

    Hi,

    I apply this strategy on daily SPY but I got error. Is this startegy suitable for daily SPY?

    #206331 quote
    GraHalGraHal
    Participant
    Master

    What error are you getting / seeing … post a screenshot?

    #217933 quote
    ProRealAlgosProRealAlgos
    Participant
    Junior

    Interesting code. I made some adjustments to adapt it to the DAX index on the 5 minute timeframe. I would say it’s a high risk it’s overly optimized though.
    Here’s the code

     

    DEFPARAM CumulateOrders = false
    DEFPARAM PRELOADBARS = 5000
    
    atrperiod = 18
    bolltrendperiod = 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(30 minutes, updateonclose)
    
    ma1 = Average[45](typicalPrice)
    ma2 = Average[15](typicalPrice)
    c4b = (ma1 >= ma2)
    
    ma3 = Average[15](typicalPrice)
    ma4 = Average[55](typicalPrice)
    c4s = (ma3 <= ma4)
    
    
    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
    
    buyday = (dlow(0) < dlow(1) or dhigh(0) < dhigh(1)) and (dhigh(0) < dhigh(1)) and (dlow(0) < dlow(1)) and (dlow(0) > dlow(1) xor dhigh(0) < dhigh(1)) and c4b
    
    shortday = (dlow(0) < dlow(1)) and (dlow(0) < dlow(1) or dhigh(0) < dhigh(1)) and c4s
    
    IF C1 THEN //when a pullback occurs...
    
    IF timeok AND Not OnMarket AND samebarsignal = 0 and buyday 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 and shortday 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 =====
    
Viewing 5 posts - 31 through 35 (of 35 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Strategy XXDJI-M5-EngulfingGap


ProOrder: Automated Strategies & Backtesting

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

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

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 05/12/2020
Status: Active
Attachments: 14 files
ProRealCode ProRealCode
Loading...