---
id: "T:cAlgo.API.BarOpenedEventArgs"
kind: "class"
namespace: "cAlgo.API"
url: "https://help.ctrader.com/ctrader-algo/references/EventArgs/BarOpenedEventArgs/"
---

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

# BarOpenedEventArgs (class)

Provides data for the event when a new bar opened on the chart.

Environments: Desktop supported · CLI supported · Cloud supported.

## Definition

```csharp
public class BarOpenedEventArgs
```

## Examples

C#:

```csharp
using cAlgo.API;

namespace cAlgo
{
    // This example shows how to use the Bars object BarOpened event BarOpenedEventArgs
    public partial class BarOpenedEventArgsSample : Indicator
    {
        protected override void Initialize()
        {
            Bars.BarOpened += Bars_BarOpened;
        }

        // This method will be called if a new bar opens
        // BarOpenedEventArgs has a Bars property the you can use to get Bars object
        private void Bars_BarOpened(BarOpenedEventArgs obj)
        {
            var newOpenedBar = obj.Bars.LastBar; // Or you can use obj.Bars[Bars.Count - 1] or obj.Bars.Last(0)
            var closedBar = obj.Bars.Last(1); // Or you can use obj.Bars[Bars.Count - 2]
        }

        public override void Calculate(int index)
        {
        }
    }
}
```

Python:

```python
import clr
clr.AddReference("cAlgo.API")

from cAlgo.API import *

class Test():
    def initialize(self):
        api.Bars.BarOpened += self.on_bar_opened

    def on_bar_opened(self, args):
        # Or you can use args.Bars[Bars.Count - 1] or args.Bars.Last(0)
        newOpenedBar = args.Bars.LastBar
         # Or you can use args.Bars[Bars.Count - 2]
        closedBar = args.Bars.Last(1)
```

config.json:

```json
{
  "AccessRights": "None",
  "TimeZone": "UTC",
  "IsOverlay": false
}
```

## Properties

- `public Bars Bars {get;}` — Gets the bar data. [details](https://help.ctrader.com/ctrader-algo/references/EventArgs/BarOpenedEventArgs/Bars/index.md)

