Closing a Position after a cBot Restart

Created at 25 May 2020, 21:05
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!
EY

eynt

Joined 08.05.2020

Closing a Position after a cBot Restart
25 May 2020, 21:05


Suppose I entered a position using myResult = ExecuteMarketOrder(...) and before I was able to close the position my cBot was restated for unexpected reason (for example, electricity is down).How can I close the position? the myResult variable is lost.

 

Thanks

 

 


@eynt
Replies

PanagiotisCharalampous
26 May 2020, 08:09

Hi Yuval,

You can consider writing information in files instead so that the information is not lost after the cBot is restarted.

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

eynt
26 May 2020, 08:45

RE:

Than you

 

In order to close the position I need to use ClosePosition which takes a parameter of type Position which does not has a constructor and therefor even if I have all the data from the files I can't create a new position instance in order to close the open position.


@eynt

PanagiotisCharalampous
26 May 2020, 08:51

Hi Yuval,

You don't need to create a position, you can retrieve it from Positions property.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous