What happens with the data on arrays when the MT4 is reseted.

 

Hi people,

I'm creating an EA which uses an array to store different price leves to be considered for each opened order.

I'm worry about what happens when external events affect the EA execution, for example: interruptions in the internet connection, or even worst a complete reset of the computer.

It's important to me to recover the data on the array when the MT4 is restarted.

- Which solutions can be implemented for this requirement?

- Saving the data to a file is a possibility to be considered? How does it affect the EA performance?

A last question, how can I detect the MT4 has been restarted?

Thanks in advance for your comments.

 
desert:

It's important to me to recover the data on the array when the MT4 is restarted.

- Which solutions can be implemented for this requirement?

- Saving the data to a file is a possibility to be considered? How does it affect the EA performance?

This strongly depends on the data you have to store and the algorithm used. A write after each tick will definately cost some performace but in general this should not be an issue on modern PC's.

A last question, how can I detect the MT4 has been restarted?

If you use a file based recovery system you can add a token to the file in the deinit function. When you recover from the file and the token is not set you know that it was a 'Hard Shutdown'

Thanks in advance for your comments.

Additionaly my personal toughts: If possible find a way to recovery all your needed variables from the trading history / active trades. If you ask me, that is the most secure and reliable way of dooing it.

If you use a filebased system for example you can not recover after a HDD crash, or recover from a different pc. Even these scenarios are very unlikely they can happen. Up to now i was able to implement a trade/history based algorithm for all the systems i wrote in the last years.

 

There are only two possibilities. On the first call to init, either recalculate whatever is required and recover or read the file you wrote (persistent storage) previously.

What is it that you can't recalculate?

 

Hi,

Thanks a lot zzuegg and WHRoeder for your comments, very appreaciated!

In that array I save information about different situations, but I describe the most important:

- Partial closes. I have created a function which allows me to have 3 levels of partial closes. So, we know that MT4 creates a new order when a partial close happens, considering this I keep in the array the current partial close level and the lot size (percentage of the original order) to close when the current level is recahed. I could not take a percentage of the current order if this is not the original one. Therefore, having the information in the array, I know which is the next level to reach. Is there a way to know the level of partial close, or the orignal lot by reading the history? How can I detect if an opened order has a previous original order? I'm quite interested on this.

Thanks again.

 

When MT reseted, data on Array will be gone. Array is just "another" variable with "funny way" to call it.

Write them into files or Global Variable (press F3 on MT) is good idea, beside your EA does not open trades on every tick isn't ?. Write to file/GlobalVariable (GVs) only when some value in your array has change.

Do not overwrite files/GV. Write them in 2 files, first file writing, over/write into first file/GV.. On second file writing, over/writes second file/GV., on third file writing, over/write to first file/GV., and so on back and forth.. So basically the EA have some sort of backups of latest file/GV..

Use GetTickCount(): 1) find out how fast your EA from start of the start() to return of the start(), 2) Create CI to find out how fast is next tick coming - the milisecs between ticks, 3) find out how much time spent in writing reading file/GV.. Then you can decide whether it's woth writing the file/GV..

If you don't like the EA writing some files/GV., create CI to mimic your EA logic, and let this CI do the file/GV. writing.

Write into GlobalVariable of time of current one minute bar. If time was elapsed more than 1 minute, your EA of MT has lost some time :(.

 
desert:

- Partial closes. I have created a function which allows me to have 3 levels of partial closes. So, we know that MT4 creates a new order when a partial close happens, considering this I keep in the array the current partial close level and the lot size (percentage of the original order) to close when the current level is recahed. I could not take a percentage of the current order if this is not the original one. Therefore, having the information in the array, I know which is the next level to reach. Is there a way to know the level of partial close, or the orignal lot by reading the history? How can I detect if an opened order has a previous original order? I'm quite interested on this.

When I do a partial close (one only) I move the SL to BE+1 and then close 1/2 and trail the remainder. No data needs to be saved.

When you open the order you know the lotsize and the three profit objectives. When you restart, you know where you originally opened (OrderOpenTime()), why can't you recalculate the original lotsize and the three profit objectives. No data needs to be saved.

 

Thanks for all your ideas.By reading your comments, I thought another possible solution to know which is the partial close level of the current opened order (remember I need 3 levels): I could read the number of closed orders with the same opened time, price level, and symbol. For example, if there was not closed orders with that info, then it means the opened order is the original one. Having that information I could save it in the array, then I could check on every tick if that value is not empty, in case that is empty that would mean a possible "Hard Shutdown", then I would just read the history again.

In this way I do not need to save a file or other solution, does it make sense?

Have a nice weekend.

 
zzuegg:

If you use a filebased system for example you can not recover after a HDD crash, or recover from a different pc. Even these scenarios are very unlikely they can happen. Up to now i was able to implement a trade/history based algorithm for all the systems i wrote in the last years.

I use external standalone backup/storage (ssd/flash) for sensitive data which is/are not dependable on hardware changes or malfunction (loads only on start-up), and on failure is also cheaper for replace (raid form of copy).
Reason: