Hi All, hope you can help me.
I have found that if my terminal is shut down by way of power crash or accidental click on the terminal x button, the EA that I was running at the time continues to run when I reopen the terminal, probably due to the incorrect removal proceedure. This nearly always causes one of my trades (I think it's always a short position) to be closed due to stop loss reason. I'm guessing that it has something to do with the ASK being 0 for a short time at the time of reestablishing the connection, because the EA, which has immediately resumed running, sees the stop loss as being activated, and runs the OrderClose function.
I can't find a way to programmatically remove or disable the EA following the crash, including using a global variable, so I was wondering if there is a switch that can be used on the terminal opening to set autotrading to false. This won't stop the EA from continuing, but it will prevent my positions being closed. I can then end the EA in the correct manner.
Sorry about the size of the post :)
i maked a function like this:if (CountOrderByMagic(X)<=0) OrderSend(...). The X is magic number of my order .Then i reboot the computer start my MT4 automatically and open 200 SELL orders.i think you have to do this:
1-) do not use for cycle as i++ , use it as i-- .
2-) use in the "IF" clause Bars count and correct magic number.for example if (Bars>=100 && MagicNo==X && CountOrderByMagic(X)<=0) OrderSend(...).
Thanks for the help, everyone. I shall try all, and I have a feeling that the "if tick=0" solution should solve the problem. I'm not too sure about the sleep idea in the init, because the global variable check in the init area didn't work. The solution put by to60 will get a try too.
I'll let you know how it goes ...
I can't find a way to programmatically remove or disable the EA following the crash
You might try starting MT4 using command line parameters with an .ini file. (Create an icon on the desktop.)
Setting one of these might work to disable trading at startup.
ExpertsEnable – enable/disable experts. ExpertsTrades – enable/disable the experts trading.