Restarting a bot

Created at 16 Nov 2023, 09:16
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!
RO

robert.john.edgar

Joined 25.01.2023

Restarting a bot
16 Nov 2023, 09:16


Is there any tutorial or sample code for restarting a bot and having it pick up any existing position.

I have a working bot that creates and monitors new positions and its all working fine, however occasionally there is a need to restart the bot (like the PC reboots) and its a bit awkward if there was an open position, it  would be better if it could find and use the current open position…

TIA
Rob 


@robert.john.edgar
Replies

firemyst
21 Nov 2023, 01:30

Positions.FindAll(yourPosition.yourLabel, Symbol.Name)

You need to give each of your positions a unique label when creating them.

Then, when you start your bot, check for them if you know there's open positions:

Positions.FindAll(yourPosition.yourLabel, Symbol.Name)


@firemyst