# 4.6.6 Calculation per Bar

Historic calculation per bar can be executed in one of the two modes:

1. Calculation upon Close of each bar and filling of the generated orders collection on the next bar. This is the default mode.
2. Calculation upon Open of each bar in the context of the previous bar and filling of the generated orders collection on this bar. This mode is enabled by the signal class attribute [CalcAtOpenNextBarAttribute(true)]:
```namespace PowerLanguage.Strategy {
[CalcAtOpenNextBarAttribute(true)]
public class Test : SignalObject {
public Test(object _ctx):base(_ctx){}
……………….
}
}
```

Open and Time values for the next bar become available through the following functions:

• Bars.OpenNextBar() or Bars.Open[-1],
• Bars.TimeNextBar() or Bars.Time[-1].

But the calculation is still executed in the context of the current bar close (for example, Bars.Close –will still return Close of the current bar, despite the calculation being executed at the Open of the next bar).

Example:
```[CalcAtOpenNextBar(true)]
public class TestSignal : SignalObject {
```

Now, Open of the opened bar is available using the index [-1] or Bars.OpenNextBar():

```double o_next_bar = Bars.Open[-1]; or double o_next_bar = Bars.OpenNextBar();
```

Using index  the information upon the closed bar is still available. Now, the following trading strategy can be implemented: to buy if opened with the gap down and sell if opened with the gap up:

```protected override void CalcBar(){
double o_next_bar = Bars.Open[-1];//Open of the opened bar
double h = Bars.High;//High of the closed calculation bar
double l = Bars.Low; //Low of the closed calculation bar
if (o_next_bar > h) sellshort_order.Send();//Gap up - sell