Bot opens positions; stop bot; restart bot; does it pick up previously open positions?
Created at 08 Apr 2019, 10:26
Bot opens positions; stop bot; restart bot; does it pick up previously open positions?
08 Apr 2019, 10:26
Hi everyone:
With automating trades, here's the sequence of events:
1) Start bot (one of many)
2) bot opens a position
3) I stop the bot for whatever reason; trade is still open on server because TP or SL isn't hit yet.
4) I restart bot
Question:
should the bot recognize the position it opened previously? Or is a bot only aware of positions it opened while the bot itself is running?
eg, will Positions.Count == 1 or should Positions.Count == 0?
Thank you.
firemyst
09 Apr 2019, 03:56
The answer to this question is Positions.Count == 1.
I ran the following test bot code to see what happens. I opened two FOREX positions with two instances of the same bot - one EURUSD and another AUDUSD.
The first instance opened EURUSD.
I stopped the bot and restarted with the ExecuteMarketOrder line commented out. It found 1 position.
Then I created a second instance of the bot running against AUDUSD. It opened a position.
I stopped both bots, exited out of cTrader, and then logged back in.
I started both bot instances and both recognized 2 opened positions.
Then I closed all the positions.
Code below.
Thank you.
@firemyst