ProRealCode - Trading & Coding with ProRealTime™
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
// --- 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
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?
Hi @GraHal
Thanks very much for your attention.
yes I need the box to be on the 15min chart
but when I change it never appears. I don’t know why? it only go back to starttime = 010000 onwards!
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?
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 …
This should be a strategyIdea … 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?
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
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
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
Central Bank Dealers Range – Reversal strategy Help please!
This topic contains 30 replies,
has 5 voices, and was last updated by crolakstrading
1 year, 7 months ago.
| Forum: | ProBuilder: Indicators & Custom Tools |
| Language: | English |
| Started: | 05/21/2024 |
| Status: | Active |
| Attachments: | 15 files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.