Improperly formatted code removed by moderator. Please EDIT your post and use the CODE button (Alt-S) when inserting code.
Hover your mouse over your post and select "edit" ...
Hello, I'm trying to code a EA to block orders being opened once the max number of trades is opened on the terminal. But I'm keeping Autotrading enabled. Just trying to block Additional trades from Any charts or EAs.
Here is the code so far: If there is a EA for this that exists or a way to Limit the amount of trades opened to the Terminal let me know.
Improperly formatted code removed by moderator. Please EDIT your post and use the CODE button (Alt-S) when inserting code.
Hover your mouse over your post and select "edit" ...
Thanks got it!
how do you want to do that? - I cannot think of any way to prevent MT from opening a position if it is told to open one....
Want to manage different EAs across different charts and want to control the max number of trades across all the EAs.
Some EAs have Max Orders coded in but others don't.
One way was disabling Auto Trading until a trade closes then enable it back on.
// Input parameters extern int MaxTrades = 5; // Change this value to set the maximum number of trades // Global variable string globalVarName = "MaxTrades_AllowTrading"; // Name of the global variable to store the trading permission //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { // Check the global variable to see if trading is allowed from other EAs double varValue = GlobalVariableGet(globalVarName); if (varValue == 0) { int result = GlobalVariableSet(globalVarName, true); if (result == 0) { Print("Error while accessing the global variable. Error code: ", GetLastError()); } } // Refresh the rates to update the trading permission RefreshRates(); return INIT_SUCCEEDED; } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { int totalOrders = OrdersTotal(); bool tradingAllowed = true; int main = GetAncestor(WindowHandle(Symbol(), Period()), 2/*GA_ROOT*/); if (totalOrders >= MaxTrades) { tradingAllowed = false; } if (tradingAllowed != TerminalInfoInteger(TERMINAL_TRADE_ALLOWED)) { if (tradingAllowed) { Print("Auto Trading::::: Starting AutoTrading for all terminal charts"); } else { Print("Auto Trading::::: Stopping AutoTrading for all terminal charts"); } PostMessageA(main, WM_COMMAND, MT4_WMCMD_EXPERTS, 0); // Update the global variable with the current trading permission int result = GlobalVariableSet(globalVarName, tradingAllowed); if (result == 0) { Print("Error while setting the global variable. Error code: ", GetLastError()); } } } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { // Reset the global variable on deinitialization int result = GlobalVariableSet(globalVarName, true); if (result == 0) { Print("Error while setting the global variable. Error code: ", GetLastError()); } }
But I'm trying to see about blocking trades across all EAs running on a terminal.
One EA managing max trades across all running EAs.
Instead of disabling Auto Trading to Keep the EAs managing any opened trades.
Want to manage different EAs across different charts and want to control the max number of trades across all the EAs.
Some EAs have Max Orders coded in but others don't.
One way was disabling Auto Trading until a trade closes then enable it back on.
But I'm trying to see about blocking trades across all EAs running on a terminal.
One EA managing max trades across all running EAs.
Instead of disabling Auto Trading to Keep the EAs managing any opened trades.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Here is the code so far: If there is a EA for this that exists or a way to Limit the amount of trades opened to the Terminal let me know.