Skip to content

CustomTimeFrameBarsNeededArgs

class cAlgo.API Since 5.3

DesktopCLICloud

Provides data for custom time frame BarsNeeded handler.

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

public class CustomTimeFrameBarsNeededArgs

Namespace: cAlgo.API · Group: Custom

Examples

protected override void OnStart()
{
    var customTimeFrame = TimeFrameManager.Custom.Add("My Custom TF");
    customTimeFrame.BarsNeeded = OnBarsNeeded;
}

private void OnBarsNeeded(CustomTimeFrameBarsNeededArgs args)
{
    var bars = MarketData.GetBars(TimeFrame.Daily, args.CustomBars.Symbol.Name);
    args.CustomBars.AppendBars(bars.Select(bar => new CustomBar(bar.OpenTime, bar.Open, bar.High, bar.Low, bar.Close, (long)bar.TickVolume)));
    Print("Provided {0} bars for {1}", bars.Count, args.CustomTimeFrame.Name);
}
from System import Action

def on_start(self):
    customTimeFrame = api.TimeFrameManager.Custom.Add("My Custom TF")
    customTimeFrame.BarsNeeded = Action[CustomTimeFrameBarsNeededArgs](self.on_bars_needed)

def on_bars_needed(self, args):
    bars = api.MarketData.GetBars(TimeFrame.Daily, args.CustomBars.Symbol.Name)
    for bar in bars:
        args.CustomBars.AppendBar(CustomBar(bar.OpenTime, bar.Open, bar.High, bar.Low, bar.Close, int(bar.TickVolume)))
    api.Print(f"Provided {bars.Count} bars for {args.CustomTimeFrame.Name}")

Properties

Name Description
CustomBarsDesktopCLICloudCustomBars Gets custom bars.
CustomTimeFrameDesktopCLICloudCustomTimeFrame Gets custom time frame.

See also