I want place an order at the beginning of a new candle in Renko chart.

 

I am testing some order code in Renko chart.

What I want is to place an order at the beginning of a new candle.

In normal chart it is OK, but when I use Renko chart. I observed many entry on the same candle.

Do you have any solutions ?


if(lastAlertTime != Time[0]) { 
  OpenOrder here .......
   lastAlertTime = Time[0]; 
}
 
Hong Ling Mu:I am testing some order code in Renko chart. What I want is to place an order at the beginning of a new candle. In normal chart it is OK, but when I use Renko chart. I observed many entry on the same candle.

Do you have any solutions ?

There are no Renko charts in MetaTrader, so on what chart is your EA running?

Usually Renko is either shown as indicator or it is via Offline Charts, but normally an EA cannot run on an Offline Chart unless it receives ticks artificially and is coded specifically to consider the real symbol when trading.

If the EA is running on the normal chart, then it has to reference the Offline Chart for the OHLC Renko data and not the current chart data.

 
Fernando Carreiro #:

There are no Renko charts in MetaTrader, so on what chart is your EA running?

Usually Renko is either shown as indicator or it is via Offline Charts, but normally an EA cannot run on an Offline Chart unless it receives ticks artificially and is coded specifically to consider the real symbol when trading.

If the EA is running on the normal chart, then it has to reference the Offline Chart for the OHLC Renko data and not the current chart data.

Thank you, Fernando.

I use ***********EA to create Renko chart off line.

<Link to ex4 file deleted by moderator>

Fresh Renko chart is always made if new tick data is made but how can I detect a new candle is formed ?

 
Hong Ling Mu #: I use ***********EA to create Renko chart off line. <Link to ex4 file deleted by moderator> Fresh Renko chart is always made if new tick data is made but how can I detect a new candle is formed ?

You did not answer my questions. Is your EA attached to a normal standard chart or is it attached to the Offline Chart?

 
Fernando Carreiro #:

You did not answer my questions. Is your EA attached to a normal standard chart or is it attached to the Offline Chart?

Sorry, I attached on offline chart. chart is redraw always.

 

This is an example for Renko which I attached EA.

 
Fernando Carreiro #:

There are no Renko charts in MetaTrader, so on what chart is your EA running?

Usually Renko is either shown as indicator or it is via Offline Charts, but normally an EA cannot run on an Offline Chart unless it receives ticks artificially and is coded specifically to consider the real symbol when trading.

If the EA is running on the normal chart, then it has to reference the Offline Chart for the OHLC Renko data and not the current chart data.

So, if I code EA specially for Renko chart, how can I detect when a new candlestick is formed ?

 
Hong Ling Mu #: Sorry, I attached on offline chart. chart is redraw always. ... So, if I code EA specially for Renko chart, how can I detect when a new candlestick is formed ?

It the EA is running on the offline chart, then detect a new Renko brick by a change in both the Time and Open price of the latest bar.

This is because sometimes, there can be multiple bricks in the same span of time.

 
Fernando Carreiro #:

It the EA is running on the offline chart, then detect a new Renko brick by a change in both the Time and Open price of the latest bar.

This is because sometimes, there can be multiple bricks in the same span of time.

Thank you, so if I want to detect when the new candle was formed.

can I use Volume[0] = 1 ?

 
Hong Ling Mu #: Thank you, so if I want to detect when the new candle was formed.can I use Volume[0] = 1 ?

No! Never rely on volume. Virtual bricks have no volume (unless you are trying to avoid them), and any delay could cause you to miss when the volume is exactly at 1. So, don't use volume to detect a new brick.

Also, why are you asking this when I have already given you the answer—detect a new brick by a change in both the brick's open price and its time.

 
Hong Ling Mu #: can I use Volume[0] = 1 ?

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)

Reason: