Bars since open

Created at 24 May 2015, 10:30
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
Baiazid's avatar

Baiazid

Joined 27.11.2014

Bars since open
24 May 2015, 10:30


Hi guys,

I am working on a strategy where close position happens after X bars.

in my OnBar() i obtain the current bar index: int index = MarketSeries.Close.Count - 1;

My question is: how I can obtain the bar index of a currently open position (I am using positions.find function) ?

 


@Baiazid
Replies

mindbreaker
24 May 2015, 13:14

RE:

3052551 said:

Hi guys,

I am working on a strategy where close position happens after X bars.

in my OnBar() i obtain the current bar index: int index = MarketSeries.Close.Count - 1;

My question is: how I can obtain the bar index of a currently open position (I am using positions.find function) ?

 

int CountBars = 0;

// close after

int CloseAfter = 10;

OnBar(){

CountBars++;

if(CountBars > CloseAfter)
 {

 CountBars = 0;

 // close here

 Close(position);

 }

}

This simple example.

 


@mindbreaker