Problem with retrieving first row with my code

 

Hi,


my code works correctly, but problem is if I have first row 1, not working. All other rows works, only this row not possible to get.


Please help thanks!


static bool first = true;
    static int pre_OrdersTotal = 0;
    int _OrdersTotal = OrdersTotal();
 
    // If this is the first launch of the Expert, we don't know the amount of orders on the previous tick.
    // So just remeber it, mark that the first launch has been happened, and exit.
    if ( first )
    {
        pre_OrdersTotal = _OrdersTotal;
        first = false;
        //return(0);
    }
 
    // Compare the amount of positions on the previous tick with the current amount
    // If it has been changed, display message
    if ( _OrdersTotal > pre_OrdersTotal ) 
    insertTrade();
       // Alert( "The amount of positions increased! There were - ", pre_OrdersTotal, 
                                                   //      ", there are now - ", _OrdersTotal );
 
    if ( _OrdersTotal < pre_OrdersTotal)
    { 
    deleteTrade();
    
    }
    
       // Alert( "The amount of positions decreased! There were - ", pre_OrdersTotal, 
       //                                                  ", there are now - ", _OrdersTotal );
 
    // Memorize the amount of positions
    pre_OrdersTotal = _OrdersTotal;
    
     }
 
    Dejan Krapez: if I have first row 1, not working. All other rows works, only this row not possible to get.
  1. The word “row” makes no sense. Use the automatic translation tool if needed. Use simple language structure when using mechanical translation. (2013)

  2. If you call insertTrade or deleteTrade they change OrdersTotal, but you store the previous value, not the updated value.

  3. Magic number only allows an EA to identify its trades from all others. Using OrdersTotal/OrdersHistoryTotal (MT4) or PositionsTotal (MT5), directly and/or no Magic number/symbol filtering on your OrderSelect / Position select loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
              Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 programming forum (2013)
              PositionClose is not working - MQL5 programming forum (2020.02.21)
              MagicNumber: "Magic" Identifier of the Order - MQL4 Articles (2006)
              Orders, Positions and Deals in MetaTrader 5 - MQL5 Articles 2011

    You need one Magic Number for each symbol/timeframe/strategy. Trade current timeframe, one strategy, and filter by symbol requires one MN.