Progressive lot size issue

 

Hello,

English isn't my native language, but I'll try to get by..

I'm a little bit new to mql4, but have been trying to get everything going, I was testing an idea, then I needed to test a progressive lot size, my EA opens one trade at a time, so I wanted to check if the previous closed trades hit tp or not, if they hit take profit, then I start the next trade using 1 lot. If the closed trades didn't hit take profit target I increase the lot of the next trade by a pre-defined lot step.

I got it going, but sometimes the EA doesn't increase the lot size, it repeats the lot size for the next trade, but increase it in the following trade.

I'm a little bit furious because I can't find where is the issue.

I coded 2 functions, the 1st one to count the closed losses and the other function to calculate the lotsize based on the count of those closed trades.

Note: lot, lotstep and progressivelot are extern variables

Help would be much appreciated.

Thank you all!

int PrevClosed()
{
  int count=0;
  
  
  for(int i=OrdersHistoryTotal()-1; i>=0; i--)
     {
       if(!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
         continue;
       if(OrderSymbol()==Symbol()&& OrderMagicNumber()==magic)
       if((OrderType()==OP_BUY) || (OrderType()==OP_SELL))  
         {
          if(OrderTakeProfit()!=OrderClosePrice())
            {
              count++;
            }
         }
     } 
     Print(count);   
 return(count);
}  
//////////////////////////
double LotSize()
{
  double lots;
   
  if(progressivelot==true)
    {
       lots=lot+(prevclosed*lotstep);

    }
   else
     {
       lots=lot;

     }
   Print(lots);

     
 return(lots);
} 
Basic Principles - Trading Operations - MetaTrader 5
Basic Principles - Trading Operations - MetaTrader 5
  • www.metatrader5.com
is an instruction given to a broker to buy or sell a financial instrument. There are two main types of orders: Market and Pending. In addition, there are special Take Profit and Stop Loss levels. is the commercial exchange (buying or selling) of a financial security. Buying is executed at the demand price (Ask), and Sell is performed at the...