How to continue my strategy after server restart

Questions about MultiCharts and user contributed studies.
kinwai
Posts: 89
Joined: 03 May 2019
Has thanked: 12 times
Been thanked: 1 time

How to continue my strategy after server restart

Postby kinwai » 20 Feb 2020

When my strategy opened a position, I need to restart server due to something reasons (eg. Windows force restart, computer halt, stop computer in weekend .....etc)

Any way to resume my strategy? My strategy logic includes marketpostion (tried to use marketposition_at_broker to replace), entry price and some dynamic values assigning during real time calculation.

gpw797
Posts: 216
Joined: 04 Mar 2006
Has thanked: 3 times
Been thanked: 7 times

Re: How to continue my strategy after server restart

Postby gpw797 » 22 Feb 2020

When you restart your strategy you should be presented with a dialog box asking if you would like to accept the position(s) reported at your broker. Depends on settings in strategy see attached at bottom
Attachments
Annotation 2020-02-22 074120.png
(54.57 KiB) Not downloaded yet

kinwai
Posts: 89
Joined: 03 May 2019
Has thanked: 12 times
Been thanked: 1 time

Re: How to continue my strategy after server restart

Postby kinwai » 01 Mar 2020

I have tried it, but it just for entry price, contract. However, if the strategy has real time value calculation, it’s not able to get it back.

User avatar
Anna MultiCharts
Posts: 560
Joined: 14 Jul 2017
Has thanked: 42 times
Been thanked: 140 times

Re: How to continue my strategy after server restart

Postby Anna MultiCharts » 11 Mar 2020

kinwai,

Please describe the issue in detail as I’m afraid it’s not clear from your description. Attach some screenshots for illustration as well.

kinwai
Posts: 89
Joined: 03 May 2019
Has thanked: 12 times
Been thanked: 1 time

Re: How to continue my strategy after server restart

Postby kinwai » 11 Mar 2020

For example, if use 1 min chart and use dynamic variable to keep the day high value. After computer executed the strategy but computer halt and need to restart, how can resume the strategy but reload the previous dynamic variable?

User avatar
Anna MultiCharts
Posts: 560
Joined: 14 Jul 2017
Has thanked: 42 times
Been thanked: 140 times

Re: How to continue my strategy after server restart

Postby Anna MultiCharts » 01 May 2020

Hello kinwai,

Apart from assigning the position, you can use the !From Broker To Strategy MP Synchronizer! signal.

Also you could trade in asynchronous mode (AA) and pick up the strategy position From Chart as a starting point of calculations.

In synchronous mode (SA) you can add a signal with a logic similar to the sample below: for each order that happened in autotrading before the restart you can assign a matching ChangeMarketPosition order. In this case in the Assign Initial Market Position dialog you should also choose From Chart.

Sample code (not functional, just an idea):

Code: Select all

if date >= date_order1 and time >= time_order1 then once ChangeMarketPosition( shares_order1, price_order1 ,"name_order1") ; if date >= date_order2 and time >= time_order2 then once ChangeMarketPosition( shares_order2, price_order2 ,"name_order2");
So to sum it up, the recommendations are as follows:

1) use the From-To data range on the chart;
2) the variables that are not related to orders and positions should have the same or very close values compared to the values that existed before the autotrading termination;
3) to have access to the information about orders and positions (and relate variables)you can trade in AA mode and assign the initial positions From Chart,
Or
Add a special script to the strategy in SA mode that will assign a matching ChangeMarketPosition order for each order from the previous trading session. In this case Assign Initial Market Position = From Chart.

cwhorton
Posts: 9
Joined: 28 Sep 2016
Has thanked: 2 times
Been thanked: 2 times

Re: How to continue my strategy after server restart

Postby cwhorton » 12 Aug 2021

A nice solution would be that if autotrading is stopped with positions opened the instances of the strategy objects get serialized to disk. This way all variable values are persevered. Then, when auto trading is re-enabled you get a prompt asking if you want to resume from the saved strategy objects. If the market was open in the meantime the now instantiated strategy objects would be fed all the bars in during its suspension to potentially update any relevant variables. Any orders the strategy object triggers would be ignored (just as if there was a broker connection error) until it reached the current bar.

Mydesign
Posts: 177
Joined: 15 Feb 2017
Has thanked: 32 times
Been thanked: 39 times

Re: How to continue my strategy after server restart

Postby Mydesign » 14 Aug 2021

Hi,

Another way (which I use) to achieve that is to select Asynchronous mode (AA) together with "Assign initial position" dialogue. That way I keep all the backtest history and calculation persistance. I can switch off autotrading if needed while in position, and resume it as if it did not happen.

Granted, AA mode is not recommended since it does not check for orders confirmation. You need to constantly monitor your strategy.

Yet I do that all the time since I need to manually tweak some inputs while in position, which saddly switches off autotrading. FWIW, MC14 introduced a "Self-Adaptive Trading" feature, which is able to change inputs value without switching off autotrading. Since it is possible, we should be able to just do that with manual changes.


Return to “MultiCharts”