trade.ResultRetcode() is giving me zero

 

Goof day can anyone help me with these, I am trying to close partial my positions but I get error in the trade because it does not enter to the if() trade

I try to print error using trade.ResultRetcode() but it gives me " method failed. Return code=0. Code description: unknown retcode 0

I also ron my EA in Backtesting and this woks fine it does closePartial  so I dont know why It does Not works running the EA normally

Can anyoe help me please

void CierraPosicionParcial(string symbol)
  {
//printf(__FUNCTION__+"entra");
   int ticket=0;
   string Mysymbol ="";
   double volumen=0;
   double desviacion=100;
   double ptp=0;
   double ppo=0;
   double ppc=0;
   double meta=0;

//obtenemos la posicion abierta
   for(int i=PositionsTotal()-1; i>=0; i--) // recorrera todas las posiciones abiertas
     {
      // Obtener el # de ticket para la posicion abierta
      ticket=PositionGetTicket(i);
      Mysymbol=PositionGetSymbol(i);
      if(Mysymbol==symbol)
        {
         ptp= PositionGetDouble(POSITION_TP);
         ppo=PositionGetDouble(POSITION_PRICE_OPEN);
         ppc=PositionGetDouble(POSITION_PRICE_CURRENT);

         
         volumen = PositionGetDouble(POSITION_VOLUME);
         int PositionDirection=PositionGetInteger(POSITION_TYPE);
         if(PositionGetDouble(POSITION_PROFIT) > 0)
           {
            meta= MathAbs(ppc-ppo)/ MathAbs(ptp-ppo);
            Comment(round(meta*100)," %");
            printf(__FUNCTION__+" La posicion va ganando "+meta);
            if(meta >= 0.6)
              {
               printf(__FUNCTION__+" Si cumple la meta:"+meta);

               if(volumen > 0.01)
                 {
                  volumen = round(volumen*100/2)/100;
                  printf(__FUNCTION__+"entra a evaluar volumen2, volumen a cerrar: " + volumen);
// ------ here is the the if that gives me false   ---------------------------
                  if(trade.PositionClosePartial(ticket,volumen))
                    {
                     if(trade.PositionModify(PositionGetInteger(POSITION_TICKET),PositionGetDouble(POSITION_PRICE_OPEN),0))
                    }
                  else
                    {
                     Print("method failed. Return code=",trade.ResultRetcode(),
                           ". Code description:",trade.ResultRetcodeDescription());
                    }
                 }
              }
           }
        }
     }
  }
Testing trading strategies on real ticks
Testing trading strategies on real ticks
  • www.mql5.com
The article provides the results of testing a simple trading strategy in three modes: "1 minute OHLC", "Every tick" and "Every tick based on real ticks" using actual historical data.
 

If your program compiles without any error but doesn't do what it should start the debugger and check the relevant variables:

https://www.metatrader5.com/en/metaeditor/help/development/debug // Code debugging
https://www.mql5.com/en/articles/2041 // Error Handling and Logging in MQL5
https://www.mql5.com/en/articles/272 // Tracing, Debugging and Structural Analysis of Source Code
https://www.mql5.com/en/articles/35 // scrol down to: "Launching and Debuggin"

Code debugging - Developing programs - MetaEditor Help
Code debugging - Developing programs - MetaEditor Help
  • www.metatrader5.com
MetaEditor has a built-in debugger allowing you to check a program execution step by step (by individual functions). Place breakpoints in the code...
 

I Have insert a Flag to print the ticket number so we can see if the problem was in there, but number ticket is ok, so the problem comes from PositionClosePartial, any Idea??

William Roeder #:
You can not get the ticket until you first select a position https://www.mql5.com/en/docs/trading/positiongetinteger
MT5: first select a position via CPositionInfo, directly, or by 'MT4Orders' library (2016)
Reason: