Hello, is there a way to reset variables automatically after disabling AutoTrading (or after enabling it)?
Example: variable = 0 and then it's equal to 1 because of the code.
I decide to disable AutoTrading and after one hour I decide to enable AutoTrading. I want the variable to be equal to 0 again. Is there a way to do this step (reset variables) automatically?
Thanks,
Marko
I'm assuming MT4/MQL4, given that you refer to AutoTrading and not AlgoTrading. So, your topic has been moved to the section: MQL4 and MetaTrader 4
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
Example: variable = 0 and then it's equal to 1 because of the code.
I decide to disable AutoTrading and after one hour I decide to enable AutoTrading. I want the variable to be equal to 0 again. Is there a way to do this step (reset variables) automatically?
Please clear up if this is a MQL4 or MQL5 question.
- If it is an MQL4 question then please read ... Trade Permission - MQL4 programs - MQL4 Reference
- If it is an MQL5 question then please read ... Documentation on MQL5: MQL5 programs / Trade Permission
For both cases, the approach is similar. You would periodically read the status information of the Auto/Algo Trading and adjust your code logic or change variables accordingly.
Since when is the OnInit triggered when the Auto/Algo Trading button is enabled or disabled?
I have never seen that happen.
Thank you for responses. I thought that i can solve using a code like this:
if (isTradeAllowed() == false) //autotrading disabled { variable = 0; //reset variable }
but I don't think this can solve my problem. If EA is disabled it will not "read" my code, right? Or am I wrong?
Your code is without context so it is difficult to answer, but your approach is too simplified.
The OnTick() event handler is called on every tick. Are you going to reset the variable on every tick?
Instead detect when the state changes, either from enabled to disabled, or from disabled to enabled, and set your variables accordingly.
Also, please use the CODE button (Alt-S) when inserting code.Thanks. Inside the onTick() section I have the main code and my variable can takes value 0 or 1.
At the beggining it has value 0. When an order opens, variable = 1. I defined my conditions when a trend begins and I want to open only one order per trend. Until the trend continuous I will not close the order.
Then the trend changes (always following my definitions and conditions) and the variable is again set to 0. I use this variable because I don't want to open more than 1 orders inside a same trend. If variable = 0, EA can open an order if there are conditions, if variable = 1, no new opens.
All of this happens inside the onTick() event.
Anyway, I want to reset this variable to 0 everytime I manually disable AutoTrading. In this way, when I will enable AutoTrading again, the variable will have the value 0 and it will open an order if there will be conditions.
Do you think that it's ok to put this code inside onTick()?
if (isTradeAllowed() == false) //autotrading disabled { variable = 0; //reset variable }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello, is there a way to reset variables automatically after disabling AutoTrading (or after enabling it)?
Example: variable = 0 and then it's equal to 1 because of the code.
I decide to disable AutoTrading and after one hour I decide to enable AutoTrading. I want the variable to be equal to 0 again. Is there a way to do this step (reset variables) automatically?
Thanks,
Marko