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

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

# CustomSymbol.BarsNeeded

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

## BarsNeeded

Gets / sets BarsNeeded handler, it's triggered when bars are needed for a time frame of current custom symbol.

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<CustomSymbolBarsNeededArgs> BarsNeeded {get; set;}
```

Python:

```python
customSymbol.BarsNeeded: Callable[[CustomSymbolBarsNeededArgs], None]
```

### Returns

`Action<CustomSymbolBarsNeededArgs>` — 

Available since cAlgo.API 5.3.

### Examples

C#:

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

Python:

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

