command to refresh the chart

command to refresh the chart
28 Feb 2025, 21:01
Hi everyone,
I’m looking for a way to automatically refresh the chart in cTrader. When the platform is left open for a long time, and price moves significantly up or down, the chart does not update automatically to keep the current price in view. I need a command or method to force the chart to refresh so that the latest price is always visible.
Is there any built-in function or workaround to achieve this?
Thanks in advance!
Replies
Thomas-Sparrow-Vizaint
02 Mar 2025, 15:05
( Updated at: 02 Mar 2025, 15:11 )
Hi Algo
Its strange. Have you tried the option in LMB Refresh?

Another think is center to las bar to time line. But If you move the chart out it does not center automatically.

Personally, in one of my indocadores I use the Chart Zoom function, to have it centered
@Thomas-Sparrow-Vizaint
AlgoCreators
04 Mar 2025, 07:57
( Updated at: 04 Mar 2025, 08:12 )
Solved
Hi everyone,
I found a solution to the issue. Using the SetYRange method to adjust the Y-axis and keep the bid price centered worked perfectly. Thanks to everyone who provided guidance and suggestions!
Best regards.
using cAlgo.API;
namespace cAlgo.Indicators
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC)]
public class CenterBidWithSetYRange : Indicator
{
[Parameter("Update Interval (s)", DefaultValue = 60)]
public int UpdateInterval { get; set; }
// Initial range of the chart's Y-axis.
private double _initialRange;
protected override void Initialize()
{
// Calculate the initial range from the chart settings.
_initialRange = Chart.TopY - Chart.BottomY;
// Start a timer to update the chart at regular intervals.
Timer.Start(UpdateInterval);
}
public override void Calculate(int index)
{
}
protected override void OnTimer()
{
// Calculate half the initial range.
double halfRange = _initialRange / 2.0;
// Use SetYRange to adjust the chart so that the bid price is centered.
Chart.SetYRange(Symbol.Bid - halfRange, Symbol.Bid + halfRange);
}
}
}
@AlgoCreators
firemyst
01 Mar 2025, 05:59 ( Updated at: 02 Mar 2025, 22:25 )
Ctrader tends to keep the chart where you last scrolled to. So don't scroll it. :-)
However in your code, you can try the ScrollToX method:
https:// help . ctrader. com /ctrader-algo/references/Chart/Chart/#scrollxby
@firemyst