lot increase

 

Hi all,

I want to give every order that is opening a lot size bigger than the last one. For that I try to use the following code to get it.

The issue is that the orders are not getting to open, but if I use FixedLotSize directly  (without lot increase) is ok.

Could anyone show me where I'm wrong ?

extern bool DynamicLotSize      = false;
extern double PercentageToTrade =   1;
extern double Multiplier        =  1.5;
extern double FixedLotSize      = 0.01;

 

    if(DynamicLotSize == true)
      {
        RiskAmount = AccountBalance() * (PercentageToTrade / 100000);     
        LotSize = RiskAmount;
      }
    else LotSize = FixedLotSize;
   
      {
        lotmin = MarketInfo(Symbol(),MODE_MINLOT);
        lotmax = MarketInfo(Symbol(),MODE_MAXLOT);
        lotstep = MarketInfo(Symbol(),MODE_LOTSTEP);
                         
       if(LotSize < lotmin)
        LotSize = lotmin;
       if(LotSize > lotmax)
        LotSize = lotmax;       
        
       for(Orders = 0; Orders < OrdersTotal()-1; Orders++)
         {
         if(OrderSelect(Orders,SELECT_BY_POS,MODE_TRADES)
           && OrderSymbol()== Symbol()&& OrderMagicNumber()== MagicNumber)
         { 
           lastlot = OrderLots();
        if(mlots <= OrderLots())mlots = NormalizeDouble(OrderLots() * Multiplier,2);
        else mlots=LotSize;  
       }
      }                               
    }                

 

Thank you in advance for any help provided

Luis

 
luisneves:

Hi all,

I want to give every order that is opening a lot size bigger than the last one. For that I try to use the following code to get it.

The issue is that the orders are not getting to open, but if I use FixedLotSize directly  (without lot increase) is ok.

Could anyone show me where I'm wrong ? 

What error do you get from the error reporting on your OrderSend() ?  please show the entry from the log . . .  

 

Haven't we discussed this before ?

https://www.mql5.com/en/forum/143292 

 
RaptorUK:

What error do you get from the error reporting on your OrderSend() ?  please show the entry from the log . . .  

 

Haven't we discussed this before ?

https://www.mql5.com/en/forum/143292 

 


Hi RaptorUK,

Thank you to keep attention for my issues.

The error that receive from Journal  is OrderSend error 4051, but seems that I'm using the same kind of code as before 

Anyway I've update the code as follow, but the error is the same (what an idiot I am...)

   {
       lotmin = MarketInfo(Symbol(),MODE_MINLOT);
       lotmax = MarketInfo(Symbol(),MODE_MAXLOT);
       lotstep = MarketInfo(Symbol(),MODE_LOTSTEP);
                         
       if(LotSize < lotmin)
        LotSize = lotmin;
       if(LotSize > lotmax)
        LotSize = lotmax;  
      LotSize = MathFloor(LotSize / lotstep) * lotstep;  
      
              
      for(Orders = 0; Orders < OrdersTotal()-1; Orders++)
        {
        if(OrderSelect(Orders,SELECT_BY_POS,MODE_TRADES)
           && OrderSymbol()== Symbol()&& OrderMagicNumber()== MagicNumber)
          { 
           lastlot = OrderLots();
        if(mlots <= OrderLots())mlots = NormalizeDouble(OrderLots() * Multiplier,2);
        else mlots = LotSize;  
          }
        }                               
    }        

 Luis

 
luisneves:


Hi RaptorUK,

Thank you to keep attention for my issues.

The error that receive from Journal  is OrderSend error 4051, but seems that I'm using the same kind of code as before 

Anyway I've update the code as follow, but the error is the same (what an idiot I am...)

 Luis

Look at your code,  follow the value of LotSize from line to line . . .  you do this . . 

       if(LotSize < lotmin)
        LotSize = lotmin;
       if(LotSize > lotmax)
        LotSize = lotmax;  
      LotSize = MathFloor(LotSize / lotstep) * lotstep;  

 and then this . . . 

           lastlot = OrderLots();
        if(mlots <= OrderLots())mlots = NormalizeDouble(OrderLots() * Multiplier,2);
        else mlots = LotSize;  

 so if  mlots  is greater than OrderLots() you use a value that may not be a multiple of LotStep.

Why don't you add this . . .

mlots = MathFloor(mlots / lotstep) * lotstep; 
 
RaptorUK:

Look at your code,  follow the value of LotSize from line to line . . .  you do this . . 

 and then this . . . 

 so if  mlots  is greater than OrderLots() you use a value that may not be a multiple of LotStep.

Why don't you add this . . .

 


Good Morning RaptorUK,

I've update the code to get that every order that  is opening have its lot increase buy the Multiplier factor.

While you try to show me what I need to change to get that the truth is I still a little confused (just not to say totally...) and now the orders are opening but can't get the lot increase as expected.

Of course that something is wrong but can't find where.

 Here is the code that I have now;

 

{
       lotmin = MarketInfo(Symbol(),MODE_MINLOT);
       lotmax = MarketInfo(Symbol(),MODE_MAXLOT);
       lotstep = MarketInfo(Symbol(),MODE_LOTSTEP);
       margin = MarketInfo(Symbol(),MODE_MARGINREQUIRED);
       
       if(LotSize * margin > AccountFreeMargin())
          LotSize = AccountFreeMargin()/margin;
          
       mlots = MathFloor(LotSize/lotstep) * lotstep;
                                
       if(mlots < lotmin)
          mlots = lotmin;
       if(mlots > lotmax)
          mlots = lotmax;  
                           
       for(Orders = 0; Orders < OrdersTotal()-1; Orders++)
        {
         if(OrderSelect(Orders,SELECT_BY_POS,MODE_TRADES)
            && OrderSymbol() == Symbol() 
            && OrderMagicNumber()== MagicNumber)
           { 
            lastlot = OrderLots();
         if(mlots <= lastlot)mlots = MathFloor(lastlot/lotstep)* lotstep * Multiplier;
       else mlots = MathFloor(LotSize/lotstep) * lotstep;  
           }
        }                                    
     }

Taking the risk of start to be a little boring could I ask  more of your patience to help me deal with this issue ?

Thank you in davance for support provided

Luis, 

 
luisneves:


Of course that something is wrong


// for(Orders = 0; Orders < OrdersTotal()-1; Orders++)
// Why don't you count down checking OrdersTotal( )
// like


for(int i = OrdersTotal()-1; i >= 0 ; i--)  
// if(mlots <= lastlot)mlots = MathFloor(lastlot/lotstep)* lotstep * Multiplier;

 if(mlots <= lastlot)mlots = MathFloor((lastlot*Multiplier)/lotstep)* lotstep; 




{
       lotmin = MarketInfo(Symbol(),MODE_MINLOT);
       lotmax = MarketInfo(Symbol(),MODE_MAXLOT);
       lotstep = MarketInfo(Symbol(),MODE_LOTSTEP);
       margin = MarketInfo(Symbol(),MODE_MARGINREQUIRED);
       
       if(LotSize * margin > AccountFreeMargin())
          LotSize = AccountFreeMargin()/margin;
          
       mlots = MathFloor(LotSize/lotstep) * lotstep;
                                
/*       if(mlots < lotmin)
          mlots = lotmin;
       if(mlots > lotmax)
          mlots = lotmax;  */
                           
     for(int i = OrdersTotal()-1; i >= 0 ; i--)   
        {
         if(OrderSelect(Orders,SELECT_BY_POS,MODE_TRADES)
            && OrderSymbol() == Symbol() 
            && OrderMagicNumber()== MagicNumber)
           { 
            lastlot = OrderLots();
         if(mlots <= lastlot)mlots = MathFloor((lastlot*Multiplier)/lotstep)* lotstep; 
   //    else mlots = MathFloor(LotSize/lotstep) * lotstep; //  ?????
 
           }
        } 
      if(mlots < lotmin)
          mlots = lotmin;
       if(mlots > lotmax)
          mlots = lotmax;  
                                   
     }

Why    if mlots > lastlot 

mlots = MathFloor(LotSize/lotstep) * lotstep;

 





 
deVries:



Good morning deVries,

Thank you to keep attention to my issue.

My apologies to keep bore you with my incompetence  dealing with mql. I've introduced your revised code in the block as shown below, but seems that the problem subsist.

 

{
       lotmin = MarketInfo(Symbol(),MODE_MINLOT);
       lotmax = MarketInfo(Symbol(),MODE_MAXLOT);
       lotstep = MarketInfo(Symbol(),MODE_LOTSTEP);
       margin = MarketInfo(Symbol(),MODE_MARGINREQUIRED);
       
       if(LotSize * margin > AccountFreeMargin())
          LotSize = AccountFreeMargin()/margin;
          
       mlots = MathFloor(LotSize/lotstep) * lotstep;
                                
         
       for(Orders = OrdersTotal()-1; Orders >= 0 ; Orders--)                      
       //for(Orders = 0; Orders < OrdersTotal()-1; Orders++)
        {
         if(OrderSelect(Orders,SELECT_BY_POS,MODE_TRADES)
            && OrderSymbol() == Symbol() 
            && OrderMagicNumber()== MagicNumber)
           { 
            lastlot = OrderLots();
        // if(mlots <= lastlot)mlots = MathFloor((lastlot*Multiplier)/lotstep)* lotstep; 
            mlots = MathFloor((lastlot*Multiplier)/lotstep)* lotstep; 
      // else mlots = MathFloor(LotSize/lotstep) * lotstep;  
           }
        } 
      if(mlots < lotmin)
          mlots = lotmin;
       if(mlots > lotmax)
          mlots = lotmax;                                           
     }
                   

 

And now I thing where the problem could be.

What I mean is that the kind of orders that need to open are pending orders could this be a problem using this kind of code?

Thank you in advance

Luis 

 
luisneves:


Good morning deVries,

Thank you to keep attention to my issue.

My apologies to keep bore you with my incompetence  dealing with mql. I've introduced your revised code in the block as shown below, but seems that the problem subsist.

 

 

And now I thing where the problem could be.

What I mean is that the kind of orders that need to open are pending orders could this be a problem using this kind of code?

Thank you in advance

Luis 

if(mlots <= lastlot)mlots = MathFloor((lastlot*Multiplier)/lotstep)* lotstep; 

why do you remove   condition

if(mlots <= lastlot)
 
deVries:

why do you remove   condition






Hi deVries,

The reason is that I'm an idiot (just can be...).

But now is there. I was confused with Why   " if mlots > lastlot". 

Luis 

 

Hi RaptorUK,

I saw in one  of your topics under the issue of dealing with doubles where you say you convert doubles to int and then work from there. Is that possible to get from you a better clarification about this ?

Thank you in advance

Luis 

 
luisneves:

Hi RaptorUK,

I saw in one  of your topics under the issue of dealing with doubles where you say you convert doubles to int and then work from there. Is that possible to get from you a better clarification about this ?

Thank you in advance

Luis 

Did you look at the code I posted and did you understand it ?  if you haven't seen it do a search . . .