OnBar and OnBarClosed issues when using Renko chart

Created at 17 Jun 2024, 05:12
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
yohtza's avatar

yohtza

Joined 20.09.2023

OnBar and OnBarClosed issues when using Renko chart
17 Jun 2024, 05:12


It appears that these methods are not executing consistently. Screenshot and code below.

 

 protected override void OnBar()
 {

     var txt = Chart.DrawText(Bars.Count().ToString(), Bars.Count().ToString(), Bars.Last(1).OpenTime, Bars.Last(1).Low - Symbol.PipValue, Color.Black);
     txt.HorizontalAlignment = HorizontalAlignment.Center;
     txt.VerticalAlignment = VerticalAlignment.Center;
     Print($"{Bars.Last(1).OpenTime} ===== {Bars.Count}");

  
 }

@yohtza
Replies

PanagiotisCharalampous
17 Jun 2024, 05:48

Hi there,

This is by design. If the price jumps more that one bar, then the method is only executed once for the last bar.

Best regards,

Panagiotis


@PanagiotisCharalampous

yohtza
18 Jun 2024, 08:34 ( Updated at: 18 Jun 2024, 09:04 )

RE: OnBar and OnBarClosed issues when using Renko chart

PanagiotisCharalampous said: 

Hi there,

This is by design. If the price jumps more that one bar, then the method is only executed once for the last bar.

Best regards,

Panagiotis

Any suggestions on how to keep the drawing behavior consistent would be greatly appreciated.

Thanks


@yohtza

PanagiotisCharalampous
18 Jun 2024, 09:14

RE: RE: OnBar and OnBarClosed issues when using Renko chart

yohtza said: 

PanagiotisCharalampous said: 

Hi there,

This is by design. If the price jumps more that one bar, then the method is only executed once for the last bar.

Best regards,

Panagiotis

Any suggestions on how to keep the drawing behavior consistent would be greatly appreciated.

Thanks

On each bar you should keep track how many bars have been added using Bars.Count. If more than one bars have been added then you would need to add the numbers using a loop for all the new bars added


@PanagiotisCharalampous