SendOrder() not allowed in OnTimer()?

 

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_DIVIDE4012Remainder from zero divide.
Error Codes - Appendixes - MQL4 Tutorial
Error Codes - Appendixes - MQL4 Tutorial
  • book.mql4.com
Error Codes - Appendixes - MQL4 Tutorial
 
honest_knave:

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

ERR_REMAINDER_FROM_ZERO_DIVIDE4012Remainder from zero divide.
I'm in MT5.  And, sorry, the error code is ERR_FUNCTION_NOT_ALLOWED 4014.  Not 4012 as I originally posted.
 
cstangor:
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()
 
Roberto Jacobs:
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();
  }
//+------------------------------------------------------------------+
 
OrderSend() is not allowed in the indicator (nor any other trading related function).
 
Drazen Penic:
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?
 
cstangor:
OK, I see... I guess it needs to be in an EA?

 

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

 
Drazen Penic:

 

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

Surprisingly it's what is stated in the documentation 
 
Drazen Penic: OrderSend() is not allowed in the indicator (nor any other trading related function).
Indicators can not do blocking calls. No Sleep, server calls, web requests, etc.
 

Alain Verleyen:
Surprisingly it's what is stated in the documentation 

 

Ah, the damned documentation again :)  So much of it to read, so easy to miss something.  I'm trying to be a good student, honest... but even the best students might need a little support now again again right?.  Thanks again for your help everyone.

 

Reason: