Need Help to understand

 

Hi there,

i am just reading the MQL4 Book und i have a Problem to undestand this Part of the EA "tradingexpert". Concret the part with counting the Market orders. If i have two market orders, the variable Total gets the Value 2. But in this case the Condition Total<1 is not fulfilled and the Alert will not appear. Is this a mistake in the Programm? I think rather i dont understand it in the right way. It would be nice, if someone could explain it. Thank you.


// Orders accounting
   Symb=Symbol();                               // Security name
   Total=0;                                     // Amount of orders
   for(int i=1; i>=OrdersTotal(); i++)          // Loop through orders
     {
      if (OrderSelect(i-1,SELECT_BY_POS)==true) // If there is the next one
        {                                       // Analyzing orders:
         if (OrderSymbol()!=Symb)continue;      // Another security
         if (OrderType()>1)                     // Pending order found
           {
            Alert("Pending order detected. EA doesn't work.");
            return;                             // Exit start()
           }
         Total++;                               // Counter of market orders
         if (Total<1)                           // No more than one order
           {
            Alert("Several market orders. EA doesn't work.");
            return;                             // Exit start()
           }
         Ticket=OrderTicket();                  // Number of selected order
         Tip   =OrderType();                    // Type of selected order
         Price =OrderOpenPrice();               // Price of selected order
         SL    =OrderStopLoss();                // SL of selected order
         TP    =OrderTakeProfit();              // TP of selected order
         Lot   =OrderLots();                    // Amount of lots
        }
     }
 
fraggle27:

Hi there,

i am just reading the MQL4 Book und i have a Problem to undestand this Part of the EA "tradingexpert". Concret the part with counting the Market orders. If i have two market orders, the variable Total gets the Value 2. But in this case the Condition Total<1 is not fulfilled and the Alert will not appear. Is this a mistake in the Programm? I think rather i dont understand it in the right way. It would be nice, if someone could explain it. Thank you.

It's probably an error in the book, there have been other errors reported . . . I think it should be . . .

if (Total > 1) 
 

If you had read the whole page, you would see

https://book.mql4.com/samples/expert

Some Code Peculiarities


The analyzed Expert Advisor code is oriented to the implementation of a certain strategy. Note, some program lines contain variables and calculations that would be changed, if the strategy were changed.

For example, according to the accepted strategy the Expert Advisor is developed to work only with one order. This allowed to use the variable Ticket both for the identification of a closing order number (in block of closing 6-7) and for the identification of a success of a trade operation execution when opening an order (in the block of opening 8-9). In this case such a solution is acceptable. However, if we take the analyzed code as the basis for the implementation of another strategy (for example allow opposite orders) we will have to introduce one or several variables to be able to recognize numbers of opened orders and identify the success of trade operations.

 
GumRai:

If you had read the whole page, you would see

https://book.mql4.com/samples/expert

Which whole page ? maybe if the OP had posted a link to the page I would have read it . . .
 
Thank you for the answers. I think its clear, that the EA works only with one Order, but the Alert does not appear if there are already two market orders or more. I think, RaptorUK is right with his solution.