---
id: "P:cAlgo.API.CustomTimeFrame.BarsNeeded"
kind: "property"
type: "T:cAlgo.API.CustomTimeFrame"
url: "https://help.ctrader.com/ctrader-algo/references/Plugin/TimeFrame/Custom/CustomTimeFrame/BarsNeeded/"
---

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

# CustomTimeFrame.BarsNeeded

Member of [CustomTimeFrame](https://help.ctrader.com/ctrader-algo/references/Plugin/TimeFrame/Custom/CustomTimeFrame/index.md).

## BarsNeeded

Gets / sets BarsNeeded handler, it's triggered when bars are needed for a symbol of current 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.

C#:

```csharp
Action<CustomTimeFrameBarsNeededArgs> BarsNeeded {get; set;}
```

Python:

```python
customTimeFrame.BarsNeeded: Callable[[CustomTimeFrameBarsNeededArgs], None]
```

### Returns

`Action<CustomTimeFrameBarsNeededArgs>` — 

Available since cAlgo.API 5.3.

### Examples

C#:

```csharp
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.Hour4, 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("My Custom TF")
    customTimeFrame.BarsNeeded = Action[CustomTimeFrameBarsNeededArgs](self.on_bars_needed)

def on_bars_needed(self, args):
    bars = api.MarketData.GetBars(TimeFrame.Hour4, 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)))
```

