CustomBars.NeedsMore
event · CustomBars · cAlgo.API Since 5.3
DesktopCLICloud
Occurs when user scrolls back on a custom bars chart.
Environment behaviour
CLI — not supported. Available to plugins only, and plugins cannot run in the CLI.
Cloud — not supported. Available to plugins only, and plugins cannot run in the cloud.
Definition
event Action<CustomBarsNeedsMoreEventArgs> NeedsMore;
customBars.NeedsMore += handler # handler(obj: CustomBarsNeedsMoreEventArgs)
Examples
private Bars _sourceBars;
protected override void OnStart()
{
_sourceBars = MarketData.GetBars(TimeFrame.Hour, "EURUSD");
var customBars = TimeFrameManager.Custom.Add("My Custom TF").AddBars(Symbols.GetSymbol("EURUSD"));
customBars.NeedsMore += OnNeedsMore;
}
private void OnNeedsMore(CustomBarsNeedsMoreEventArgs args)
{
var loadedCount = _sourceBars.LoadMoreHistory();
args.CustomBars.PrependBars(_sourceBars.Take(loadedCount).Select(bar => new CustomBar(bar.OpenTime, bar.Open, bar.High, bar.Low, bar.Close, (long)bar.TickVolume)));
}
from System import Array
def on_start(self):
self.sourceBars = api.MarketData.GetBars(TimeFrame.Hour, "EURUSD")
customBars = api.TimeFrameManager.Custom.Add("My Custom TF").AddBars(api.Symbols.GetSymbol("EURUSD"))
customBars.NeedsMore += self.on_needs_more
def on_needs_more(self, args):
loadedCount = self.sourceBars.LoadMoreHistory()
olderBars = [CustomBar(self.sourceBars[i].OpenTime, self.sourceBars[i].Open, self.sourceBars[i].High, self.sourceBars[i].Low, self.sourceBars[i].Close, int(self.sourceBars[i].TickVolume)) for i in range(loadedCount)]
args.CustomBars.PrependBars(Array[CustomBar](olderBars))