Automatically Toggle Autotrading

 

Hello Everyone,


I have a semiautomated M1 stradegy that I use an EA for. I am looking for a way to automatically toggle off the autotrading function preferably after the close of each trade or at specific time intervals.


The reason for this is im using a VPS for server speed, and in the event that I lose internet or the power goes out I dont want the bot continuing to trade since im on M1 it could be detrimental to my account.


Any way to do this with code or settings within MT5?


Anyone have insights or alternative solutions?


Thanks in advance.

 
ebarrow123: I have a semiautomated M1 stradegy that I use an EA for. I am looking for a way to automatically toggle off the autotrading function preferably after the close of each trade or at specific time intervals. The reason for this is im using a VPS for server speed, and in the event that I lose internet or the power goes out I dont want the bot continuing to trade since im on M1 it could be detrimental to my account. Any way to do this with code or settings within MT5? Anyone have insights or alternative solutions?

If you have the source code to the EA, then change it to stop trading based on your requirements.

If not, then search the CodeBase as there are examples there for turning off the "Algo Trading" via DLL calls.

 
Fernando Carreiro #:

If you have the source code to the EA, then change it to stop trading based on your requirements.

If not, then search the CodeBase as there are examples there for turning off the "Algo Trading" via DLL calls.

Thanks!
 

Here is one example from the CodeBase ...

Code Base

How to Disable/Enable Auto/Algo-Trading in both MT5 and MT4.

Kailash Bai Mina, 2022.04.21 07:38

Just simple codes to Disable/Enable Auto/Algo-Trading in both MT5 and MT4. Of course, DLLs must be allowed, This cannot be done without DLLs
//--- importing required dll files
#define MT_WMCMD_EXPERTS   32851
#define WM_COMMAND 0x0111
#define GA_ROOT    2
#include <WinAPI\winapi.mqh>

//+------------------------------------------------------------------+
//| Toggle auto-trading button                                       |
//+------------------------------------------------------------------+
void AlgoTradingStatus(bool newStatus_True_Or_False) {
    //--- getting the current status
    bool currentStatus = (bool) TerminalInfoInteger(TERMINAL_TRADE_ALLOWED);
    //--- if the current status is equal to input trueFalse then, no need to toggle auto-trading
    if(trueFalse != newStatus_True_Or_False) {
        //--- Toggle Auto-Trading
        HANDLE hChart = (HANDLE) ChartGetInteger(ChartID(), CHART_WINDOW_HANDLE);
        PostMessageW(GetAncestor(hChart, GA_ROOT), WM_COMMAND, MT_WMCMD_EXPERTS, 0);
    }
}
//+------------------------------------------------------------------+
Reason: