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 avatarbobt.
Viewing 8 posts - 1 through 8 (of 8 total)
  • #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

     

    However 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 …

     

    This 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

     

    #160119

    Add this as the first line of your original code:

     

    #160123

    Hi 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

     

    #160125

    Then 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.

    #160126

    You could also store location and values for historical signals in an array and redraw them repeatedly on the last bar only.

    #160130

    Hi 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..

    #160132

    Values can only be returned if a candle is created. If a market is closed and so no candles are drawn then no values can be returned.

    #160139

    Hi Vonasi,

    Thanks for the info, that helps.

    Many thanks for your time answering my questions.

     

    Regards,

    Bob

Viewing 8 posts - 1 through 8 (of 8 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login