Start trading

Keeping the data of a variable after Stop()

Created at 17 Feb 2022, 14:30
cTrader Reddit
cTrader Discord
AL

Algo_Invest

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!

 


@Algo_Invest
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

Algo_Invest
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.

 

 


@Algo_Invest