Central Bank Dealers Range – Reversal strategy Help please!

Viewing 15 posts - 1 through 15 (of 31 total)
  • Author
    Posts
  • #232841 quote
    crolakstrading
    Participant
    Senior

    Hi

    I have tried to make an indicator for a range breakout reversal strategy – It’s called the central bank dealers range. The original strategy works as below,

    On the 15 min Chart – If the time 7pm to 1am take the open or the close price of the highest candle and the lowest candle of the range 7am-1am. then if the market stretches and goes up to 1.5 or 2 standard deviations before 10am of that range enter short, the Stop loss is at 3 of that range. The target will be at 50% inside the range. the whole thing should not trigger if the time passes at 10am next day after london session.

    The indicator works and shows what I need but the problem is I can not change the time 7 pm to 1am. it can make any range after 1 am though? any reason for that? Please can anyone help to build this? Massive help?

     

    I have attached pics to see if it make any sense? of the the strategy. Please kindly if anyone can let me know what I do wrong in here.

    Thank you all in advance

    #232843 quote
    crolakstrading
    Participant
    Senior
    // --- property settings
    //Alpha   = 180 // Transparency text
    //Offset  = 10  // Offset alphanumeric/rectangle OPR
    //Level   = 1   // (0=hidden; 1=observable)
    //Text    = 1   // (0=no text; 1=text)
    // --- end
    
    DefParam DrawOnLastBarOnly = true
    
    starttime = 041500
    endtime   = 071500
    alpha = max(alpha,0)   // Restricted input variable Max-Min
    alpha = min(alpha,255)
    
    dif = hh-ll
    fib38 = hh
    fib0  = ll
    
    if time = starttime then
    startbar = barindex
    endif
    if time = endtime then
    endbar = barindex
    endif
    
    if time >= starttime and time <= endtime then
    if high > hh then
    hh = high
    hh1 = high+10
    endif
    if low < ll or ll = 0 then
    ll = low
    ll2 = low-10
    endif
    endif
    
    if intradaybarindex = 0 then
    hh = 0
    ll = 0
    endif
    
    //hh = round(hh) // Option résultat valeur arrondi
    //ll = round(ll) // Option résultat valeur arrondi
    
    if time > endtime then
    //DrawRectangle(startbar,hh,endbar,ll) coloured(0,255,255,alpha) // Option Rectangle (Alpha = transparence)
    //DrawEllipse(startbar,hh,endbar,ll) coloured(0,255,255,alpha)   // Option ellipse
    DrawSegment(startbar,Hh,endbar,Hh) coloured(123,123,123,alpha)      // Segment Upper
    DrawSegment(startbar,Ll,endbar,Ll) coloured(123,123,123,alpha)      // Segment Lower
    DrawSegment(startbar,hh,endbar-12,ll) coloured(123,123,123,alpha)   // Segment Left
    DrawSegment(startbar+12,Hh,endbar,Ll) coloured(123,123,123,alpha)   // Segment Right
    endif
    
    if Text = 1 then
    DrawText("OPR #dif#pts",startbar+6,hh+(offset*4),SansSerif,Bold,11) coloured(150,150,150,alpha)
    DrawText(" HI  #hh# ",startbar+6,hh+1,SansSerif,Standard,10) coloured(22,111,0,alpha)
    
    //DrawText("Bull Market",startbar+5,hh+(offset),Dialog,Bold,12) coloured(22,111,0,alpha) // Option text only
    //DrawLine(barindex-1,hh,barindex,hh) coloured(111,11,111,alpha) // Option ligne continue
    DrawSegment(endbar,hh,barindex,hh) coloured(0,200,0,alpha)
    DrawText("╔═════► ",startbar+6,hh+(dif),Dialog,Bold,10) coloured(22,111,0,alpha) // Option OPR - 100% (Glyphe alt+201, alt+205)
    DrawText(" LO  #ll# ",startbar+6,ll-1,SansSerif,Standard,10) coloured(200,20,20,alpha)
    
    //DrawText("Bear Market",startbar+5,ll-(offset),Dialog,Bold,12) coloured(200,20,20,alpha) // Option text only
    //DrawLine(barindex-1,ll,barindex,ll) coloured(111,11,111,alpha) // Option ligne continue
    DrawSegment(endbar,ll,barindex,ll) coloured(200,0,0,alpha)
    DrawText("╚═════► ",startbar+6,ll-(dif),Dialog,Bold,10) coloured(200,10,10,alpha) // Option OPR - 100% (Glyphe alt+200, alt+205)
    endif
    
    if Level = 1 then
    fibobull100 = (fib38-fib0)*3.0050+fib38
    DrawSegment(endbar+2,fibobull100,barindex-10,fibobull100) coloured(200,10,10,alpha)
    DrawText("300% SL",barindex-3,fibobull100,SansSerif,Bold,11) coloured(200,10,10,alpha)
    
    fibobull162 = (fib38-fib0)*3+fib0
    DrawSegment(endbar+2,fibobull162,barindex-10,fibobull162) coloured(25,100,0,alpha)
    DrawText("200% E2",barindex-3,fibobull162,SansSerif,Bold,11) coloured(25,100,0,alpha)
    
    fibobull62 = (fib38-fib0)*2.500+fib0
    DrawSegment(endbar+2,fibobull62,barindex-10,fibobull62) coloured(25,100,0,alpha)
    DrawText("150% E1",barindex-3,fibobull62,SansSerif,Bold,11) coloured(25,100,0,alpha)
    fibobull62 = (fib38-fib0)*2+fib0
    
    DrawSegment(endbar+2,fibobull62,barindex-10,fibobull62) coloured(105,105,105,alpha)
    DrawText("100%",barindex-3,fibobull62,SansSerif,Bold,11) coloured(105,105,105,alpha)
    
    
    
    fibobear62 = (fib0-fib38)*3.0050+fib0
    DrawSegment(endbar+2,fibobear62,barindex-10,fibobear62) coloured(200,11,11,alpha)
    DrawText("300% SL",barindex-3,fibobear62,SansSerif,Bold,11) coloured(200,10,10,alpha)
    
    fibobear100 = (fib0-fib38)*2+fib0
    DrawText("200% E2",barindex-3,fibobear100,SansSerif,Bold,11) coloured(25,100,0,alpha)
    DrawSegment(endbar+2,fibobear100,barindex-10,fibobear100) coloured(25,100,0,alpha)
    
    fibobear124 = (fib0-fib38)*1.5+fib0
    DrawSegment(endbar+2,fibobear124,barindex-10,fibobear124) coloured(25,100,0,alpha)
    DrawText("150% E1",barindex-3,fibobear124,SansSerif,Bold,11) coloured(25,100,0,alpha)
    
    fibobear162 = (fib0-fib38)*1+fib0
    DrawSegment(endbar+2,fibobear162,barindex-10,fibobear162) coloured(105,105,105,alpha)
    DrawText("100%",barindex-3,fibobear162,SansSerif,Bold,11) coloured(105,105,105,alpha)
    
    endif
    
    return
    
    #233035 quote
    GraHal
    Participant
    Master

    I can not change the time 7 pm to 1am

    Just an observation … the only times you have in your code are Lines 10 and 11 (4:15am and 7:15am) is this correct?

    starttime = 041500
    endtime   = 071500
    OR
    Do you need …

    starttime = 190000
    endtime   = 010000
    crolakstrading thanked this post
    #233040 quote
    crolakstrading
    Participant
    Senior

    Hi @GraHal

    Thanks very much for your attention.

    yes I need the box to be on the 15min chart

    starttime =  190000
    endtime =  010000

    but when I change it never appears. I don’t know why? it only go back to starttime =  010000 onwards!

    #233041 quote
    GraHal
    Participant
    Master

    I think you need some code in there to define that 070000 is the previous day.

    Just as a trial, see if below works logically?

    starttime = 010000
    endtime   = 040000
    crolakstrading thanked this post
    #233045 quote
    crolakstrading
    Participant
    Senior
    Thanks GraHal
    starttime = 010000
    endtime   = 040000  works perfectly. but cant go beyond that 🙁 I think the initial attached code above is also from 1am to 4am. but trying to find a way that goes to previous day starttime =  190000 and endtime =  010000
    This should be a strategy but you can see I’m not capable of making the indicator properly..  making up a strategy is a but far away for me. I have attached the pic of the strategy should look like! 🙂
    #233047 quote
    JS
    Participant
    Senior

    Hi,

    You use an “IntraDay” time frame (15 min) and “intraday” times run from 00:00:00 (reset IntraDayBarIndex) to 23:59:59… so, all the times you use in your code are related to the current (intra)day …

    crolakstrading thanked this post
    #233048 quote
    GraHal
    Participant
    Master
    This should be a strategy
    Idea … concentrate on making the code into strategy and then optimise those times to see what the best few hours are. If ‘best few hours’ turns out to be 7pm to 11pm or even 11:45pm then your 7pm to 1am may have some basis. But if when optimised 1am to 6am gives most Gain then run with that?
    crolakstrading thanked this post
    #233049 quote
    druby
    Participant
    New
    Hi.. As @GraHal mentions original code ‘s start and end time on same day however you want start and end on different days. Another thing is that the Higher high/low values are reset when intradaybarindex resets which I think is 23:00:00, so range between HH and LL wouldn’t be over the whole time window either. HH and LL now reset at start of time window and flags ensure endtime not valid till start time reached. Try this,  compare it with other, on a time setting that work in both and see if levels are the same. druby    
    DefParam DrawOnLastBarOnly = true
    
    // --- property settings
    
    //AlphaText = 180 // [integer] Transparency text 0-255
    //Offset    = 10  // [integer] Offset AlphaTextnumeric/rectangle OPR
    //Level     = 1   // [boolean] (0=hidden; 1=observable)
    //Text      = 1   // [boolean  (0=no text; 1=text)
    //AlphaRect = 30  // [integer] Transparency Rectangle 0-255
    // --- end
    
    
    
    starttime = 190000
    endtime   = 010000
     
    AlphaText = abs(max(min(AlphaText,255) ,-255)) // Restricted input variable Max-Min
    AlphaRect = abs(max(min(AlphaRect,255) ,-255))
    //------------------------------------------------------ open data window
    if time = starttime and startFlag = 0   then
    startFlag = 1
    startBar = barindex
    hh = 0
    ll = 0
    endFlag = 0
    endif
    
    //------------------------------------------------------ update hh/ll while in window open
    if startFlag = 1 then
    if high > hh then
    hh = high
    endif
    if low < ll or ll = 0 then
    ll = low
    endif
    endif
    
    //------------------------------------------------------ close data window
    if time = endTime and startFlag = 1 and endFlag = 0 then
    endFlag = 1
    endBar = barindex
    startFlag = 0
    elsif startFlag = 1 then
    endbar = barindex
    endif
    
    //------------------------------------------------------ when window closed
    if endFlag = 1 then
    dif = hh-ll
    fib38 = hh
    fib0  = ll
    endif
    
    
    if islastbarupdate then
    
    DrawRectangle(startbar,hh,endbar,ll) coloured(0,255,255,AlphaRect)bordercolor(0,0,0,0) // Option Rectangle (AlphaText = transparence)
    //DrawEllipse(startbar,hh,endbar,ll) coloured(0,255,255,alpha)   // Option ellipse
    //DrawSegment(startbar,Hh,endbar,Hh) coloured(123,123,123,alpha)      // Segment Upper
    //DrawSegment(startbar,Ll,endbar,Ll) coloured(123,123,123,alpha)      // Segment Lower
    //DrawSegment(startbar,hh,endbar-12,ll) coloured(123,123,123,alpha)   // Segment Left
    //DrawSegment(startbar+12,Hh,endbar,Ll) coloured(123,123,123,alpha)   // Segment Right
    
    if startFlag = 0  and endFlag = 1 then
    if Text = 1 then
    DrawText("OPR #dif#pts",startbar+6,hh+(offset*4),SansSerif,Bold,11) coloured(150,150,150,AlphaText)
    DrawText(" HI  #hh# ",startbar+6,hh+3,SansSerif,Standard,10) coloured(22,111,0,AlphaText)
    
    //DrawText("Bull Market",startbar+5,hh+(offset),Dialog,Bold,12) coloured(22,111,0,AlphaText) // Option text only
    //DrawLine(barindex-1,hh,barindex,hh) coloured(111,11,111,AlphaText) // Option ligne continue
    DrawSegment(endbar,hh,barindex,hh) coloured(0,200,0,AlphaText)
    DrawText("╔═════► ",startbar+6,hh+(dif),Dialog,Bold,10) coloured(22,111,0,AlphaText) // Option OPR - 100% (Glyphe alt+201, alt+205)
    DrawText(" LO  #ll# ",startbar+6,ll-2,SansSerif,Standard,10) coloured(200,20,20,AlphaText)
    
    //DrawText("Bear Market",startbar+5,ll-(offset),Dialog,Bold,12) coloured(200,20,20,AlphaText) // Option text only
    //DrawLine(barindex-1,ll,barindex,ll) coloured(111,11,111,AlphaText) // Option ligne continue
    DrawSegment(endbar,ll,barindex,ll) coloured(200,0,0,AlphaText)
    DrawText("╚═════► ",startbar+6,ll-(dif),Dialog,Bold,10) coloured(200,10,10,AlphaText) // Option OPR - 100% (Glyphe alt+200, alt+205)
    endif // text
    
    if Level = 1 then
    fibobull100 = (fib38-fib0)*3.0050+fib38
    DrawSegment(endbar+2,fibobull100,barindex-10,fibobull100) coloured(200,10,10,AlphaText)
    DrawText("300% SL",barindex-3,fibobull100,SansSerif,Bold,11) coloured(200,10,10,AlphaText)
    
    fibobull162 = (fib38-fib0)*3+fib0
    DrawSegment(endbar+2,fibobull162,barindex-10,fibobull162) coloured(25,100,0,AlphaText)
    DrawText("200% E2",barindex-3,fibobull162,SansSerif,Bold,11) coloured(25,100,0,AlphaText)
    
    fibobull62 = (fib38-fib0)*2.5+fib0
    DrawSegment(endbar+2,fibobull62,barindex-10,fibobull62) coloured(25,100,0,AlphaText)
    DrawText("150% E1",barindex-3,fibobull62,SansSerif,Bold,11) coloured(25,100,0,AlphaText)
    fibobull62 = (fib38-fib0)*2+fib0
    
    DrawSegment(endbar+2,fibobull62,barindex-10,fibobull62) coloured(105,105,105,AlphaText)
    DrawText("100%",barindex-3,fibobull62,SansSerif,Bold,11) coloured(105,105,105,AlphaText)
    
    
    
    fibobear62 = (fib0-fib38)*3.0050+fib0
    DrawSegment(endbar+2,fibobear62,barindex-10,fibobear62) coloured(200,11,11,AlphaText)
    DrawText("300% SL",barindex-3,fibobear62,SansSerif,Bold,11) coloured(200,10,10,AlphaText)
    
    fibobear100 = (fib0-fib38)*2+fib0
    DrawText("200% E2",barindex-3,fibobear100,SansSerif,Bold,11) coloured(25,100,0,AlphaText)
    DrawSegment(endbar+2,fibobear100,barindex-10,fibobear100) coloured(25,100,0,AlphaText)
    
    fibobear124 = (fib0-fib38)*1.5+fib0
    DrawSegment(endbar+2,fibobear124,barindex-10,fibobear124) coloured(25,100,0,AlphaText)
    DrawText("150% E1",barindex-3,fibobear124,SansSerif,Bold,11) coloured(25,100,0,AlphaText)
    
    fibobear162 = (fib0-fib38)*1+fib0
    DrawSegment(endbar+2,fibobear162,barindex-10,fibobear162) coloured(105,105,105,AlphaText)
    DrawText("100%",barindex-3,fibobear162,SansSerif,Bold,11) coloured(105,105,105,AlphaText)
    
    endif // level 1
    endif // startFlag ...
    endif // islastbarupdate
    return
    crolakstrading thanked this post
    #233175 quote
    crolakstrading
    Participant
    Senior
    Hi @druby, It works very well and now I can change it to any time. Thank you all for your kind attention on this. Even though the Original strategy’s time scale is at 19.00 to 01.00 as central banks dealers range, as @GraHal mentioned, it should be tested at different times as well. I have tried to use your cording and tried to create a strategy but failed miserably. Please will you be kind enough to check what I have done wrong? Take profit both should be at the 50% of the middle range of the box – I have no idea how to get that Also is there a way to add if the whole thing did not get trigger at 10am that everything will cancel? Thank you once again GraHal,druby and @JS    
    DEFPARAM CumulateOrders = False
    starttime = 191500
    endtime   = 011500
     
    //------------------------------------------------------ open data window
    if time = starttime and startFlag = 0   then
    startFlag = 1
    startBar = barindex
    hh = 0
    ll = 0
    endFlag = 0
    endif
    
    //------------------------------------------------------ update hh/ll while in window open
    if startFlag = 1 then
    if high > hh then
    hh = high
    endif
    if low < ll or ll = 0 then
    ll = low
    endif
    endif
    
    //------------------------------------------------------ close data window
    if time = endTime and startFlag = 1 and endFlag = 0 then
    endFlag = 1
    endBar = barindex
    startFlag = 0
    elsif startFlag = 1 then
    endbar = barindex
    endif
    
    //------------------------------------------------------ when window closed
    if endFlag = 1 then
    dif = hh-ll
    fib38 = hh
    fib0  = ll
    endif 
      
    EntryPrice = (fib38-fib0)*2.5+fib0
    EntryPrice1 = (fib0-fib38)*1.5+fib0
    StopLoss = (fib38-fib0)*3.0050+fib38  
    StopLoss1 = (fib0-fib38)*3.0050+fib0   
    takeprofit = (fib38-fib0)*2+fib0 
    takeprofit1 = (fib0-fib38)*1+fib0
    
    
    if startFlag = 0  and endFlag = 1 then
    if Text = 1 then
    
    endif // text
    
    if Level = 1 then
    
    // Conditions to enter Short positions
    IF NOT ShortOnMarket AND startFlag = 0  and endFlag = 1 then
    SEllSHORT 1 CONTRACTS AT EntryPrice LIMIT
    ENDIF
    IF OnMarket THEN
    SET STOP LOSS StopLoss 
    Endif
    Set Target pProfit takeprofit
    
    // Conditions to enter long positions
    IF NOT LongOnMarket AND tradingtime and value2 THEN
    BUY 1 CONTRACTS AT EntryPrice1 LIMIT
    ENDIF
    IF OnMarket THEN
    SET STOP LOSS StopLoss1
    ENDIF
    Set Target pProfit takeprofit1
    
    /*
    reference
    #233233 quote
    druby
    Participant
    New
    Try this, I did a back test run it on DAX 15min seems to do something  
    DEFPARAM CumulateOrders = False
    starttime = 191500
    endtime   = 011500
    trigTime  = 100000 // added!
     
    //------------------------------------------------------ open data window
    if time = starttime and startFlag = 0   then
    startFlag = 1
    startBar = barindex
    hh = 0
    ll = 0
    endFlag = 0
    trigFlag = 0
    endif
    
    //------------------------------------------------------ update hh/ll while in window open
    if startFlag = 1 then
    if high > hh then
    hh = high
    endif
    if low < ll or ll = 0 then
    ll = low
    endif
    endif
    
    //------------------------------------------------------ close data window
    if time = endTime and startFlag = 1 and endFlag = 0 then
    endFlag = 1
    endBar = barindex
    startFlag = 0
    elsif startFlag = 1 then
    endbar = barindex
    endif
    
    //------------------------------------------------------ when window closed
    if endFlag = 1 then
    dif = hh-ll
    fib38 = hh
    fib0  = ll
    endif
    //------------------------------------------------------ when trigger time reached
    if time >= trigTime and startFlag = 0 and endFlag = 1 then     // added! +2 lines
    trigFlag = 1
    endif
      
    EntryPrice = (fib38-fib0)*2.5+fib0
    EntryPrice1 = (fib0-fib38)*1.5+fib0
    StopLoss = (fib38-fib0)*3.0050+fib38
    StopLoss1 = (fib0-fib38)*3.0050+fib0
    takeprofit = (fib38-fib0)/2+fib0     //changed
    takeprofit1 = (fib0-fib38)/2+fib0    //changed!
    
    
    // Conditions to enter Short positions
    IF NOT ShortOnMarket AND startFlag = 0  and endFlag = 1 and trigFlag = 0 then  // changed!
    SEllSHORT 1 CONTRACTS AT EntryPrice LIMIT
    ENDIF
    IF OnMarket THEN
    SET STOP LOSS StopLoss
    Endif
    Set Target pProfit takeprofit
    
    // Conditions to enter long positions
    //IF NOT LongOnMarket AND >tradingtime< and >value2< THEN                        //????? was this line in error  --- 
    
    If NOT LongOnMarket AND startFlag = 0 and endFlag = 1 and trigFlag = 0 then  // changed and added!
    BUY 1 CONTRACTS AT EntryPrice1 LIMIT
    ENDIF
    IF OnMarket THEN
    SET STOP LOSS StopLoss1
    ENDIF
    Set Target pProfit takeprofit1
    #233316 quote
    crolakstrading
    Participant
    Senior
    Hi druby, Thank you very mcuh for this.. for some reason probacktest or detailed report won’t show in my chat ;( I saved it but it doesn’t load up. can’t see anything? Is it because I’m using PRT with IG? 🙁 🙁  it has never happened before!! Please can you advise Please.. 🙁
    #233320 quote
    druby
    Participant
    New
    On win11, IG, I used  snipping tool to crop an image of desktop area. Alternate, you can use the share feature from the top right hand side of Detailed report, ‘Save’ saves an image. Below, in the reply section, Attachments [Select File] click!, then navigate to the location of the required image file, select  file and then click ‘open’. Image should be previewed in attachment section.. One other thing, Attachment only show up when viewing  AND your logged in . At times you get automatically logged out. IF use several devices maybe that one has logged out.
    crolakstrading thanked this post
    #233357 quote
    crolakstrading
    Participant
    Senior
    Hi druby Thanks, it worked. I tried your coding it takes the entry perfectly I think but somehow trade trigger and exit at the same time. please can you have a look at the pics below on EURUSD on the 14 MAy. The trade trigger but instead of going into TP, it straight exits simultaneously with a loss! tried to change things but did not work!  also is the trigTime 100000 means if the price goes to the entry-level anytime before 10am will trigger the trade I guess? Sorry, I know I’m asking you loads of questions.. I like to see what happens I have been trying this manually for a long time but its tough! Thank you in advance
    #233368 quote
    druby
    Participant
    New
    I’m not 100% on this but, on lines 58 and 69 we have ‘IF ON MARKET THEN’ where, line 58 set the short stoploss and line 69 the long stoploss. So when long limit order triggered, line 66, and order executed, (on market) the stoploss and target are set. Now since on the market, the next run through of the code sees the line 58 ‘IF ON MARKET THEN ‘ again and reset the stoploss to the short stoploss. Since both targets are the same level the change doesn’t affect those. However, in a long trade the stop level is set below the price, and if price goes below it, the stop is triggered, but when it’s now changed to above the price, effectively the price is below the short stoploss level and triggers, out of market. So if this is what’s happening then the lines need to be changed to: 58    IF SHORT ON MARKET THEN 69    IF LONG ON MARKET THEN This would remove this conflict.   On another point,  if a position only exits if the stop or target met, and every day a new stop and target are calculated, then depending on price movement the new stop and targets would be the active ones. So if in a position, it appears possible for these moving stops and targets and price movements, to make a target bigger than was originally set, and opposite for the stoploss, making it worse than originally set. This all if trade triggered before the 10am cut off point, but trade could last, lets say days, and who knows were stop and target will be on that day. If that’s not your intension then the logic around the stop and target need some thought. This is if, i’m seeing this all right! Regards
    crolakstrading thanked this post
Viewing 15 posts - 1 through 15 (of 31 total)
  • You must be logged in to reply to this topic.

Central Bank Dealers Range – Reversal strategy Help please!


ProBuilder: Indicators & Custom Tools

New Reply
Author
Summary

This topic contains 30 replies,
has 5 voices, and was last updated by crolakstrading
1 year, 7 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 05/21/2024
Status: Active
Attachments: 15 files
Logo Logo
Loading...