Can I not use SendOrder() in the OnTimer() function?

Can I not use SendOrder() in the OnTimer() function?

I want to look for a local file and then send an order when it appears. I have the code, but the function returns 4014.

Thanks.

Check your error codes here - https://book.mql4.com/appendix/errors

ERR_REMAINDER_FROM_ZERO_DIVIDE

I’m in MT5. And, sorry, the error code is ERR_FUNCTION_NOT_ALLOWED 4014. Not 4012 as I originally posted.

Maybe you need to check ENUM_TERMINAL_INFO_INTEGER = TERMINAL_TRADE_ALLOWED OR IsTradeAllowed()

Both MessageBox() and OrderSend() functions return Error 4014 from my OnTimer:

#property indicator_chart_window

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   EventSetTimer(1);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
  
Alert(ENUM_TERMINAL_INFO_INTEGER(TERMINAL_TRADE_ALLOWED));
MessageBox("Check", "Query",MB_OKCANCEL);
Alert(GetLastError());      
MqlTradeRequest request={0};
MqlTradeResult  result={0};
OrderSend(request,result);
Alert(GetLastError());      
EventKillTimer(); 
  }
//+------------------------------------------------------------------+

Both MessageBox() and OrderSend() functions return Error 4014 from my OnTimer:

#property indicator_chart_window

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   EventSetTimer(1);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
  
Alert(ENUM_TERMINAL_INFO_INTEGER(TERMINAL_TRADE_ALLOWED));
MessageBox("Check", "Query",MB_OKCANCEL);
Alert(GetLastError());      
MqlTradeRequest request={0};
MqlTradeResult  result={0};
OrderSend(request,result);
Alert(GetLastError());      
EventKillTimer(); 
  }
//+------------------------------------------------------------------+

OrderSend() is not allowed in the indicator (nor any other trading related function).

OK, I see… I guess it needs to be in an EA?

Yes, trading functions work in the EA’s and scripts.

Surprisingly it’s what is stated in the documentation

yes sure
you can use it in OnTimer() function (MT4)
but take care it is not SendOrder() , IT IS OrderSend()

I am in forex since 2005.

See my products, they are the greatest.
Note that I am always updating them.

For MT4 Experts programming/development, please apply to the link below:

My library/codes (examples):
https://www.mql5.com/en/search#!keyword=soubra2003&amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bmodule=mql5_module_codebase&module=mql5_module_codebase

What’s new?