Draw a rectangle each day between 00:00 and 07:00
Forums › ProRealTime English forum › ProBuilder support › Draw a rectangle each day between 00:00 and 07:00
- This topic has 8 replies, 4 voices, and was last updated 6 years ago by crolakstrading.
-
-
01/23/2017 at 9:32 PM #22207
Good evening,
I am new to ProRealCode and would like to understand where I am wrong.
I need to draw a rectangle each day from 00:00 to 07:00 where Y1/Y2 are low/high for the same time frame.
If I uncomment line 1 (defparam drawonlastbaronly=true) it works fine on last day.
Uncommenting this line causes the rectangle to be drawn for all periods and I don’t realise why.
Any help is really appreciated.
Thanks
Giovanni
PS I attach screenshot of the actual wrong visualisation.
1234567891011121314151617181920//defparam drawonlastbaronly = trueif intradaybarindex=0 thenmaxvalue=0minvalue=close*5x1=0x2=0endiftimerange = time>=000000 and time<=070000if timerange thenmaxvalue = max(maxvalue , high)minvalue = min(minvalue , low)if time=010000 thenx1=barindexendifif time=070000 thenx2=barindexendifendifDRAWRECTANGLE(x1,maxvalue,x2,minvalue)RETURN01/24/2017 at 11:11 AM #22234In fact this is not a problem, because your result give you exactly what you have coded.
If you don’t use the ‘drawonlastbaronly’ function, the code is read and executed while the history is read at the first time. As you may already know, prorealtime only read once the history and drawn things on chart can’t be erased.
So, in order to draw correctly the rectangles in your chart history, you’ll need to begin and end drawing them, once the last schedule (X coordinates = barindex) has already passed.
Another possibility could be to use the ‘drawonlastbaronly’ and make loop through the past data, but it would be memory consuming for the platform.
But if I understand correctly what you want to achieve here, is to draw the current rectangle (the one for the current day) and the ones from previous day also?
01/25/2017 at 1:39 PM #22423Thank you Nicolas,
I amended the code as you explained and now it’s working fine .
The only issue is that it worked after restarting my PC, without changing any line of code at all.
I then tried to add a background to the rectangle but there is no way to do it, as far as I know.
Thank you Nicolas!
12345678910111213141516171819//defparam drawonlastbaronly = trueif intradaybarindex=0 thenmaxvalue=0minvalue=Dclose(0)*5endiftimerange = time>000000 and time<=070000if timerange thenmaxvalue = max(maxvalue , high)minvalue = min(minvalue , low)if intradaybarindex=0 thenx1=barindexendifif time=070000 thenx2=barindexDRAWRECTANGLE(x1,maxvalue,x2,minvalue) coloured(10,255,10,255)endifendifRETURN03/30/2018 at 12:11 AM #66741i wanted to change this box to 4am to 7am i tried below,
123456789101112131415161718if intradaybarindex=0 thenmaxvalue=0minvalue=Dclose(0)*5endiftimerange = time>=040000 and time<=080000if timerange thenmaxvalue = max(maxvalue , high)minvalue = min(minvalue , low)if intradaybarindex=0 thenx1=barindexendifif time=080000 thenx2=barindexDRAWRECTANGLE(x1,maxvalue,x2,minvalue) coloured(70,130,190)endifendifRETURNbut it didnt do anything any reason why???
03/30/2018 at 8:00 AM #66753It’s because line 9 will never be true after 000000.
Insert a new line between 3 and 4 which reads
1MyBar=0then at line 9 (now line 10) replace intradaybarindex with MyBar
1if MyBar=0 thenand, finally, insert a line before or after line 10 (now line 11)
1MyBar=103/30/2018 at 8:03 AM #66754There was an ENDIF wrongly placed in the code. The X1 coordinate was not correctly found, here is the code fixed:
12345678910111213141516171819if intradaybarindex=0 thenmaxvalue=0minvalue=Dclose(0)*5endiftimerange = time>=040000 and time<=080000if timerange thenmaxvalue = max(maxvalue , high)minvalue = min(minvalue , low)endifif intradaybarindex=0 thenx1=barindexendifif time=080000 thenx2=barindexDRAWRECTANGLE(x1,maxvalue,x2,minvalue) coloured(70,130,190)endifRETURN03/30/2018 at 8:07 AM #66756Well Nicolas, that would partially do, you’ll have a rectangle displayed also for hours BEFORE 040000.
I think the problem was the one I posted about.
03/30/2018 at 8:10 AM #66757To recap :
12345678910111213141516171819if intradaybarindex=0 thenmaxvalue=0minvalue=Dclose(0)*5MyBar=0endiftimerange = time>=040000 and time<=080000if timerange thenmaxvalue = max(maxvalue , high)minvalue = min(minvalue , low)if MyBar=0 thenx1=barindexMyBar=1endifif time=080000 thenx2=barindexDRAWRECTANGLE(x1,maxvalue,x2,minvalue) coloured(70,130,190)endifendifRETURN04/03/2018 at 3:15 PM #67036Thank you both! @robertogozzi & @Nicolas
-
AuthorPosts