---
id: "T:cAlgo.API.CustomTimeFrame"
kind: "interface"
namespace: "cAlgo.API"
url: "https://help.ctrader.com/ctrader-algo/references/Plugin/TimeFrame/Custom/CustomTimeFrame/"
---

> Documentation index for agents: https://help.ctrader.com/ctrader-algo/llms.txt · machine index: https://help.ctrader.com/ctrader-algo/api.json

# CustomTimeFrame (interface)

Represents a custom time frame.

Environments: Desktop supported · CLI not supported · Cloud not supported.

- CLI: Available to plugins only, and plugins cannot run in the CLI.
- Cloud: Available to plugins only, and plugins cannot run in the cloud.

## Definition

```csharp
public interface CustomTimeFrame
```

Available since cAlgo.API 5.3.

## Examples

C#:

```csharp
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)));
}
```

Python:

```python
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

- `CustomBars AddBars(Symbol symbol)` — Adds bars for a symbol that will be used for this custom time frame when needed. [details](https://help.ctrader.com/ctrader-algo/references/Plugin/TimeFrame/Custom/CustomTimeFrame/AddBars/index.md)
- `CustomBars GetBars(Symbol symbol)` — Returns bars of a symbol if exists otherwise null. [details](https://help.ctrader.com/ctrader-algo/references/Plugin/TimeFrame/Custom/CustomTimeFrame/GetBars/index.md)
- `void RemoveAllUnloadedBars()` — Removes all existing unloaded custom bars that aren't being used. [details](https://help.ctrader.com/ctrader-algo/references/Plugin/TimeFrame/Custom/CustomTimeFrame/RemoveAllUnloadedBars/index.md)
- `bool RemoveBars(Symbol symbol)` — Removes bars of a symbol which is not being used. [details](https://help.ctrader.com/ctrader-algo/references/Plugin/TimeFrame/Custom/CustomTimeFrame/RemoveBars/index.md)

## Properties

- `Action<CustomTimeFrameBarsNeededArgs> BarsNeeded {get; set;}` — Gets / sets BarsNeeded handler, it's triggered when bars are needed for a symbol of current time frame. [details](https://help.ctrader.com/ctrader-algo/references/Plugin/TimeFrame/Custom/CustomTimeFrame/BarsNeeded/index.md)
- `string Description {get; set;}` — Gets / sets custom time frame description. [details](https://help.ctrader.com/ctrader-algo/references/Plugin/TimeFrame/Custom/CustomTimeFrame/Description/index.md)
- `string Name {get;}` — Gets Custom time frame unique name. [details](https://help.ctrader.com/ctrader-algo/references/Plugin/TimeFrame/Custom/CustomTimeFrame/Name/index.md)
- `TimeFrame TimeFrame {get;}` — Gets regular time frame. [details](https://help.ctrader.com/ctrader-algo/references/Plugin/TimeFrame/Custom/CustomTimeFrame/TimeFrame/index.md)

## Events

- `event Action<CustomTimeFrameBarsUnloadedEventArgs> BarsUnloaded;` — Occurs when a custom bars is unloaded and not being used anymore. [details](https://help.ctrader.com/ctrader-algo/references/Plugin/TimeFrame/Custom/CustomTimeFrame/BarsUnloaded/index.md)
- `event Action<CustomTimeFrameNewChartEventArgs> NewChart;` — Occurs when user opens a new chart of current custom time frame. [details](https://help.ctrader.com/ctrader-algo/references/Plugin/TimeFrame/Custom/CustomTimeFrame/NewChart/index.md)

