How to program for protecting EA account automatically stopped when the Free Margin down to a certain level and continue the Free Margin of up to certain levels?

 

How to program for protecting EA account automatically stopped when the Free Margin down to a certain level and continue the Free Margin of up to certain levels?

 
Either setup order SL's to meet your margin requirements or have a 'Close All' function check for that criteria. Certain brokers also allow to set a global maximum loss on their side.
 
Thanks you very much.
 

The similar sample, "Capital defence" -> https://www.mql5.com/en/code

Reason: