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 ;
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.
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.
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!
First of all try to start the loob in inverse order
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?

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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??
my code.
what is the problem?