Getting OrderSend error 4107 with an EA I am working on

 

I'm new to programming and have been working on creating my first EA. The latest problem I am having is that when back testing it through the strategy tester I am getting the following messages in the journal:

2013.04.18 12:00:05    2013.01.25 21:59  Flat Line Strategy EA Changes EURUSD,H1: OrderSend error 4107
2013.04.18 12:00:05    2013.01.25 21:59  Flat Line Strategy EA Changes EURUSD,H1: invalid price for OrderSend function
2013.04.18 12:00:05    2013.01.25 21:59  Flat Line Strategy EA Changes EURUSD,H1: Error opening BUY order : 4107

Although the messages say that the price is invalid, I think it's actually a time issue. The EA should only trade during the week with all trades being closed out on Friday's at 19.00, but these messages are appearing on every Friday, sometime after 19.00 throughout the whole back test. During normal trading times, from Monday 7.00 - Friday 19.00 the back test results work perfectly with no errors. So it's as if the the EA is trying to put orders in after Friday 19.00, when it shouldn't be, but then is getting a load of errors.

Hope that makes sense. Any ideas what the problem could be?

Here is what I have so far related to the time:

extern int       StartDay=1;
extern int       EndDay=5;
extern int       StartTime=7;
extern int       EndTime=19;
   //Check time is within permitted trading times 
   if(TimeDayOfWeek(Time[0])<StartDay)                                                              {return(0);}
   if(TimeDayOfWeek(Time[0])==StartDay && TimeHour(Time[0])<StartTime)                              {return(0);}
   if(TimeDayOfWeek(Time[0])==EndDay && TimeHour(Time[0])>=EndTime && TimeMinute(Time[0]>0))        {return(0);}
   if(TimeDayOfWeek(Time[0])>EndDay)                                                                {return(0);}
  if( TimeHour(Time[0])==EndTime && TimeDayOfWeek(Time[0])==EndDay )
    {
    if(OrdersTotal()>0)
      {
      for(i = OrdersTotal()-1; i >= 0; i--)
        {  
        OrderSelect(i,SELECT_BY_POS,MODE_TRADES);           
        if(OrderType()==OP_BUY && OrderMagicNumber()==BuyMagicNumber)
          {
          OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet);
          }
        if(OrderType()==OP_SELL && OrderMagicNumber()==SellMagicNumber)
          {
          OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet);
          }
        if(OrderType()==OP_BUYSTOP && OrderMagicNumber()==BuyMagicNumber)
          {
          OrderDelete(OrderTicket());
          }
        if(OrderType()==OP_SELLSTOP && OrderMagicNumber()==SellMagicNumber)
          {
          OrderDelete(OrderTicket());
          }
        }  
      }
    }
 
Philsko:

I'm new to programming and have been working on creating my first EA. The latest problem I am having is that when back testing it through the strategy tester I am getting the following messages in the journal:

2013.04.18 12:00:05    2013.01.25 21:59  Flat Line Strategy EA Changes EURUSD,H1: OrderSend error 4107
2013.04.18 12:00:05    2013.01.25 21:59  Flat Line Strategy EA Changes EURUSD,H1: invalid price for OrderSend function
2013.04.18 12:00:05    2013.01.25 21:59  Flat Line Strategy EA Changes EURUSD,H1: Error opening BUY order : 4107

Although the messages say that the price is invalid, I think it's actually a time issue. The EA should only trade during the week with all trades being closed out on Friday's at 19.00, but these messages are appearing on every Friday, sometime after 19.00 throughout the whole back test. During normal trading times, from Monday 7.00 - Friday 19.00 the back test results work perfectly with no errors. So it's as if the the EA is trying to put orders in after Friday 19.00, when it shouldn't be, but then is getting a load of errors.

Hope that makes sense. Any ideas what the problem could be?

Here is what I have so far related to the time:

2013.04.18 12:00:05    2013.01.25 21:59  Flat Line Strategy EA Changes EURUSD,H1: OrderSend error 4107

2013.04.18 12:00:05    2013.01.25 21:59  Flat Line Strategy EA Changes EURUSD,H1: invalid price for OrderSend function  

#define ERR_INVALID_PRICE_PARAM                    4107

  the messages say that the price is invalid  OrderSend error 

What is your OrderSend function doing you don't show 

 
Philsko:

I'm new to programming and have been working on creating my first EA. The latest problem I am having is that when back testing it through the strategy tester I am getting the following messages in the journal:

2013.04.18 12:00:05    2013.01.25 21:59  Flat Line Strategy EA Changes EURUSD,H1: OrderSend error 4107
2013.04.18 12:00:05    2013.01.25 21:59  Flat Line Strategy EA Changes EURUSD,H1: invalid price for OrderSend function
2013.04.18 12:00:05    2013.01.25 21:59  Flat Line Strategy EA Changes EURUSD,H1: Error opening BUY order : 4107

Although the messages say that the price is invalid, I think it's actually a time issue. 

It's probably that the open price or TP or SL is invalid,  are you calculating these prices ?  see this post/thread for more info:  https://www.mql5.com/en/forum/136997/page2#779284
 

Thank you both for your quick responses. I've actually managed to solve the problem. As I thought it was a time issue with some of the code I posted above as opposed to a problem with the OrderSend function.

No idea why it gave that particular error code but at least it's fixed! :-)

 
Philsko:

Thank you both for your quick responses. I've actually managed to solve the problem. As I thought it was a time issue with some of the code I posted above as opposed to a problem with the OrderSend function.

No idea why it gave that particular error code but at least it's fixed! :-)

I suspect not all the output to the log was generated by your code and if thats the case then you probably haven't fixed the underlying issue.
Reason: