OrderSend error 4107

 

During a back test I receive the error message 'OrderSend error 4107 .... invalid price 1.39103000' in the Journal tab.

I bracketed the suspect function with 2 print statements as shown below


Print("Ask1=",Ask);

ticket=OrderSend(Symbol(),OP_BUY, user_lots, Ask, slip, stoploss, takeprofit, EA, MagicNo, 0, Blue);

Print("Ask2=",Ask);


The printout from the Journal tab is shown below.

The Ask price is 1.391 on both sides of the OrderSend function according to print statement.

However the function is returning an error with Ask price 1.39103000. I am stumped. What is causing this?


2009.08.03 20:33:28 2009.06.16 15:00 FxTriggerTrader_EU EURUSD,H1: Ask2=1.391

2009.08.03 20:33:28 2009.06.16 15:00 FxTriggerTrader_EU EURUSD,H1: OrderSend error 4107

2009.08.03 20:33:28 2009.06.16 15:00 FxTriggerTrader_EU EURUSD,H1: invalid price 1.39103000 for OrderSend function
2009.08.03 20:33:28 2009.06.16 15:00 FxTriggerTrader_EU EURUSD,H1: Ask1=1.391


note: I downloaded the history file from MetaQuotes history center. That may be irrelevant.

 

Looks like you are using 5 digit history data when 4 digit data is expected due to the parameters that have been set whilst you've had that MetaTrader instance connected to a broker.

Try swapping "Ask" for "NormalizeDouble(Ask,4)" and let me know how it goes.


CB

 
SquareRoot:

During a back test I receive the error message 'OrderSend error 4107 .... invalid price 1.39103000' in the Journal tab.

I bracketed the suspect function with 2 print statements as shown below


Print("Ask1=",Ask);

ticket=OrderSend(Symbol(),OP_BUY, user_lots, Ask, slip, stoploss, takeprofit, EA, MagicNo, 0, Blue);

Print("Ask2=",Ask);


The printout from the Journal tab is shown below.

The Ask price is 1.391 on both sides of the OrderSend function according to print statement.

However the function is returning an error with Ask price 1.39103000. I am stumped. What is causing this?


2009.08.03 20:33:28 2009.06.16 15:00 FxTriggerTrader_EU EURUSD,H1: Ask2=1.391

2009.08.03 20:33:28 2009.06.16 15:00 FxTriggerTrader_EU EURUSD,H1: OrderSend error 4107

2009.08.03 20:33:28 2009.06.16 15:00 FxTriggerTrader_EU EURUSD,H1: invalid price 1.39103000 for OrderSend function
2009.08.03 20:33:28 2009.06.16 15:00 FxTriggerTrader_EU EURUSD,H1: Ask1=1.391


note: I downloaded the history file from MetaQuotes history center. That may be irrelevant.

replacing Ask with NormalizeDouble(Ask,Digits) fixes the problem

 

Such error I got with Demo Account:

2016.10.07 19:02:32.001    mGRID_ver7E01FT5Auto4 USDZAR,H4: invalid price for OrderSend function

All Normalized. Code is below:

//+------------------------------------------------------------------+
// Set up a new grid
       
InitialPrice =NormalizeDouble(Ask,Digits);
SellGoal = NormalizeDouble(InitialPrice-(Levels+1)*pips*Point, Digits);
BuyGoal  = NormalizeDouble(InitialPrice+(Levels+1)*pips*Point, Digits);
for(cpt = 1; cpt <= Levels; cpt++)
{
ticket=    OrderSend(Symbol(),OP_BUYSTOP,lots,NormalizeDouble(InitialPrice+cpt*pips*Point, Digits),Slipppppage,SellGoal,BuyGoal,
DoubleToStr(InitialPrice,Digits),Magic,0,Blue);

if(ticket<0)
     {
      ErrNumber = GetLastError();
      Print("OrderSend failed with error #",ErrNumber);
      if(ErrNumber==4107)
      {
      Print("Order Send Price = ", NormalizeDouble(InitialPrice+cpt*pips*Point, Digits) );
      Print("Stop Loss = ", SellGoal);
      Print("Take Profit", BuyGoal);
     
      }
     }
   else
      Print("OrderSend placed successfully");
     
Sleep(1000);
       
ticket=     OrderSend(Symbol(),OP_SELLSTOP,lots,InitialPrice-cpt*pips*Point,Slipppppage,
NormalizeDouble(BuyGoal+spread*Point,Digits),NormalizeDouble(SellGoal+spread*Point,Digits),
DoubleToStr(InitialPrice,Digits),Magic,0,Red);

if(ticket<0)
     {
     ErrNumber = GetLastError();
      Print("OrderSend failed with error #",ErrNumber);
      if(ErrNumber==4107)
      {
      Print("Order Send Price = ", NormalizeDouble(InitialPrice+cpt*pips*Point, Digits) );
      Print("Stop Loss = ", NormalizeDouble(BuyGoal+spread*Point,Digits));
      Print("Take Profit", NormalizeDouble(SellGoal+spread*Point,Digits));
     
      }
     }
   else
      Print("OrderSend placed successfully");

Sleep(1000);
}}

//+------------------------------------------------------------------+
// Initial setup done

  

EA is improved version of:

http://www.forexfactory.com/showthread.php?t=109589

Any manipulation with does not brought good results.

 
Additional phenomena. "Auto trading", was switch off,  face of robot - Sad, but EA continue to trade ... Fantastic. This phenomena is the same in different brokers. Continue to trade all time.
Reason: