I get ERROR 4756 during with using CTrade, Please help MQL5!

Chaiya Srisawat
9462
Chaiya Srisawat  

Hello

I am so new in MQl5 programing, I program it by passing to CTrade Class, and found the error 4756, then I print check detail is follows..


This routine using..

//+------------------------------------------------------------------+

//| Modify specified opened position                                 |

//+------------------------------------------------------------------+

bool CTrade::PositionModify(const ulong ticket,const double sl,const double tp)

  {

//--- check stopped

   if(IsStopped(__FUNCTION__))

      return(false);

//--- check position existence

   if(!PositionSelectByTicket(ticket))

      return(false);

//--- clean

   ClearStructures();

//--- setting request

   m_request.action  =TRADE_ACTION_SLTP;

   m_request.position=ticket;

   m_request.symbol  =PositionGetString(POSITION_SYMBOL);

   m_request.magic   =m_magic;

   m_request.sl      =sl;

   m_request.tp      =tp;

   //

   Print(PositionGetDouble(POSITION_SL),"<<",sl,"--",tp,">>",PositionGetDouble(POSITION_TP));  <-----I print check the inside routine for audit the value!!

   

//--- action and return the result

   return(OrderSend(m_request,m_result));

  }


I call the routine as follows..

//+------------------------------------------------------------------+

//| Trailing stop/profit short position                              |

//+------------------------------------------------------------------+

bool TrailingStopShort(ulong positionTicket,double sl)

  {

   bool result;

//---

   if(IsHedging())

      result=m_trade.PositionModify(positionTicket,sl,PositionGetDouble(POSITION_TP)); < this routine is tack action !!

   else

    result=m_trade.PositionModify(PositionGetString(POSITION_SYMBOL),sl,PositionGetDouble(POSITION_TP));

//---

Print(GetLastError());  <-------------- I print check after call the routime

   return(result);

  }


So now I have to receive the print check 2 lines eg.. Last Error and the exit TP/SL and new TP/SL..

See the result.. that surprise to me..

My Print test

  • OLD SL= 0.0 >> NEW SL =1.19378
  • OLD TP=1.19349 >> NEW TP= 1.19349

From MQl5 report

  • OLD SL=0.0  >> NEW SL=1.19378
  • OLD TP=1.19159 >> NEW TP=1.19349

And this the evident from testing

Order(#7) from log, server say tp=1.20008 and the test terminal read T/P=1.20008

So it seem that data reading from function is not same.

PositionGetDouble(POSITION_TP)) <--- give to me  1.20695


The old TP from MQL5 and my print is not same and go to error 4756


Please advise to me how to fix this..

Chaiya

Alain Verleyen
40764
Alain Verleyen  

Your position #7 is a sell and you are trying to set the TP (1.20695) above the SL (1.20648). What is current market price ? For a SELL the TP must always be below ask price (minus stoplevel).

   if(IsHedging())

      result=m_trade.PositionModify(positionTicket,sl,PositionGetDouble(POSITION_TP)); < this routine is tack action !!

Before using PositionGetDouble() you need to select a position (see documentation), where is it done ?

R3za1361
7
R3za1361  

Hello

I wrote an EXPERT but with a 4756 error please Guide me

Thanks

Files: