How to draw x bars back from latest candle without a history when market closed
Forums › ProRealTime English forum › ProBuilder support › How to draw x bars back from latest candle without a history when market closed
- This topic has 7 replies, 2 voices, and was last updated 3 years ago by bobt.
-
-
02/02/2021 at 11:01 AM #160116
Hello all, I hope you can assist.
I have a need to draw a signal on the chart, based on the latest candle. I only want to show one signal on the chart.
I’m using V11 and so can use IsLastBarUpdate to check I’m on the most recent bar.
e.g
123IF IsLastBarUpdate > 1 THENDrawArrowDown(Barindex - 3, 20)ENDIFHowever as new bars are added to the chart, this leaves a trail of previous arrows on the chart, therefore I now test to check it’s not the opening second of the new bar in order to avoid drawing a history …
Draw 3 bars back - with no123IF IsLastBarUpdate and CurrentSecond > 1 THENDrawArrowDown(Barindex - 3, 40)ENDIFThis works fine ( I’ve attached code to demo this,and a screenshot, just set to 1 minute refresh and leave running for 2-3 minutes )
So far, so good BUT on a Monday morning in Europe when US stock market is closed ( e.g GME yesterday morning ! ), the CurrentSecond only returns 0, and therefore no arrow is drawn, until the market closes.
So, what;s my question ?
I’m using a workaround of testing the CurrentSecond in order to make my arrow only appear once. Should I expect CurrentSecond to return the current second time from my PC no matter the state of the market ? ( I think it should ). If not, how can I draw a single instance of a signal, on the chart, without a history appearing – even if the market is closed ?
I’ve attached a bit of sample code which shows both drawing methods and demonstrates the problem occurring, also a screenshot of the problem to save people having to load the code !!
Any help much appreciated, regards,
Bob
02/02/2021 at 11:05 AM #16011902/02/2021 at 11:26 AM #160123Hi Vonas,
Many thanks for the quick reply.Unfortunately DrawOnLastBarOnly isn’t an option for me, as the signal I need to draw is one among many – most of which are drawn throughout the chart timeline as the chart is loaded.
In essence I’ve had to simplify my code, in order to post it on a public forum.
DrawOnLastBarOnly is a global type parameter rather than something which can be turned on and off throughout the code as I understand it, therefore using it would break other things within my indicator.Regards,
Bob
02/02/2021 at 11:44 AM #160125Then the simple solution is possibly to apply the indicator as two indicators. One that draws on the last bar only and one that draws on every bar. I often do this if for example I have a set of bands drawn on the chart but want also display the latest value of the bands.
02/02/2021 at 11:46 AM #16012602/02/2021 at 11:58 AM #160130Hi Vonasi,
Yes, both those approaches make sense, either split the code into two, or rewrite it using arrays.
Both of those options result from the fact that CurrentSecond doesn’t return the current second ( unless the market is open), is that the expected behaviour ?
Regards..
02/02/2021 at 12:12 PM #16013202/02/2021 at 12:52 PM #160139 -
AuthorPosts
Find exclusive trading pro-tools on