[Position Doesn't Exit]

 

I have issue where I am getting the error [Position Doesn't Exist]
Below is my function that closes trades. Note: I am using this ea to close trades on many symbols. I have not added check for Symbols, because I want the ea to manage all trades; that were opened by other eas and on other charts, symbols.
I will appreciate the answer, however, I will appreciate, even more, for document source to look up, for myself. But as yet, I think that I had tried everything, but this issue keeps propping up. Maybe it is not avoidable?

#include "PositionInfo.mqh"   CPositionInfo     position;
#include "TradeAlt.mqh"       CTradeAlt         trade;
   trade.SetAsyncMode(true);
void CloseTrades(int total, int trades, int no2close = 99)
  {
   ulong tk;
   double divb = equ/bal;
   int neg = 0, otyp = 9;
   bool marg = info.MarginLevel()>lever;
//   no2close=equ>MaxEqu[2] && aboveDD && info.MarginLevel()<=lever ? 99 : no2close;
   uint worst=(uint)worsTics[0];
//   bool loss = equ/MaxEqu[2]<0.85;
   bool closeAll = equ>0.00 && equ>bal+eqplus*1.618034;
   tsl[0]=tsla=0.00;
   tsl[1]=tslb=0.00;
   trailPft=iMinimalProfit;
   for(int k=total-1; k>=0; k--)
     {
      if(position.SelectByIndex(k))
        {
         tk=position.Ticket();
         if(tk<=0 || tk!=position.Ticket())
            break;
         otyp = position.Type();
         if(otyp!=POSITION_TYPE_SELL && otyp!=POSITION_TYPE_BUY)
            continue;
         else
           {
            if(position.Ticket()==worst || (no2close==99 && !marg) || closeAll)
              {
               if(tk==worst)
                  ++neg;
               if(trade.PositionClose(tk,iSlippage)>0)
                  continue;
               else
                  break;
              }
            else
              {
               ltv=position.Volume();
               if(no2close!=99 && neg<no2close && no2close>0)
                 {
                  for(int i = 1; i<no2close; ++i)
                    {
                     tk=position.Ticket();
                     if(neg>=no2close)
                        break;
                     if((worsTics[i]>0 && tk==worsTics[i]) || tk==worst)
                       {
                        ++neg;
                        ltv=position.Volume();
                        if(ltv<iStartLots) // || profitDirection!=otyp || loss) // || no2close!=99)
                          {
                           if(trade.PositionClose(tk,iSlippage)>0)
                              continue;
                           else
                              break;
                          }
                        else
                          {
                           sw=position.Swap();
                           pft=position.Profit();
                           //                           xcm=position.Commission()*2;
                           net = pft-iMinimalProfit+sw;
                           net+=((net>-xcm)?xcm:-iMinimalProfit);
                           if(net<=-1000*iStartLots && position.Ticket()==worst)
                              if(trade.PositionClosePartial(tk,NormalizeDouble(ltv-fmax(0.01,0.35*iStartLots),2),iSlippage)>0)
                                 continue;
                              else
                                 break;
                          }
                       }
                    }
                 }
               tk=position.Ticket();
               sw=position.Swap();
               pft=position.Profit();
               //               xcm=position.Commission()*2;
               net = pft-iMinimalProfit+sw;
               net+=((net>-xcm)?xcm:-iMinimalProfit);
               if(net>0 || no2close == 99)
                 {
                  if(trade.PositionClose(tk,iSlippage)>0)
                     continue;
                  else
                     break;
                 }
              }
           }
        }
     }
   osd_to_be_called = true;
  }
 

Note: The error occurs after the ea has already closed the trades successfully.
It does NOT happen all the time, however it does happen often.

Note 

trade.SetAsyncMode(true);

is placed in OnInit.

#include "PositionInfo.mqh"   CPositionInfo     position;
#include "TradeAlt.mqh"       CTradeAlt         trade;

are at near top of code.

 

Does it even close any positions? Or every time it tries to close a position it fails?


Maybe checking for the result of the MqlTradeResult member of CTrade may help to find the issue. If it only happens when live trading, try to print all open position tickets and compare them to the position ticket you're actually trying to close.

I also see you have 4 PositionClose statements. You need to figure out which one (if not all) is causing the problem, so we can be more assertive.


Also, where does total come from? Is it an array that you manage yourself or is it just a variable that stores the result of PositionsTotal()?


Its a weird error, tbh. PositionClose() and its variants actually call PositionSelect__ . I thought this function couldn't return true if the position doesn't exist, but I may be wrong.

 
Emanuel Cavalcante Amorim Filho #:

Does it even close any positions? Or every time it tries to close a position it fails?

As I said in previous comment: 

Note: The error occurs after the ea has already closed the trades successfully.

As per your suggestion, I have inserted Print statements after each PositionClose request. I will post results in few days or when I first notice the error happens again.

yes, total is just saving of PositionsTotal which I had saved on OnTick, and passed the result to the CloseTrades function.

I did a assume that it had something to do with the Asynchronous sending of the orders to the broker? Or no?

...and yeah -- I have not noticed it occur in any backtest; only in forward and live trading.

 

Excerpt from the log

OD 0 18:13:56.088 Trades '7017660': market buy 0.05 USDJPY, close #7491527 sell 0.05 USDJPY 153.208

JH 0 18:13:56.088 Trades '7017660': market buy 0.05 GBPJPY, close #7491524 sell 0.05 GBPJPY 197.176

PK 0 18:13:56.088 Trades '7017660': market buy 0.05 CADJPY, close #7491523 sell 0.05 CADJPY 110.851

MO 0 18:13:56.088 Trades '7017660': market buy 0.05 EURJPY, close #7491518 sell 0.05 EURJPY 166.338

ER 0 18:13:56.088 Trades '7017660': market buy 0.05 CHFJPY, close #7491478 sell 0.05 CHFJPY 173.674

NE 0 18:13:56.088 Trades '7017660': market buy 0.05 EURNZD, close #7483958 sell 0.05 EURNZD 1.84020

GI 0 18:13:56.088 Trades '7017660': market buy 0.05 GBPCAD, close #7483956 sell 0.05 GBPCAD 1.77724

RL 0 18:13:56.088 Trades '7017660': market buy 0.05 EURNZD, close #7483435 sell 0.05 EURNZD 1.84073

LO 0 18:13:56.088 Trades '7017660': market buy 0.05 GBPCAD, close #7483434 sell 0.05 GBPCAD 1.77786

IS 0 18:13:56.088 Trades '7017660': market buy 0.05 GBPAUD, close #7483341 sell 0.05 GBPAUD 1.96053

DF 0 18:13:56.088 Trades '7017660': market buy 0.05 GBPNZD, close #7482899 sell 0.05 GBPNZD 2.18261

JJ 0 18:13:56.088 Trades '7017660': market buy 0.05 GBPCAD, close #7482379 sell 0.05 GBPCAD 1.77767

LM 0 18:13:56.088 Trades '7017660': market buy 0.05 GBPCAD, close #7469636 sell 0.05 GBPCAD 1.77674

QP 0 18:13:56.088 Trades '7017660': market buy 0.05 GBPNZD, close #7469542 sell 0.05 GBPNZD 2.18406

HD 0 18:13:56.088 Trades '7017660': market buy 0.05 GBPCAD, close #7469541 sell 0.05 GBPCAD 1.77680

QG 0 18:13:56.088 Trades '7017660': market buy 0.05 GBPCAD, close #7469248 sell 0.05 GBPCAD 1.77670

DJ 0 18:13:56.088 Trades '7017660': market buy 0.05 GBPNZD, close #7469247 sell 0.05 GBPNZD 2.18379

FN 0 18:13:56.088 Trades '7017660': market buy 0.05 CADCHF, close #7468264 sell 0.05 CADCHF 0.63748

FQ 0 18:13:56.088 Trades '7017660': market buy 0.05 GBPNZD, close #7467990 sell 0.05 GBPNZD 2.18260

ME 0 18:13:56.088 Trades '7017660': market buy 0.05 GBPCAD, close #7467760 sell 0.05 GBPCAD 1.77639

GH 0 18:13:56.088 Trades '7017660': market buy 0.05 GBPCAD, close #7467637 sell 0.05 GBPCAD 1.77645

EK 0 18:13:56.088 Trades '7017660': market buy 0.05 GBPNZD, close #7463607 sell 0.05 GBPNZD 2.18152

QO 0 18:13:56.088 Trades '7017660': market buy 0.05 GBPNZD, close #7463202 sell 0.05 GBPNZD 2.18173

ER 0 18:13:56.088 Trades '7017660': market buy 0.05 USDCHF, close #7463110 sell 0.05 USDCHF 0.87896

CE 0 18:13:56.089 Trades '7017660': market buy 0.05 GBPNZD, close #7462828 sell 0.05 GBPNZD 2.18126

OI 0 18:13:56.089 Trades '7017660': market buy 0.05 USDJPY, close #7456119 sell 0.05 USDJPY 152.233

ML 0 18:13:56.130 Trades '7017660': market buy 0.05 USDJPY, close #7491527 sell 0.05 USDJPY 153.208

DP 0 18:13:56.130 Trades '7017660': market buy 0.05 GBPJPY, close #7491524 sell 0.05 GBPJPY 197.176

FS 0 18:13:56.130 Trades '7017660': market buy 0.05 CADJPY, close #7491523 sell 0.05 CADJPY 110.851

GF 0 18:13:56.130 Trades '7017660': market buy 0.05 EURJPY, close #7491518 sell 0.05 EURJPY 166.338

GJ 0 18:13:56.130 Trades '7017660': market buy 0.05 CHFJPY, close #7491478 sell 0.05 CHFJPY 173.674

PM 0 18:13:56.130 Trades '7017660': market buy 0.05 EURNZD, close #7483958 sell 0.05 EURNZD 1.84020

MP 0 18:13:56.130 Trades '7017660': market buy 0.05 GBPCAD, close #7483956 sell 0.05 GBPCAD 1.77724

DD 0 18:13:56.130 Trades '7017660': market buy 0.05 EURNZD, close #7483435 sell 0.05 EURNZD 1.84073

RG 0 18:13:56.130 Trades '7017660': market buy 0.05 GBPCAD, close #7483434 sell 0.05 GBPCAD 1.77786

CK 0 18:13:56.130 Trades '7017660': market buy 0.05 GBPAUD, close #7483341 sell 0.05 GBPAUD 1.96053

RN 0 18:13:56.130 Trades '7017660': market buy 0.05 GBPNZD, close #7482899 sell 0.05 GBPNZD 2.18261

LQ 0 18:13:56.130 Trades '7017660': market buy 0.05 GBPCAD, close #7482379 sell 0.05 GBPCAD 1.77767

RE 0 18:13:56.130 Trades '7017660': market buy 0.05 GBPCAD, close #7469636 sell 0.05 GBPCAD 1.77674

KH 0 18:13:56.130 Trades '7017660': market buy 0.05 GBPNZD, close #7469542 sell 0.05 GBPNZD 2.18406

NK 0 18:13:56.130 Trades '7017660': market buy 0.05 GBPCAD, close #7469541 sell 0.05 GBPCAD 1.77680

CO 0 18:13:56.130 Trades '7017660': market buy 0.05 GBPCAD, close #7469248 sell 0.05 GBPCAD 1.77670

JR 0 18:13:56.130 Trades '7017660': market buy 0.05 GBPNZD, close #7469247 sell 0.05 GBPNZD 2.18379

HF 0 18:13:56.130 Trades '7017660': market buy 0.05 CADCHF, close #7468264 sell 0.05 CADCHF 0.63748

PI 0 18:13:56.130 Trades '7017660': market buy 0.05 GBPNZD, close #7467990 sell 0.05 GBPNZD 2.18260

GL 0 18:13:56.130 Trades '7017660': market buy 0.05 GBPCAD, close #7467760 sell 0.05 GBPCAD 1.77639

EP 0 18:13:56.130 Trades '7017660': market buy 0.05 GBPCAD, close #7467637 sell 0.05 GBPCAD 1.77645

HS 0 18:13:56.131 Trades '7017660': market buy 0.05 GBPNZD, close #7463607 sell 0.05 GBPNZD 2.18152

DF 0 18:13:56.131 Trades '7017660': market buy 0.05 GBPNZD, close #7463202 sell 0.05 GBPNZD 2.18173

PJ 0 18:13:56.131 Trades '7017660': market buy 0.05 USDCHF, close #7463110 sell 0.05 USDCHF 0.87896

IM 0 18:13:56.131 Trades '7017660': market buy 0.05 GBPNZD, close #7462828 sell 0.05 GBPNZD 2.18126

MQ 0 18:13:56.131 Trades '7017660': market buy 0.05 USDJPY, close #7456119 sell 0.05 USDJPY 152.233

OF 0 18:13:56.238 Trades '7017660': accepted market buy 0.05 USDJPY, close #7491527 sell 0.05 USDJPY 153.208

DJ 0 18:13:56.240 Trades '7017660': deal #6347967 buy 0.05 USDJPY at 153.848 done (based on order #7492694)

JK 0 18:13:56.243 Trades '7017660': accepted market buy 0.05 GBPJPY, close #7491524 sell 0.05 GBPJPY 197.176

CK 0 18:13:56.243 Trades '7017660': order #7492694 buy 0.05 / 0.05 USDJPY at 153.848 done in 155.853 ms

PS 0 18:13:56.244 Trades '7017660': deal #6347968 buy 0.05 GBPJPY at 197.137 done (based on order #7492695)

PR 0 18:13:56.245 Trades '7017660': accepted market buy 0.05 CADJPY, close #7491523 sell 0.05 CADJPY 110.851

KS 0 18:13:56.245 Trades '7017660': order #7492695 buy 0.05 / 0.05 GBPJPY at 197.137 done in 157.371 ms

MI 0 18:13:56.246 Trades '7017660': deal #6347969 buy 0.05 CADJPY at 111.171 done (based on order #7492696)

PH 0 18:13:56.247 Trades '7017660': order #7492696 buy 0.05 / 0.05 CADJPY at 111.171 done in 159.408 ms

NH 0 18:13:56.248 Trades '7017660': accepted market buy 0.05 EURJPY, close #7491518 sell 0.05 EURJPY 166.338

HQ 0 18:13:56.250 Trades '7017660': deal #6347970 buy 0.05 EURJPY at 166.749 done (based on order #7492697)

NM 0 18:13:56.251 Trades '7017660': accepted market buy 0.05 CHFJPY, close #7491478 sell 0.05 CHFJPY 173.674

JQ 0 18:13:56.251 Trades '7017660': order #7492697 buy 0.05 / 0.05 EURJPY at 166.749 done in 163.369 ms

LH 0 18:13:56.252 Trades '7017660': deal #6347971 buy 0.05 CHFJPY at 173.786 done (based on order #7492698)

EE 0 18:13:56.253 Trades '7017660': accepted market buy 0.05 EURNZD, close #7483958 sell 0.05 EURNZD 1.84020

HD 0 18:13:56.253 Trades '7017660': deal #6347972 buy 0.05 EURNZD at 1.84378 done (based on order #7492699)

CK 0 18:13:56.254 Trades '7017660': order #7492698 buy 0.05 / 0.05 CHFJPY at 173.786 done in 165.977 ms

OL 0 18:13:56.254 Trades '7017660': accepted market buy 0.05 GBPCAD, close #7483956 sell 0.05 GBPCAD 1.77724

NQ 0 18:13:56.258 Trades '7017660': order #7492699 buy 0.05 / 0.05 EURNZD at 1.84378 done in 169.949 ms

FQ 0 18:13:56.258 Trades '7017660': accepted market buy 0.05 EURNZD, close #7483435 sell 0.05 EURNZD 1.84073

NH 0 18:13:56.261 Trades '7017660': deal #6347973 buy 0.05 GBPCAD at 1.77325 done (based on order #7492700)

NI 0 18:13:56.262 Trades '7017660': order #7492700 buy 0.05 / 0.05 GBPCAD at 1.77325 done in 173.857 ms

IF 0 18:13:56.263 Trades '7017660': deal #6347974 buy 0.05 EURNZD at 1.84378 done (based on order #7492701)

QO 0 18:13:56.264 Trades '7017660': accepted market buy 0.05 GBPCAD, close #7483434 sell 0.05 GBPCAD 1.77786

IN 0 18:13:56.265 Trades '7017660': order #7492701 buy 0.05 / 0.05 EURNZD at 1.84378 done in 176.810 ms

RO 0 18:13:56.265 Trades '7017660': deal #6347975 buy 0.05 GBPCAD at 1.77325 done (based on order #7492702)

CG 0 18:13:56.267 Trades '7017660': accepted market buy 0.05 GBPAUD, close #7483341 sell 0.05 GBPAUD 1.96053

KK 0 18:13:56.268 Trades '7017660': deal #6347976 buy 0.05 GBPAUD at 1.95811 done (based on order #7492703)

DH 0 18:13:56.268 Trades '7017660': order #7492702 buy 0.05 / 0.05 GBPCAD at 1.77325 done in 180.309 ms

FL 0 18:13:56.268 Trades '7017660': order #7492703 buy 0.05 / 0.05 GBPAUD at 1.95811 done in 180.386 ms

CO 0 18:13:56.269 Trades '7017660': market buy 0.05 GBPNZD, close #7482899 sell 0.05 GBPNZD 2.18261

IR 0 18:13:56.269 Trades '7017660': market buy 0.05 GBPCAD, close #7482379 sell 0.05 GBPCAD 1.77767

KF 0 18:13:56.270 Trades '7017660': market buy 0.05 GBPCAD, close #7469636 sell 0.05 GBPCAD 1.77674

RI 0 18:13:56.270 Trades '7017660': market buy 0.05 GBPNZD, close #7469542 sell 0.05 GBPNZD 2.18406

OL 0 18:13:56.270 Trades '7017660': market buy 0.05 GBPCAD, close #7469541 sell 0.05 GBPCAD 1.77680

JP 0 18:13:56.270 Trades '7017660': market buy 0.05 GBPCAD, close #7469248 sell 0.05 GBPCAD 1.77670

CS 0 18:13:56.270 Trades '7017660': market buy 0.05 GBPNZD, close #7469247 sell 0.05 GBPNZD 2.18379

EG 0 18:13:56.270 Trades '7017660': market buy 0.05 CADCHF, close #7468264 sell 0.05 CADCHF 0.63748

MJ 0 18:13:56.270 Trades '7017660': market buy 0.05 GBPNZD, close #7467990 sell 0.05 GBPNZD 2.18260

FM 0 18:13:56.270 Trades '7017660': market buy 0.05 GBPCAD, close #7467760 sell 0.05 GBPCAD 1.77639

HQ 0 18:13:56.270 Trades '7017660': market buy 0.05 GBPCAD, close #7467637 sell 0.05 GBPCAD 1.77645

FD 0 18:13:56.270 Trades '7017660': market buy 0.05 GBPNZD, close #7463607 sell 0.05 GBPNZD 2.18152

JG 0 18:13:56.270 Trades '7017660': market buy 0.05 GBPNZD, close #7463202 sell 0.05 GBPNZD 2.18173

NK 0 18:13:56.270 Trades '7017660': market buy 0.05 USDCHF, close #7463110 sell 0.05 USDCHF 0.87896

CN 0 18:13:56.270 Trades '7017660': market buy 0.05 GBPNZD, close #7462828 sell 0.05 GBPNZD 2.18126

OR 0 18:13:56.270 Trades '7017660': market buy 0.05 USDJPY, close #7456119 sell 0.05 USDJPY 152.233

EG 0 18:13:56.284 Trades '7017660': accepted market buy 0.05 GBPNZD, close #7482899 sell 0.05 GBPNZD 2.18261

EE 0 18:13:56.284 Trades '7017660': accepted market buy 0.05 GBPCAD, close #7482379 sell 0.05 GBPCAD 1.77767

DE 0 18:13:56.284 Trades '7017660': deal #6347977 buy 0.05 GBPNZD at 2.17969 done (based on order #7492704)

OL 0 18:13:56.285 Trades '7017660': order #7492704 buy 0.05 / 0.05 GBPNZD at 2.17969 done in 196.794 ms

QR 0 18:13:56.288 Trades '7017660': deal #6347978 buy 0.05 GBPCAD at 1.77325 done (based on order #7492705)

DP 0 18:13:56.290 Trades '7017660': order #7492705 buy 0.05 / 0.05 GBPCAD at 1.77325 done in 201.626 ms

DF 0 18:13:56.292 Trades '7017660': accepted market buy 0.05 GBPCAD, close #7469636 sell 0.05 GBPCAD 1.77674

DD 0 18:13:56.293 Trades '7017660': accepted market buy 0.05 GBPNZD, close #7469542 sell 0.05 GBPNZD 2.18406

CJ 0 18:13:56.293 Trades '7017660': accepted market buy 0.05 GBPCAD, close #7469541 sell 0.05 GBPCAD 1.77680

MI 0 18:13:56.294 Trades '7017660': accepted market buy 0.05 GBPCAD, close #7469248 sell 0.05 GBPCAD 1.77670

GP 0 18:13:56.295 Trades '7017660': deal #6347979 buy 0.05 GBPCAD at 1.77325 done (based on order #7492706)

JN 0 18:13:56.298 Trades '7017660': order #7492706 buy 0.05 / 0.05 GBPCAD at 1.77325 done in 209.838 ms

JP 0 18:13:56.298 Trades '7017660': accepted market buy 0.05 GBPNZD, close #7469247 sell 0.05 GBPNZD 2.18379

IH 0 18:13:56.301 Trades '7017660': deal #6347980 buy 0.05 GBPNZD at 2.17969 done (based on order #7492707)

JG 0 18:13:56.304 Trades '7017660': order #7492707 buy 0.05 / 0.05 GBPNZD at 2.17969 done in 216.067 ms

EG 0 18:13:56.306 Trades '7017660': deal #6347981 buy 0.05 GBPCAD at 1.77325 done (based on order #7492708)

MN 0 18:13:56.307 Trades '7017660': accepted market buy 0.05 CADCHF, close #7468264 sell 0.05 CADCHF 0.63748

IO 0 18:13:56.307 Trades '7017660': order #7492708 buy 0.05 / 0.05 GBPCAD at 1.77325 done in 218.812 ms

IS 0 18:13:56.307 Trades '7017660': accepted market buy 0.05 GBPNZD, close #7467990 sell 0.05 GBPNZD 2.18260

FN 0 18:13:56.309 Trades '7017660': deal #6347982 buy 0.05 GBPCAD at 1.77325 done (based on order #7492709)

DJ 0 18:13:56.309 Trades '7017660': deal #6347983 buy 0.05 GBPNZD at 2.17969 done (based on order #7492710)

PI 0 18:13:56.310 Trades '7017660': order #7492709 buy 0.05 / 0.05 GBPCAD at 1.77325 done in 221.957 ms

DI 0 18:13:56.310 Trades '7017660': accepted market buy 0.05 GBPCAD, close #7467760 sell 0.05 GBPCAD 1.77639

NM 0 18:13:56.312 Trades '7017660': order #7492710 buy 0.05 / 0.05 GBPNZD at 2.17969 done in 224.027 ms

KR 0 18:13:56.313 Trades '7017660': accepted market buy 0.05 GBPCAD, close #7467637 sell 0.05 GBPCAD 1.77645

GN 0 18:13:56.314 Trades '7017660': deal #6347984 buy 0.05 CADCHF at 0.63972 done (based on order #7492711)

PE 0 18:13:56.315 Trades '7017660': order #7492711 buy 0.05 / 0.05 CADCHF at 0.63972 done in 227.083 ms

MJ 0 18:13:56.315 Trades '7017660': accepted market buy 0.05 GBPNZD, close #7463607 sell 0.05 GBPNZD 2.18152

JF 0 18:13:56.318 Trades '7017660': deal #6347985 buy 0.05 GBPNZD at 2.17969 done (based on order #7492712)

HQ 0 18:13:56.320 Trades '7017660': deal #6347986 buy 0.05 GBPCAD at 1.77325 done (based on order #7492713)

DO 0 18:13:56.324 Trades '7017660': order #7492712 buy 0.05 / 0.05 GBPNZD at 2.17969 done in 235.745 ms

MS 0 18:13:56.324 Trades '7017660': order #7492713 buy 0.05 / 0.05 GBPCAD at 1.77325 done in 236.059 ms

JI 0 18:13:56.326 Trades '7017660': deal #6347987 buy 0.05 GBPCAD at 1.77325 done (based on order #7492714)

EK 0 18:13:56.326 Trades '7017660': deal #6347988 buy 0.05 GBPNZD at 2.17969 done (based on order #7492715)

JH 0 18:13:56.327 Trades '7017660': order #7492714 buy 0.05 / 0.05 GBPCAD at 1.77325 done in 238.375 ms

PL 0 18:13:56.327 Trades '7017660': order #7492715 buy 0.05 / 0.05 GBPNZD at 2.17969 done in 238.584 ms

EM 0 18:13:56.328 Trades '7017660': accepted market buy 0.05 GBPNZD, close #7463202 sell 0.05 GBPNZD 2.18173

LM 0 18:13:56.330 Trades '7017660': deal #6347989 buy 0.05 GBPNZD at 2.17969 done (based on order #7492716)

DD 0 18:13:56.331 Trades '7017660': order #7492716 buy 0.05 / 0.05 GBPNZD at 2.17969 done in 242.172 ms

JD 0 18:13:56.332 Trades '7017660': accepted market buy 0.05 USDCHF, close #7463110 sell 0.05 USDCHF 0.87896

RK 0 18:13:56.333 Trades '7017660': accepted market buy 0.05 GBPNZD, close #7462828 sell 0.05 GBPNZD 2.18126

PI 0 18:13:56.333 Trades '7017660': accepted market buy 0.05 USDJPY, close #7456119 sell 0.05 USDJPY 152.233

DQ 0 18:13:56.337 Trades '7017660': deal #6347990 buy 0.05 USDCHF at 0.88529 done (based on order #7492717)

PP 0 18:13:56.338 Trades '7017660': order #7492717 buy 0.05 / 0.05 USDCHF at 0.88529 done in 249.094 ms

GR 2 18:13:56.338 Trades '7017660': failed market buy 0.05 USDJPY [Position doesn't exist]

NK 0 18:13:56.339 Trades '7017660': deal #6347991 buy 0.05 GBPNZD at 2.17969 done (based on order #7492718)

IE 0 18:13:56.339 Trades '7017660': deal #6347992 buy 0.05 USDJPY at 153.848 done (based on order #7492719)

JL 0 18:13:56.341 Trades '7017660': order #7492718 buy 0.05 / 0.05 GBPNZD at 2.17969 done in 252.495 ms

LO 0 18:13:56.341 Trades '7017660': order #7492719 buy 0.05 / 0.05 USDJPY at 153.848 done in 252.505 ms

PP 2 18:13:56.341 Trades '7017660': failed market buy 0.05 GBPJPY [Position doesn't exist]

HF 2 18:13:56.342 Trades '7017660': failed market buy 0.05 CADJPY [Position doesn't exist]

LJ 2 18:13:56.342 Trades '7017660': failed market buy 0.05 EURJPY [Position doesn't exist]

RO 2 18:13:56.343 Trades '7017660': failed market buy 0.05 CHFJPY [Position doesn't exist]

NR 2 18:13:56.343 Trades '7017660': failed market buy 0.05 EURNZD [Position doesn't exist]

HI 2 18:13:56.344 Trades '7017660': failed market buy 0.05 GBPCAD [Position doesn't exist]

OM 2 18:13:56.344 Trades '7017660': failed market buy 0.05 EURNZD [Position doesn't exist]

GP 2 18:13:56.345 Trades '7017660': failed market buy 0.05 GBPCAD [Position doesn't exist]

ME 2 18:13:56.345 Trades '7017660': failed market buy 0.05 GBPAUD [Position doesn't exist]

DJ 2 18:13:56.346 Trades '7017660': failed market buy 0.05 GBPNZD [Position doesn't exist]

RO 2 18:13:56.346 Trades '7017660': failed market buy 0.05 GBPCAD [Position doesn't exist]

IR 2 18:13:56.347 Trades '7017660': failed market buy 0.05 GBPCAD [Position doesn't exist]

KG 2 18:13:56.347 Trades '7017660': failed market buy 0.05 GBPNZD [Position doesn't exist]

IM 2 18:13:56.347 Trades '7017660': failed market buy 0.05 GBPCAD [Position doesn't exist]

QQ 2 18:13:56.347 Trades '7017660': failed market buy 0.05 GBPCAD [Position doesn't exist]

RE 2 18:13:56.348 Trades '7017660': failed market buy 0.05 GBPNZD [Position doesn't exist]

KI 2 18:13:56.349 Trades '7017660': failed market buy 0.05 CADCHF [Position doesn't exist]

IN 2 18:13:56.350 Trades '7017660': failed market buy 0.05 GBPNZD [Position doesn't exist]

LS 2 18:13:56.351 Trades '7017660': failed market buy 0.05 GBPCAD [Position doesn't exist]

EF 2 18:13:56.352 Trades '7017660': failed market buy 0.05 GBPCAD [Position doesn't exist]

PK 2 18:13:56.353 Trades '7017660': failed market buy 0.05 GBPNZD [Position doesn't exist]

EP 2 18:13:56.354 Trades '7017660': failed market buy 0.05 GBPNZD [Position doesn't exist]

CD 2 18:13:56.354 Trades '7017660': failed market buy 0.05 USDCHF [Position doesn't exist]

FI 2 18:13:56.355 Trades '7017660': failed market buy 0.05 GBPNZD [Position doesn't exist]

RM 2 18:13:56.355 Trades '7017660': failed market buy 0.05 USDJPY [Position doesn't exist]

HR 2 18:13:56.410 Trades '7017660': failed market buy 0.05 GBPNZD [Position doesn't exist]

NG 2 18:13:56.410 Trades '7017660': failed market buy 0.05 GBPCAD [Position doesn't exist]

EJ 2 18:13:56.411 Trades '7017660': failed market buy 0.05 GBPCAD [Position doesn't exist]

HO 2 18:13:56.418 Trades '7017660': failed market buy 0.05 GBPNZD [Position doesn't exist]

NE 2 18:13:56.418 Trades '7017660': failed market buy 0.05 GBPCAD [Position doesn't exist]

EI 2 18:13:56.419 Trades '7017660': failed market buy 0.05 GBPCAD [Position doesn't exist]

OM 2 18:13:56.419 Trades '7017660': failed market buy 0.05 GBPNZD [Position doesn't exist]

CQ 2 18:13:56.420 Trades '7017660': failed market buy 0.05 CADCHF [Position doesn't exist]

RF 2 18:13:56.429 Trades '7017660': failed market buy 0.05 GBPNZD [Position doesn't exist]

DK 2 18:13:56.429 Trades '7017660': failed market buy 0.05 GBPCAD [Position doesn't exist]

DN 2 18:13:56.430 Trades '7017660': failed market buy 0.05 GBPCAD [Position doesn't exist]

RS 2 18:13:56.430 Trades '7017660': failed market buy 0.05 GBPNZD [Position doesn't exist]

EH 2 18:13:56.442 Trades '7017660': failed market buy 0.05 GBPNZD [Position doesn't exist]

CL 2 18:13:56.442 Trades '7017660': failed market buy 0.05 USDCHF [Position doesn't exist]

FQ 2 18:13:56.443 Trades '7017660': failed market buy 0.05 GBPNZD [Position doesn't exist]

RE 2 18:13:56.443 Trades '7017660': failed market buy 0.05 USDJPY [Position doesn't exist]

 
... ALL of the trades closed.
 
Michael Charles Schefe:

I have issue where I am getting the error [Position Doesn't Exist]
Below is my function that closes trades. Note: I am using this ea to close trades on many symbols. I have not added check for Symbols, because I want the ea to manage all trades; that were opened by other eas and on other charts, symbols.
I will appreciate the answer, however, I will appreciate, even more, for document source to look up, for myself. But as yet, I think that I had tried everything, but this issue keeps propping up. Maybe it is not avoidable?

You have this code in a loop where tk is unchanged.

                           if(trade.PositionClose(tk,iSlippage)>0)
                              continue;
                           else
                              break;

You probably should reverse the "continue" and the "break".

 

change made. I will report back towards end of the week if no more errors; sooner if the change is unsuccessful.

Either way, thanks for the assist.

 
reordering of continue and break has had effect of not closing the full group of trades. But you both have given me ideas.