Keeping the data of a variable after Stop()

Created at 17 Feb 2022, 14: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!
NC

ncel01

Joined 19.03.2020

Keeping the data of a variable after Stop()
17 Feb 2022, 14:30


Hello,

Is there a possibility to keep the data of some of variables, to be considered on Start(), after stopping cBot?

 

Thank you!

 


@ncel01
Replies

firemyst
18 Feb 2022, 07:08

There's at least two easy options:

1) save the values to a data file, and then read the values back in when you restart your bot. You'll probably want to save to an XML or Json file so you have easy parsers available.

2) not the best practice, but you can create static variable collections and reference those. As long as you don't close cTrader, they should be around. However, if you close down cTrader, you'll lose the values in those variables.

 


@firemyst

ncel01
18 Feb 2022, 11:57

RE:

firemyst said:

There's at least two easy options:

1) save the values to a data file, and then read the values back in when you restart your bot. You'll probably want to save to an XML or Json file so you have easy parsers available.

2) not the best practice, but you can create static variable collections and reference those. As long as you don't close cTrader, they should be around. However, if you close down cTrader, you'll lose the values in those variables.

 

Hi firemyst,

 

Thanks for the tip!

I'll try to implement option 1.

 

 


@ncel01