close and restart Metatrader

 
Hello friends
When running the code, how can it detect that Metatrader is closed and restart?
 

The MQL code will be stopped when metatrader is closed.

You need an external program (not MQL) to implement this.

But I suggest instead of implementing this, don't close the metatrader when you don't want the metatrader to be closed.

 
Vladislav Boyko #:

The MQL code will be stopped when metatrader is closed.

You need an external program (not MQL) to implement this.

But I suggest instead of implementing this, don't close the metatrader when you don't want the metatrader to be closed.

But sometimes this is unavoidable due to power fluctuations

 
st.khalili #:

But sometimes this is unavoidable due to power fluctuations

I would prefer to place the advisor on VPS and sleep peacefully.

Even if you implement automatic launch of metatrader, it will still be much worse than VPS.

 
Vladislav Boyko #:

I would prefer to place the advisor on VPS and sleep peacefully.

Even if you implement automatic launch of metatrader, it will still be much worse than VPS.

Yes VPS is best.

But if you really, really want such a feature, I guess you could write the original start time of the EA to a file - or just note it manually.

If you want to use MQL5, using functions like GetTickCount64() & GetMicrosecondCount() you may be able to compare and figure it out. Please refer to the documentation for these

If you want to do it at OS level you can use uptime in Linux, or for Windows there are various methods:

https://www.windowscentral.com/how-check-your-computer-uptime-windows-10

But you could also install GitBash or some similar Unix emulator for Windows and use the uptime command there also I guess
How to check your computer uptime on Windows 10
How to check your computer uptime on Windows 10
  • 2022.09.27
  • www.windowscentral.com
Do you need to know your PC's uptime? In this guide, we show you four ways to check on Windows 10.
 
R4tna C #:

Yes VPS is best.

But if you really, really want such a feature, I guess you could write the original start time of the EA to a file - or just note it manually.

If you want to use MQL5, using functions like GetTickCount64() & GetMicrosecondCount() you may be able to compare and figure it out. Please refer to the documentation for these

If you want to do it at OS level you can use uptime in Linux, or for Windows there are various methods:

https://www.windowscentral.com/how-check-your-computer-uptime-windows-10

But you could also install GitBash or some similar Unix emulator for Windows and use the uptime command there also I guess

I have use  GetMicrosecondCount() , but i don't know why it dosen't work for offline chart

 
st.khalili #:

I have use  GetMicrosecondCount() , but i don't know why it dosen't work for offline char

I have no idea - perhaps it needs a server connection.

You may be better off developing this using OS commands - but getting a VPS will save all this effort

 
R4tna C #:

Yes VPS is best.

But if you really, really want such a feature, I guess you could write the original start time of the EA to a file - or just note it manually.

If you want to use MQL5, using functions like GetTickCount64() & GetMicrosecondCount() you may be able to compare and figure it out. Please refer to the documentation for these

If you want to do it at OS level you can use uptime in Linux, or for Windows there are various methods:

https://www.windowscentral.com/how-check-your-computer-uptime-windows-10

But you could also install GitBash or some similar Unix emulator for Windows and use the uptime command there also I guess

you are right and vps is best,

I am trying to solve this problem for when there is no VPS, I have used the GetMicrosecondCount()  function and it shows me if the meta is restarted.

I have asked it to read data  if the time of this function is less than 5 seconds from my file (it is stored in the necessary data file)

but it does not do this for offline data!!!

Documentation on MQL5: Common Functions / GetMicrosecondCount
Documentation on MQL5: Common Functions / GetMicrosecondCount
  • www.mql5.com
GetMicrosecondCount - Common Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
As my contribution to other friends
Because offline charts are made by smaller online charts, they need a few seconds more time to have the initial data.
Therefore, this time can be provided to the robot with the command Sleep().
I solved the above problem with this command and got the best solution
Reason: