Draw Object for every new bar

 
Hello all, I want to draw trendline as forecast line so I want the line start from price Close[0]. The problem is, I want to draw the object automatically everytime new bar appear, any idea so I can update my object everytime new bar appear?
 
  1. Don't double post! You already had this thread open.
              General rules and best pratices of the Forum. - General - MQL5 programming forum #6 (2017)

  2. A A Adhioermawan: any idea so I can update my object everytime new bar appear?

    Detect a new bar, update your object.

    You can't know when a candle closes. Only when a new tick arrives that starts a new bar is the old bar closed, and that tick could arrive almost at the end of a bar's duration.

    For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart), volume is unreliable (miss ticks), Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
              MT4: New candle - MQL4 programming forum #3 (2014)
              MT5: Accessing variables - MQL4 programming forum #3 (2022)

    I disagree with making a new bar function, because it can only be called once per tick (second call returns false). A variable can be tested multiple times.
              Running EA once at the start of each bar - MQL4 programming forum (2011)


how to draw object when every new bar appear
how to draw object when every new bar appear
  • 2024.03.05
  • A A Adhioermawan
  • www.mql5.com
Hello all, I want to draw trendline as forecast line so I want the line start from price Close[0]...
 

Forum on trading, automated trading systems and testing trading strategies

...

Fabio Cavalloni, 2024.03.05 06:20

Close[0] changes until the bar is not finished. You should use Close[1] or Open[0]

The simpler way to detect a new bar into indicators is with condition

prev_calculated>0 && rates_total!=prev_calculated

 
William Roeder #:
Don't double post! You already had this thread open.
I deleted that thread (thanks for informing).