Switch to Disable Autotrading on Startup

To add comments, please log in or register
Graham from Brisbane
91
Graham from Brisbane  

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 :)

to60
37
to60  
Graham from Brisbane:

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(...).

Konstantin Nikitin
7864
Konstantin Nikitin  
You can check the ASK/BID, in OnTick. If 0, do not work.
Graham from Brisbane
91
Graham from Brisbane  

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 ...

Graham from Brisbane
91
Graham from Brisbane  
Thanks for the help all, I ended up using the Sleep() function, and I put it in the init section. The 5 second delay gives me time to punch the auto trading button, and then I can end the EA without closing any positions.
Anthony Garot
3266
Anthony Garot  
Graham from Brisbane:

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.)

https://www.metatrader4.com/en/trading-platform/help/service/start_conf_file

Setting one of these might work to disable trading at startup.

    ExpertsEnable – enable/disable experts.
    ExpertsTrades – enable/disable the experts trading.

Configuration at Startup - Tools - MetaTrader 4 Help
Configuration at Startup - Tools - MetaTrader 4 Help
  • www.metatrader4.com
The client terminal can be launched with some predefined settings. For this purpose, the configuration file name will be passed to the client terminal as a parameter. If the full path to the file (Drive:\SubDirectory\FileName) is not given, the file will be searched for in the client terminal's data folder. The configuration file contains...
To add comments, please log in or register