Increase Order after stoploss

 
Hi, i created an ea that increments the order volume after it has stopped and resets from the initial value after taking the take profit.I have to say it works, but sometimes (especially if I get more charts) goes crazy and returns to the value of initial multiplication without taking the takeprofit. because? I need your help

 please


 double Raddoppio()
   {
   int it=OrdersHistoryTotal()-1;
   //----
   OrderSelect(it,SELECT_BY_POS,MODE_HISTORY);
      {                                           
      OL = OrderLots();       


  if (   ordinemagico() && ordprofiz() )
         {
            Lots = NormalizeDouble(OL*2,3); 
              
                              
            }
         else
            {
            Lots=Lots2 ;
            }
         if ( ordprofutente() ) { raddoppiato=Lots2; }                  
         
      }
      return (Lots);
   }

bool ordprofutente() {

   if (OrderProfit() >0 &&  OrderLots() > Lots) {return (true);}
   else {return (false);  }
}

bool ordinemagico() {

   if (OrderMagicNumber() == MagicNumber && OrderSymbol() == _Symbol) {return (true);}
   else {return (false);  }
}

bool ordprofiz() {

   if (OrderProfit() < 0 &&  OrderLots() < NormalizeDouble(Lots*2,3)) {return (true);}
   else {return (false);  }
}

i use it in OnTick() for get the result multiplied or reset on: int Lots, Ordersend reads it (sell for example )

 ticket = OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,Ask+StopLoss*point,Bid-TakeProfit*point,commentosell,MagicNumber,0,clrRed);


 
  1.    int it=OrdersHistoryTotal()-1;
       //----
       OrderSelect(it,SELECT_BY_POS,MODE_HISTORY);
          {                                           
          OL = OrderLots();      
    
    Using OrdersHistoryTotal directly and/or no Magic number filtering on your OrderSelect 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 forum
  2. You assume history is ordered by date, it's not. Could EA Really Live By Order_History Alone? (ubzen) - MQL4 forum
  3. Your code
       if (OrderProfit() >0 &&  OrderLots() > Lots) {return (true);}
       else {return (false);  }
    
    Generic
       if (             true                      ) {return (true);}
       else {return (false);  }
    
    Equivalent
       if (          condition                    ) return (condition);
    
    Simplify your code
       return OrderProfit() >0 &&  OrderLots() > Lots;

 
whroeder1:
  1. Using OrdersHistoryTotal directly and/or no Magic number filtering on your OrderSelect 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 forum
  2. You assume history is ordered by date, it's not. Could EA Really Live By Order_History Alone? (ubzen) - MQL4 forum
  3. Your code
    Generic
    Equivalent
    Simplify your code


Thank you for answer

i modified the EA

 
 double Raddoppio()
   {
   
   int it=OrdersHistoryTotal()-1;
      OL = OrderLots(); 
   //----
   OrderSelect(it,SELECT_BY_POS,MODE_HISTORY);
      {                                           
         
  if (   ordinemagico() && ordprofiz() )
         {
            Lots = NormalizeDouble(OL*2,3); 
              
                              
            }
         else
            {
            Lots=Lots2 ;
            }
         if ( ordprofutente() ) { raddoppiato=Lots2; }                  
         
      }
      return (Lots);
   }

bool ordprofutente() {

   return OrderProfit() >0 &&  OrderLots() > Lots;
  
}

bool ordinemagico() {

  return OrderMagicNumber() == MagicNumber && OrderSymbol() == Symbol();
  
}

bool ordprofiz() {

  return OrderProfit() < 0 &&  OrderLots() < NormalizeDouble(Lots*2,3); 

}

now is right?

I think I still have the same mistakes. History should be set in Closing Date order? From top to bottom or vice versa? Sorry so much but really is a bad problem. thank you in advance

 

Giovanni Guastella:

now is right?

I think I still have the same mistakes.

History should be set in Closing Date order?


  1. no. #1.1 and #1.2
  2. yes. #1.1 and #1.2
  3. No such thing.
 
whroeder1:

  1. no. #1.1 and #1.2
  2. yes. #1.1 and #1.2
  3. No such thing.


Sorry, but I read it over and over again, but I can not understand what I should do. Please, if you can easily explain the level I have

Thank you

 
Giovanni Guastella: , but I read it over and over again, but I can not understand what I should do.
   int it=OrdersHistoryTotal()-1;
      OL = OrderLots(); 
   //----
   OrderSelect(it,SELECT_BY_POS,MODE_HISTORY);
  1. You select anything in history. Could be anything from any chart (a closed order, or a deleted pending order,) a balance/credit/deposit/withdrawal adjustment. Since history is not ordered by date, could be anything. Don't you want the last closed order for the current EA on the current chart? I pointed you to two links. You need to find only closed orders for the current EA on the current chart and of those, find the last one. There is no "should do," there is only a must do: learn to code it, or pay (Freelance) someone to code it. We're not going to code it for you (although it could happen if you are lucky or the problem is interesting.) We are willing to help you when you post your attempt (using SRC) and the nature of your problem.
  2. You can not use any Trade Functions until you select an order.
  3. What if it is the first time and there is no previous orders? Check your return codes What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles