CustomSymbol.BarsNeeded
property · CustomSymbol · cAlgo.API Since 5.3
DesktopCLICloud
Gets / sets BarsNeeded handler, it's triggered when bars are needed for a time frame of current custom symbol.
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
Action<CustomSymbolBarsNeededArgs> BarsNeeded {get; set;}
customSymbol.BarsNeeded: Callable[[CustomSymbolBarsNeededArgs], None]
Returns Action<CustomSymbolBarsNeededArgs>
Examples
protected override void OnStart()
{
var customSymbol = CustomSymbols.Add("MYEURUSD", Symbols.GetSymbol("EURUSD"));
customSymbol.BarsNeeded = OnBarsNeeded;
}
private void OnBarsNeeded(CustomSymbolBarsNeededArgs args)
{
var bars = MarketData.GetBars(args.CustomBars.TimeFrame, "EURUSD");
args.CustomBars.AppendBars(bars.Select(bar => new CustomBar(bar.OpenTime, bar.Open, bar.High, bar.Low, bar.Close, (long)bar.TickVolume)));
}
from System import Action
def on_start(self):
customSymbol = api.CustomSymbols.Add("MYEURUSD", api.Symbols.GetSymbol("EURUSD"))
customSymbol.BarsNeeded = Action[CustomSymbolBarsNeededArgs](self.on_bars_needed)
def on_bars_needed(self, args):
bars = api.MarketData.GetBars(args.CustomBars.TimeFrame, "EURUSD")
for bar in bars:
args.CustomBars.AppendBar(CustomBar(bar.OpenTime, bar.Open, bar.High, bar.Low, bar.Close, int(bar.TickVolume)))