Error 129 Invalid Price - How?

 

I wrote an EA to place orders from an email signal service and subsequently manage the orders afterwards. However any attempts to partially close orders and take profit at predefined levels have so far been impossible. Iam using the OrdersSuite.mqh file available here which includes all error processing for orders.


iSlippage is set to 100 as I have a 5 digit broker. Is this correct? Within the orders suite no modifications are made to the passed slippage value before the order request is sent.

I always recieve Error 129 Invalid Price, the function attempts 10x at this price before declaring a severe error and closing all my positions. Yet the price the positions are then closed at are well within the slippage limit.

What am I doing wrong here?


void ManageBuyOrder(double GBValue, int iTicket, int iMagicNo, double dLots, double dOpenPrice, double dSL)             
{
   
	double dNewSL;
   double dCloseLots;
   int    iNewTicket;
   //log(StringConcatenate("ManageBuyOrder function entered for #",iTicket));
	RefreshRates();
	if(GBValue==0)//a new order, as of yet unmodifed
   {
      if(Ask > dTarget1)
      {  
         dCloseLots = NormalizeDouble((dLots/4),2);//Alpari UK has lot increment of 0.01
         log(StringConcatenate("Condition 1 OK: dCloseLots =",dCloseLots));
         Alert("Target 1 passed on ",Symbol());
         RefreshRates();
		   if(OrderClose2(iTicket, dCloseLots, Bid, iSlippage, CLR_DEF)) 
		   {  
		      if(GlobalVariableSet(TradeProgressGB,1)==0) {
		      log(StringConcatenate("Set GlobalVariable: ",TradeProgressGB," failed",ErrorDescription(GetLastError())));}
		      log(StringConcatenate("Condition 1 OK: BUY order ",iTicket," TP1 reached. Order partially closed")); 
         }
			else log(StringConcatenate("Condition 1 Order Close Failed: ",ErrorDescription2(giError))); 
		}	 
	}
	if(GBValue==1)//a new order, as of yet unmodifed
   {
       //if price is above Target1 adjust SL to half the previous value
      if(Ask > dTarget1)
      {  
         dNewSL = NormalizeDouble((dOpenPrice - (dOpenPrice - dSL)/2),Digits);
         log(StringConcatenate("Condition 1 OK: NewSL = ",dNewSL));
         RefreshRates();
         if(OrderModify2(iTicket,0,dNewSL,0,0,CLR_DEF)) 
         {
            if(GlobalVariableSet(TradeProgressGB,2)==0) {
            log(StringConcatenate("Set GlobalVariable: ",TradeProgressGB," failed",ErrorDescription(GetLastError())));}
            log(StringConcatenate("Condition 1 OK: BUY order ",iTicket," successfully modified. New SL = ",dNewSL)); 
         }   
         else log(StringConcatenate("Condition 1 Order Modify Failed: ",ErrorDescription2(giError)));
      }
      //else if(Debug) log("Order not at Target1 yet");   
 

Is it possible you're trying to close a short position at the Bid price?

Or is it possible that OrdersSuite is normalizing the price to 4 digits when you need 5 or something like that?


CB