newbe to MT5. Event OnTick

 

new to this - How can I stop a new tick event (OnTick) from executing (or get out of it). Tried using  if (!TERMINAL_TRADE_ALLOWED) return; but as stated that does not stop the event.

I need to do this as in the event i want to place a trade or report back the error if it fails.

Without allowing trading (while working on my code) if the the EA is attached to the chart the error saying it cannot trade is shown every tick. So I have to remove the EA from the chart

to stop the messages which is rather annoying

 
BigAl:

new to this - How can I stop a new tick event (OnTick) from executing (or get out of it). Tried using  if (!TERMINAL_TRADE_ALLOWED) return; but as stated that does not stop the event.

I need to do this as in the event i want to place a trade or report back the error if it fails.

Without allowing trading (while working on my code) if the the EA is attached to the chart the error saying it cannot trade is shown every tick. So I have to remove the EA from the chart

to stop the messages which is rather annoying


If the purpose of this is just to limit some Alert(), then count it.

static int Alarm_1;

if (error == true)
   {
   if (Alarm_1 <= 3)
      {
      Alert ("You have annoying error ",error);
      Alarm_1 ++;
      }
   }
   else
   {
   Alarm_1 = 0;
   }
 
Hi, as you are a newbie my suggestion is use Print to debug OnTick code before start to use Alert, because you can check your code without Alert annoying messages. After you reach stability in your code, you can start use Alerts.
Documentation on MQL5: Common Functions / Print
Documentation on MQL5: Common Functions / Print
  • www.mql5.com
Common Functions / Print - Documentation on MQL5
 
figurelli:
Hi, as you are a newbie my suggestion is use Print to debug OnTick code before start to use Alert, because you can check your code without Alert annoying messages. After you reach stability in your code, you can start use Alerts.

Thanks for the 2 suggestions. I will use debug to start and once happy with that then use Alert if I still have problems. Still do not understand why if trade is not allowed events are still activated though, if you know please tell me just to satisfy my curiosity

thanks to those who responded

 
Note that you are using OnTick event, so you will get all ticks of the chart instrument and there is no relation to sending orders or not in this event. If you take care about using right flags to detect and filter trends before send orders you will get the solution, because you will mask the ticks info you don't need.
 
BigAl:

Thanks for the 2 suggestions. I will use debug to start and once happy with that then use Alert if I still have problems. Still do not understand why if trade is not allowed events are still activated though, if you know please tell me just to satisfy my curiosity

thanks to those who responded

Trade is not allowed only make EA/Script can not trade, but it does not stop tick from coming in and execute EA/CI.
Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Symbol Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Environment State / Symbol Properties - Documentation on MQL5