Incrementing problems

 

Hello everybody,

i have a real problem which is blocking the progression of my EA.
In the following part of code, i'm trying to develop an EA, which increment the lot losses and when the first win come ,  these losses will be the amount of the next trade 
but  it seems there is a probleme with the incrementation of losses (stop at 1 incrementation) and when the first win is hit  , i get an error of invalid lots amount and (in the same time the loss=0).

Thanks by advance.

double WIN,LOSS;
double Lots_i; // initial lot

int h=OrdersHistoryTotal();
if (h==0 ) {Lots=Lots_i;}
else 
{  
 OrderSelect(h, SELECT_BY_TICKET, MODE_HISTORY);
 

        if  (OrderProfit() > 0) 
            {
             WIN++ ;
             if (WIN==1)  
            {   if (OrderLots()==LOSS)
                { 
                 Lots=OrderLots(); 
                 DIRECTION=DIRECTION;
                }
               else if (OrderLots()!=LOSS)
                { if (h==1)   // case: if the first trade is a win 
                     {
                     Lots=Lots_i;
                     DIRECTION=DIRECTION;
                     }
                  else
                     {
                     Lots=LOSS;
                     LOSS=0; 
                     DIRECTION=DIRECTION;
                     }
                }
             }
             else if (WIN==2)
             {
                Lots=Lots_i;
                LOSS=0; 
                DIRECTION=DIRECTION;  
             }
             }
           else if (OrderProfit() < 0)
           {
           LOSS+=OrderLots();   
           WIN=0;
           Lots=OrderLots();
           if (DIRECTION==OP_BUY)
              {
               DIRECTION=OP_SELL;
              }
              else
              {
              DIRECTION=OP_BUY;
              }
           }
                    
 }
 
  1. int h=OrdersHistoryTotal();
    if (h==0 ) {Lots=Lots_i;}
    else 
    {  
     OrderSelect(h, SELECT_BY_TICKET, MODE_HISTORY);
    h is a count, like 0, 1, 2... But then you use in in OrderSelect as a Ticket number. Won't work
  2. Even if you used it as a position number, still won't work as valid positions are 0 .. OrdersHistoryTotal-1 inclusive. There is no position number OrdersHistoryTotal.
  3. What are Function return values ? How do I use them ? - MQL4 forum
  4.            if (WIN==1)  
                {   if (OrderLots()==LOSS)
    
    WIN and LOSS are initially zero. If the last order is a win, then how can OrderLots() == 0 ever?
  5. if (OrderLots()==LOSS){ ... }
    else // if (OrderLots()!=LOSS)
    {
    When the first If fails the second if must be true. No need to check.
  6. it seems there is a probleme with the incrementation of losses (stop at 1 incrementation)
    Of course. You only process one history order, no loop, there will be only one incrementation.
  7. What's the purpose of?
                    DIRECTION=DIRECTION;
 

1&2:

i tried many combinaison to get the right "h"(order history) despite the presence of a lag, because for the first trade there is not a valid history information.

4: it's not like this (or it's not my aim), loss is a counter of the lots that i loose, so loss must be different of 0. and in this special case : if the order after the first win is a loss then "loss" is incementing, so then i check thanks this condition.

5. you're right !!

6. i tried too, with a loop, but the difficulty is how i'll get the limt of the loop, because the aim is to count the losses and stop when i'll get 2 consecutive wins !!??

7. it's not used now, but it's will be useto get the direction (sell or buy) calculated by an indicator for example.

Thanks !!