Central Bank Dealers Range – Reversal strategy Help please!
Forums › ProRealTime English forum › ProBuilder support › Central Bank Dealers Range – Reversal strategy Help please!
- This topic has 30 replies, 5 voices, and was last updated 6 months ago by crolakstrading.
-
-
05/21/2024 at 12:05 AM #232841
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
05/21/2024 at 12:06 AM #232843123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107// --- 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)// --- endDefParam DrawOnLastBarOnly = truestarttime = 041500endtime = 071500alpha = max(alpha,0) // Restricted input variable Max-Minalpha = min(alpha,255)dif = hh-llfib38 = hhfib0 = llif time = starttime thenstartbar = barindexendifif time = endtime thenendbar = barindexendifif time >= starttime and time <= endtime thenif high > hh thenhh = highhh1 = high+10endifif low < ll or ll = 0 thenll = lowll2 = low-10endifendifif intradaybarindex = 0 thenhh = 0ll = 0endif//hh = round(hh) // Option résultat valeur arrondi//ll = round(ll) // Option résultat valeur arrondiif 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 ellipseDrawSegment(startbar,Hh,endbar,Hh) coloured(123,123,123,alpha) // Segment UpperDrawSegment(startbar,Ll,endbar,Ll) coloured(123,123,123,alpha) // Segment LowerDrawSegment(startbar,hh,endbar-12,ll) coloured(123,123,123,alpha) // Segment LeftDrawSegment(startbar+12,Hh,endbar,Ll) coloured(123,123,123,alpha) // Segment Rightendifif Text = 1 thenDrawText("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 continueDrawSegment(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 continueDrawSegment(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)endifif Level = 1 thenfibobull100 = (fib38-fib0)*3.0050+fib38DrawSegment(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+fib0DrawSegment(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+fib0DrawSegment(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+fib0DrawSegment(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+fib0DrawSegment(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+fib0DrawText("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+fib0DrawSegment(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+fib0DrawSegment(endbar+2,fibobear162,barindex-10,fibobear162) coloured(105,105,105,alpha)DrawText("100%",barindex-3,fibobear162,SansSerif,Bold,11) coloured(105,105,105,alpha)endifreturn05/24/2024 at 8:23 PM #233035I 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 = 041500endtime = 071500OR
Do you need …starttime = 190000endtime = 0100001 user thanked author for this post.
05/25/2024 at 1:00 AM #233040Hi @GraHal
Thanks very much for your attention.
yes I need the box to be on the 15min chart
starttime = 190000endtime = 010000but when I change it never appears. I don’t know why? it only go back to starttime = 010000 onwards!
05/25/2024 at 8:07 AM #233041I 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 = 010000endtime = 0400001 user thanked author for this post.
05/25/2024 at 10:56 AM #233045Thanks GraHalstarttime = 010000endtime = 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 = 010000This 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! 🙂05/25/2024 at 11:26 AM #233047Hi,
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 …
1 user thanked author for this post.
05/25/2024 at 11:54 AM #233048This 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?
1 user thanked author for this post.
05/25/2024 at 12:21 PM #233049Hi.. 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
CBDR test(1)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119DefParam 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// --- endstarttime = 190000endtime = 010000AlphaText = abs(max(min(AlphaText,255) ,-255)) // Restricted input variable Max-MinAlphaRect = abs(max(min(AlphaRect,255) ,-255))//------------------------------------------------------ open data windowif time = starttime and startFlag = 0 thenstartFlag = 1startBar = barindexhh = 0ll = 0endFlag = 0endif//------------------------------------------------------ update hh/ll while in window openif startFlag = 1 thenif high > hh thenhh = highendifif low < ll or ll = 0 thenll = lowendifendif//------------------------------------------------------ close data windowif time = endTime and startFlag = 1 and endFlag = 0 thenendFlag = 1endBar = barindexstartFlag = 0elsif startFlag = 1 thenendbar = barindexendif//------------------------------------------------------ when window closedif endFlag = 1 thendif = hh-llfib38 = hhfib0 = llendifif islastbarupdate thenDrawRectangle(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 Rightif startFlag = 0 and endFlag = 1 thenif Text = 1 thenDrawText("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 continueDrawSegment(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 continueDrawSegment(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 // textif Level = 1 thenfibobull100 = (fib38-fib0)*3.0050+fib38DrawSegment(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+fib0DrawSegment(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+fib0DrawSegment(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+fib0DrawSegment(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+fib0DrawSegment(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+fib0DrawText("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+fib0DrawSegment(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+fib0DrawSegment(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 1endif // startFlag ...endif // islastbarupdatereturn1 user thanked author for this post.
05/29/2024 at 12:35 AM #233175Hi @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
CBDR strat1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374DEFPARAM CumulateOrders = Falsestarttime = 191500endtime = 011500//------------------------------------------------------ open data windowif time = starttime and startFlag = 0 thenstartFlag = 1startBar = barindexhh = 0ll = 0endFlag = 0endif//------------------------------------------------------ update hh/ll while in window openif startFlag = 1 thenif high > hh thenhh = highendifif low < ll or ll = 0 thenll = lowendifendif//------------------------------------------------------ close data windowif time = endTime and startFlag = 1 and endFlag = 0 thenendFlag = 1endBar = barindexstartFlag = 0elsif startFlag = 1 thenendbar = barindexendif//------------------------------------------------------ when window closedif endFlag = 1 thendif = hh-llfib38 = hhfib0 = llendifEntryPrice = (fib38-fib0)*2.5+fib0EntryPrice1 = (fib0-fib38)*1.5+fib0StopLoss = (fib38-fib0)*3.0050+fib38StopLoss1 = (fib0-fib38)*3.0050+fib0takeprofit = (fib38-fib0)*2+fib0takeprofit1 = (fib0-fib38)*1+fib0if startFlag = 0 and endFlag = 1 thenif Text = 1 thenendif // textif Level = 1 then// Conditions to enter Short positionsIF NOT ShortOnMarket AND startFlag = 0 and endFlag = 1 thenSEllSHORT 1 CONTRACTS AT EntryPrice LIMITENDIFIF OnMarket THENSET STOP LOSS StopLossEndifSet Target pProfit takeprofit// Conditions to enter long positionsIF NOT LongOnMarket AND tradingtime and value2 THENBUY 1 CONTRACTS AT EntryPrice1 LIMITENDIFIF OnMarket THENSET STOP LOSS StopLoss1ENDIFSet Target pProfit takeprofit1/*reference05/29/2024 at 2:03 PM #233233Try this, I did a back test run it on DAX 15min seems to do something
cbdr V1.00123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172DEFPARAM CumulateOrders = Falsestarttime = 191500endtime = 011500trigTime = 100000 // added!//------------------------------------------------------ open data windowif time = starttime and startFlag = 0 thenstartFlag = 1startBar = barindexhh = 0ll = 0endFlag = 0trigFlag = 0endif//------------------------------------------------------ update hh/ll while in window openif startFlag = 1 thenif high > hh thenhh = highendifif low < ll or ll = 0 thenll = lowendifendif//------------------------------------------------------ close data windowif time = endTime and startFlag = 1 and endFlag = 0 thenendFlag = 1endBar = barindexstartFlag = 0elsif startFlag = 1 thenendbar = barindexendif//------------------------------------------------------ when window closedif endFlag = 1 thendif = hh-llfib38 = hhfib0 = llendif//------------------------------------------------------ when trigger time reachedif time >= trigTime and startFlag = 0 and endFlag = 1 then // added! +2 linestrigFlag = 1endifEntryPrice = (fib38-fib0)*2.5+fib0EntryPrice1 = (fib0-fib38)*1.5+fib0StopLoss = (fib38-fib0)*3.0050+fib38StopLoss1 = (fib0-fib38)*3.0050+fib0takeprofit = (fib38-fib0)/2+fib0 //changedtakeprofit1 = (fib0-fib38)/2+fib0 //changed!// Conditions to enter Short positionsIF NOT ShortOnMarket AND startFlag = 0 and endFlag = 1 and trigFlag = 0 then // changed!SEllSHORT 1 CONTRACTS AT EntryPrice LIMITENDIFIF OnMarket THENSET STOP LOSS StopLossEndifSet 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 LIMITENDIFIF OnMarket THENSET STOP LOSS StopLoss1ENDIFSet Target pProfit takeprofit105/31/2024 at 2:00 AM #233316Hi 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.. 🙁
05/31/2024 at 8:10 AM #233320On 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.
1 user thanked author for this post.
06/01/2024 at 1:05 AM #233357Hi 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
06/01/2024 at 10:46 AM #233368I’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
1 user thanked author for this post.
-
AuthorPosts