Why have my positions Closed?

 

I feel weird asking this question.. but somehow I have an EA (Mt5) which seems to 'lose' trades. I've been trying to find a problem for the last few days and not getting any nearer.  It's almost as if there is an EA deleting trades!

I created the small routine below which just checks the positions I have for the current Symbol. If use a different location according where the routine is inserted.

The 'Report_StringError' function - prints the details to file if "Both" and reports Trapped Errors. If I use "Error" then it only traps errors.


I have placed this routine in several places and just find a Position no longer listed (in the next use of the routine) with no obvious 'rogue' code between two occurrences. Other positions for other Symbols are  present PositionsTotal() was 1 less than previous (before I commented out)

No Errors found.


I don't examine any 'DEALS' - just positions.


My EA the detects PositionsCurrent = 0 then generates a new Order which can then happen every other click (SL / TP wouldn't take effect if set). Many trades all opened / closed in same MINUTE

I run another EA which reports / summary of 6 other charts - but doesn't delete orders

Any suggestions appreciated.

Any statements to maybe clear something / reset etc



[Apologies for spelling of- just noticed]

CheckRemaingTickets
//==============================CheckRemaingTickets START==============================+
void CheckRemaingTickets(string location)
{  // for test purposes only
   //Report_StringError("Both","777776 CRT CheckRemaingTickets from "+location+" PositionsTotal() = "+IntegerToString(PositionsTotal()));
   ulong TempPositionsCurrent = 0;
   string thispairhere = "FALSE";
   for ( int i = PositionsTotal() - 1; i >= 0; i--)
   {  if ( myposition.SelectByIndex(i) == true ) 
      {  thispairhere = "FALSE";
         ulong CRTTicket   = PositionGetTicket(i);                                        // MySymbol = PositionGetString(POSITION_SYMBOL);
         double CRTProfit = PositionGetDouble(POSITION_PROFIT);
         if (PositionGetSymbol(i) == _Symbol)
         {  TempPositionsCurrent++;
            thispairhere = "TRUE";
            string st777777 ="CheckRemaingTickets from "+location+", CRTTicket = "+IntegerToString(CRTTicket)+" Symbol = "+PositionGetSymbol(i)+" CRTProfit = "+DoubleToString(CRTProfit,2)+" TempPositionsCurrent = "+IntegerToString(TempPositionsCurrent);
            Report_StringError("Both","777777 CRT "+st777777+" <<< "+thispairhere);
         }
      }
   }
   return;
}
//===============================CheckRemaingTickets END===============================+
Documentation on MQL5: Integration / MetaTrader for Python / order_calc_margin
Documentation on MQL5: Integration / MetaTrader for Python / order_calc_margin
  • www.mql5.com
order_calc_margin - MetaTrader for Python - Integration - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

I noticed this post

"After placeing an order you should program an 10 second delay. once all your orders have been placed you should verify that in fact they were executed before releaseing the account for other EAs to use".


https://www.mql5.com/en/forum/174825#comment_4266035

I am never aware of timing issues before but could this be an issue? Is 10 seconds an overkill?

Any EA's that OPEN/CLOSE more than 1position?
Any EA's that OPEN/CLOSE more than 1position?
  • 2006.08.10
  • www.mql5.com
I'm just looking for an example of an EA that opens and closes more than 1 position at a time.. THANKS...
 
Without commands for closing every OP (Open Position) can only be closed if the price touches the TP or SL value.

In the function that you display above, there are no instructions that can make the OP can be closed, so it can be ascertained the cause of closing is the TP or SL value.
Check on TP and SL on your OP.
 
Nino Guevara Ruwano #:
Without commands for closing every OP (Open Position) can only be closed if the price touches the TP or SL value.

In the function that you display above, there are no instructions that can make the OP can be closed, so it can be ascertained the cause of closing is the TP or SL value.
Check on TP and SL on your OP.
If the EA makes use of trailing stop (hedging) that mechanism overtakes the regular TP in case price leaps forward past the trailing stop distance. Once trailing stop begins to 'trail' the rising price then a common situation to occur is that the Trailing stop value has been set rather small and fast price jitter back/forth exceeds that range so price quickly backs down past the stop value, thus closing the order "prematurely". This can mean not reaching a profit otherwise assured by the regular TP setting or the intended trailing distance. So for a particular currency pair if you use trailing stop (a k a hedging mode) it is good to study the price fluctuation behavior when trading gets intense and make sure to set some trailing stop margin to not be 'stopped out' inadvertantly.
Reason: