need assistance solving this EA error "invalid price 1.16925750 for OrderSend function"

To add comments, please log in or register
lehlogonolo28
51
lehlogonolo28  


//----
extern double TakeProfit = 20;
extern double Lots = 20;
extern double TrailingStop = 30;
extern double StopLoss = 40;
extern double MM = 0;
extern double Risk = 30;
extern double LotLimit = 50;
extern double Per = 3;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   double s = GlobalVariableGet("SELLLIMIT");
   double b = GlobalVariableGet("BUYLIMIT");
   double ds = GlobalVariableGet("DateS");
   double db = GlobalVariableGet("DateB");
//----
   if(ds != DayOfWeek())
     {
       GlobalVariableDel("SELLLIMIT");
       GlobalVariableDel("BUYLIMIT");
       GlobalVariableDel("DatesS");
       GlobalVariableDel("DatesB");
     }
   double H3,H4,L3,L4,SH4,SH3,BL3,BL4;
//----
   if(OrdersTotal() < 1 && Hour() == 23 && Minute() == 59) 
       return(0);
//----
   if(OrdersTotal() > 0 && Hour() == 23 && Minute() == 59) 
     {
       int total = OrdersTotal();
       //----
       for(int i = total - 1; i >= 0; i--)
         {
           OrderSelect(i, SELECT_BY_POS);
           int type = OrderType();
           bool result = false;
           //----
           switch(type)
             {
               //Close opened long positions
               case OP_BUY       : result = OrderClose(OrderTicket(), OrderLots(), 
                                                       MarketInfo(OrderSymbol(), MODE_BID), 
                                                       5, Red );
                                   break;
               //Close opened short positions
               case OP_SELL      : result = OrderClose(OrderTicket(), OrderLots(), 
                                                       MarketInfo(OrderSymbol(), MODE_ASK), 
                                                       5, Red );
                                   break;
               //Close pending orders
               case OP_BUYLIMIT  :
               case OP_BUYSTOP   :
               case OP_SELLLIMIT :
               case OP_SELLSTOP  : result = OrderDelete(OrderTicket());
             }
           //----
           if(result == false)
             {
               Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError());
               Sleep(3000);
             }  
         }
     }
   H4 = ((((High[1] - Low[1])*1.1) / 2) + Close[1]);
   H3 = ((((High[1] - Low[1])*1.1) / 4) + Close[1]);
   L3 = (Close[1] - ((High[1] - Low[1])*1.1) / 4);
   L4 = (Close[1] - ((High[1] - Low[1])*1.1) / 2);
//----
   if(db != DayOfWeek() && s == 0) 
     {
       SH3 = OrderSend(Symbol(), OP_SELLLIMIT, Lots, H4, 3, H4 + StopLoss*Point, 
                       H4 - TakeProfit*Point, "H3", 0, 0, Red);
       //----
       if(SH3 < 0)
         {
           GlobalVariableSet("SELLLIMIT", 0);
         }
       else 
         {
           GlobalVariableSet("SELLLIMIT", 1);
           GlobalVariableSet("DateS", DayOfWeek());   
         }
     }
//----
   if(db != DayOfWeek() && b == 0) 
     {
       BL3 = OrderSend(Symbol(), OP_BUYLIMIT, Lots, L4, 3, L4 - StopLoss*Point, 
                       L4 + TakeProfit*Point, "L3", 0, 0, Green);  
       //----
       if(BL3 < 0)
         {
           GlobalVariableSet("BUYLIMIT", 0);  
         }
       else 
         {
           GlobalVariableSet("BUYLIMIT", 1);
           GlobalVariableSet("DateB", DayOfWeek());   
         }
     }
  }       
//+------------------------------------------------------------------+

Stuart Browne
7455
Stuart Browne  
I haven't gone through your code but the first thing you should do is to normalize the order price to the correct number of digits - 2, 3, 4 or 5 depending on the symbol and broker
Alain Verleyen
36133
Alain Verleyen  
Stuart Browne:
I haven't gone through your code but the first thing you should do is to normalize the order price to the correct number of digits - 2, 3, 4 or 5 depending on the symbol and broker

Hi Stuart :-)

Please note that a normalized price working for all symbols should be done from ticksize and not only digits.

lehlogonolo28
51
lehlogonolo28  

Thank you for your response Alain Verleyen and Stuart Browne.

I have been trying to modify it using  NormalizeDouble(digits) with no success. Could you please indicate with a working code.

Regards 

Osama Shaban
1549
Osama Shaban  

With pending orders always the situation is harder than market orders operations !!!.

You always need to check at the time of sending the pending order (Limit one) is that the current price

is higher than the BUYLIMIT and lower than the SELLLIMIT levels.

The NormalizeDouble(Price, Digits) is also essential as you have been advised by  Alain Verleyen and Stuart Browne.

Frederic Metraux
412
Frederic Metraux  

Placing a stop is a bit tricky. Like says Osama, price must be checked.

For a buy stop the price must be checked like this:

minprice=SymbolInfoDouble(symbol,SYMBOL_ASK)+SymbolInfoDouble(symbol, SYMBOL_POINT) * SymbolInfoInteger(symbol,SYMBOL_TRADE_STOPS_LEVEL);
if(price<minprice){price=minprice;}
lehlogonolo28
51
lehlogonolo28  
thank you Fred and Osama I appreciate your input, this one is quite challenging.
lehlogonolo28
51
lehlogonolo28  
Alain Verleyen:

Hi Stuart :-)

Please note that a normalized price working for all symbols should be done from ticksize and not only digits.

Hi Alian

Im aware you once had a similar challenge how did you resolve it.My broker is a 5 digit broker

Regards 

Alain Verleyen
36133
Alain Verleyen  
lehlogonolo28:

Hi Alian

Im aware you once had a similar challenge how did you resolve it.My broker is a 5 digit broker

Regards 

The minimum is to normalize your prices :

   double tickSize=SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_SIZE);
   double openprice=MathRound(L4/tickSize)*tickSize;
lehlogonolo28
51
lehlogonolo28  
Alain Verleyen:

The minimum is to normalize your prices :

Thank you so so much Alian.
To add comments, please log in or register