Mql5 position close error

 

I'm getting this error - error fill not supported - when trying to close a position using the mt5 trade.mgh  include file. The ea fails to close the position. I've serched everywhere and cant find a solution. Is there a problem in the mgh file below??

bool CTrade::SetTypeFillingBySymbol(const string symbol)
  {
//--- get possible filling policy types by symbol
   uint filling=(uint)SymbolInfoInteger(symbol,SYMBOL_FILLING_MODE);
   if((filling&SYMBOL_FILLING_FOK)==SYMBOL_FILLING_FOK)
     {
      m_type_filling=ORDER_FILLING_FOK;
      return(true);
     }
   if((filling&SYMBOL_FILLING_IOC)==SYMBOL_FILLING_IOC)
     {
      m_type_filling=ORDER_FILLING_IOC;
      return(true);
     }
//---


my code.


   for(int i=0; i<PositionsTotal(); i++)
    {
  
       {
       ulong ticket= PositionGetTicket(i);
      bool selected=PositionSelectByTicket(ticket);
      
      
     
      if (selected ==true)
       {
       
         ulong ticket3= PositionGetTicket(i);
       ulong ticket_by= PositionGetTicket(i);
      Object.PositionCloseBy( ticket3, ticket_by );
      
    }
    }
 }
}

what is the problem?

 
Please help order does not close.
 
First of all try to start the loob in inverse order
I=positionstotal()-1;I>=o;i--
The above is the correct way for loobung through orders if you want to close it

Then try to use positionclose not position close by 
And let us know
 
Still does not work. There are two open opposite positions of the same symbol that I wish to close.


Here is the include file quoted in the beginning of the programme.

  for(int i=PositionsTotal()-1; i>=0;i--)
    
     // string   symbol;
 

    {
  
       {
       ulong ticket= PositionGetTicket(i);
         ulong ticketby= PositionGetTicket(i);
      bool selected=PositionSelectByTicket(ticketby);
      
      
     
      if (selected ==true&&symbol==_Symbol)
       {
       
     

      Object.PositionCloseBy( ticket,ticketby );
    }


Here is the native include file that I recalled within include.


//+------------------------------------------------------------------+
//| Close one position by other                                      |
//+------------------------------------------------------------------+
bool CTrade1::PositionCloseBy(const ulong ticket,const ulong ticket_by)
  {
//--- check stopped
   if(IsStopped(__FUNCTION__))
      return(false);
//--- check hedging mode
   if(!IsHedging())
      return(false);
//--- check position existence
   if(!PositionSelectByTicket(ticket))
      return(false);
   string symbol=PositionGetString(POSITION_SYMBOL);
   ENUM_POSITION_TYPE type=(ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);
   if(!PositionSelectByTicket(ticket_by))
      return(false);
   string symbol_by=PositionGetString(POSITION_SYMBOL);
   ENUM_POSITION_TYPE type_by=(ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);
//--- check positions
   if(type==type_by)
      return(false);
   if(symbol!=symbol_by)
      return(false);
//--- clean
   ClearStructures();
//--- check filling
   if(!FillingCheck(symbol))
      return(false);
//--- setting request
   m_request.action     =TRADE_ACTION_CLOSE_BY;
   m_request.position   =ticket;
   m_request.position_by=ticket_by;
   m_request.magic      =m_magic;
//--- close position
   return(OrderSend(m_request,m_result));
#include <Trade\Tradenat.mqh>
CTrade1 Object ;

 
Peter Kaiza:
Still does not work. There are two open opposite positions of the same symbol that I wish to close.


Here is the include file quoted in the beginning of the programme.


It seems you don't understand what you are doing :

 for(int i=PositionsTotal()-1; i>=0;i--)
    {  
       {
       ulong ticket= PositionGetTicket(i);
         ulong ticketby= PositionGetTicket(i);
      bool selected=PositionSelectByTicket(ticketby);
      
      
     
      if (selected ==true&&symbol==_Symbol)
       {

      Object.PositionCloseBy( ticket,ticketby );
    }

What is that code ? It's not even possible to compile it as you have 3 opening '{' and only one closing '}'. You should at least copy and paste correctly.

Then you are using the same ticket on both side of the close by statement, ticket is the same as ticketby. The "selected" is useless. The "symbol" is not set.

Even if ticket and ticketby were different, are you thinking you can just pick 2 tickets in sequence and close one by the other ?

You need to get the ticket of your buy position, then the one of your sell position, obviously they must be on the same symbol, then you should use PositionCloseBy() with these tickets.

 
Alain Verleyen:

It seems you don't understand what you are doing :

What is that code ? It's not even possible to compile it as you have 3 opening '{' and only one closing '}'. You should at least copy and paste correctly.

Then you are using the same ticket on both side of the close by statement, ticket is the same as ticketby. The "selected" is useless. The "symbol" is not set.

Even if ticket and ticketby were different, are you thinking you can just pick 2 tickets in sequence and close one by the other ?

You need to get the ticket of your buy position, then the one of your sell position, obviously they must be on the same symbol, then you should use PositionCloseBy() with these tickets.

are you ok ? What is the point on saying "It seems you don't understand what you are doing ". We are here for help and being helped. if you are professional enough, good for you mate.

 
rodrigoabrao:

are you ok ? What is the point on saying "It seems you don't understand what you are doing ". We are here for help and being helped. if you are professional enough, good for you mate.

The point is that Alain goes on to explain what is wrong with the code.

Alain IS helping.

Your post however is not helpful at all!

 
Kareem Abdelhakim #:
First of all try to start the loob in inverse order
I=positionstotal()-1;I>=o;i--
The above is the correct way for loobung through orders if you want to close it

Then try to use positionclose not position close by 
And let us know

Hi,

What makes looping through the positions

from 0 to the  positionstotal() ---> for(int i=0; i<PositionsTotal(); i++)

and

from  positionstotal() to 0 --->  for(int i=PositionsTotal()-1; i>=0; i--)

different?

Reason: