Close position on bar close

Created at 26 Mar 2023, 18:17
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!
W1

w1848494

Joined 26.03.2023

Close position on bar close
26 Mar 2023, 18:17


How do I close a position when a bar closes, (Not on the opening of the next one).

For example a if a trade is opened at the opening of a bar, how do I close it on the closing price of the same bar???


@w1848494
Replies

PanagiotisChar
27 Mar 2023, 11:12

Hi there,

At the moment there is no event raised at the moment a bar closes. A workaround would be to implement a Timer that is triggered on fixed intervals which coincide with a bar closing time.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 


@PanagiotisChar

firemyst
28 Mar 2023, 03:20

RE:

PanagiotisChar said:

Hi there,

At the moment there is no event raised at the moment a bar closes. A workaround would be to implement a Timer that is triggered on fixed intervals which coincide with a bar closing time.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 

Or if you're using a chart that doesn't involve time like Renko and Range bars where a timer isn't practical, you can see how well the Bar Open event works for you because obviously when a new bar opens, the previous bar is closed.


@firemyst

w1848494
28 Mar 2023, 07:14

RE: RE:

firemyst said:

PanagiotisChar said:

Hi there,

At the moment there is no event raised at the moment a bar closes. A workaround would be to implement a Timer that is triggered on fixed intervals which coincide with a bar closing time.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 

Or if you're using a chart that doesn't involve time like Renko and Range bars where a timer isn't practical, you can see how well the Bar Open event works for you because obviously when a new bar opens, the previous bar is closed.

Hey,

Thanks for answering. I tried doing the same, but there's almost always a considerable difference between the two prices. 


@w1848494

w1848494
28 Mar 2023, 07:16

RE:

w1848494 said:

How do I close a position when a bar closes, (Not on the opening of the next one).

For example a if a trade is opened at the opening of a bar, how do I close it on the closing price of the same bar???

Hey,

 

Thanks for answering.

How do I use the timer to do it. Can u suggest with sample code?

 

Regards,

Sid

 


@w1848494

PanagiotisChar
28 Mar 2023, 08:46

Hi Sid,

There is a hyperlink on the Timer word in my post above.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 


@PanagiotisChar