CustomTimeFrame
interface cAlgo.API Since 5.3
DesktopCLICloud
Represents a custom time frame.
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 interface CustomTimeFrame
Namespace: cAlgo.API · Group: Custom
Examples
protected override void OnStart()
{
var customTimeFrame = TimeFrameManager.Custom.Add("Daily Copy");
customTimeFrame.Description = "Daily bars provided by my plugin";
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)));
}
from System import Action
def on_start(self):
customTimeFrame = api.TimeFrameManager.Custom.Add("Daily Copy")
customTimeFrame.Description = "Daily bars provided by my plugin"
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)))
Methods
| Name | Description |
|---|---|
AddBarsDesktopCLICloudCustomBars | Adds bars for a symbol that will be used for this custom time frame when needed. |
GetBarsDesktopCLICloudCustomBars | Returns bars of a symbol if exists otherwise null. |
RemoveAllUnloadedBarsDesktopCLICloudvoid | Removes all existing unloaded custom bars that aren't being used. |
RemoveBarsDesktopCLICloudbool | Removes bars of a symbol which is not being used. |
Properties
| Name | Description |
|---|---|
BarsNeededDesktopCLICloudAction<CustomTimeFrameBarsNeededArgs> | Gets / sets BarsNeeded handler, it's triggered when bars are needed for a symbol of current time frame. |
DescriptionDesktopCLICloudstring | Gets / sets custom time frame description. |
NameDesktopCLICloudstring | Gets Custom time frame unique name. |
TimeFrameDesktopCLICloudTimeFrame | Gets regular time frame. |
Events
| Name | Description |
|---|---|
BarsUnloadedDesktopCLICloudAction<CustomTimeFrameBarsUnloadedEventArgs> | Occurs when a custom bars is unloaded and not being used anymore. |
NewChartDesktopCLICloudAction<CustomTimeFrameNewChartEventArgs> | Occurs when user opens a new chart of current custom time frame. |