mql loop for cent accout max trading lot

 
Hi Everyone,

Due to my trading account is cent one, the max trading volume is 100lots.

If my trading lot is over 100, then EA need to separate into few orders.

I am trying to write a do-while statement, but it seems I could not get correct spare trading lots.

Please refer my codes below, and kindly give me some feedback,

Thank you so much.


extern int maxlots=100; //Maximum order volume (lots)

void martket_order_loop(int tradingtype,double tradinglots,string tradingcmts)
{
         if(tradinglots<=maxlots)
         {
            //for long
            if(tradingtype==0)
            {
               //long@market price
               ticket_buy_1=OrderSend(Symbol(),OP_BUY,lots,Ask,3,0,0,tradingcmts,magicno,0,Blue);                    
            }
         } 
         else
         {
            int county=0,sumlot=0; //counts,total trading lots
            do
            {
               //count+1
               county++;
               //total trading lots ideally
               sumlot=sumlot+maxlots*county;
              
               //
               if(sumlot<=lots)
               {
                  //thislot=maxlots;
                  //
                     //
                     if(tradingtype==0)
                     {
                        ticket_buy_1=OrderSend(Symbol(),OP_BUY,maxlots,Ask,3,0,0,tradingcmts,magicno,0,Blue); 
                     }
                                         
               }
               else //**************************************my problem is what below
               {
                  //thislot=lots-maxlots*(county-1);   
                  //                     
                     if(tradingtype==0)
                     {
                        ticket_buy_1=OrderSend(Symbol(),OP_BUY,lots-maxlots*(county-1),Ask,3,0,0,tradingcmts,magicno,0,Blue);                          
                     }  
               }               
            }
            while(sumlot<=tradinglots);
         }
}
 

Your loop is very complicated (besides some other variable naming issues). You have tradinglots as a parameter but use *lots* as a (global) variable.

Also not tested, this is might be more straightforwarded:

void martket_order_loop(int tradingtype,double tradinglots,string tradingcmts)
  {
   bool done=false;
   do
     {
      double tradelots=maxlots;
      if(tradinglots<=maxlots) 
        {
         tradelots=tradinglots;
         done=true;
        }
      tradinglots-=tradelots;
      if(tradingtype==0)
        {
         ticket_buy_1=OrderSend(Symbol(),OP_BUY,tradelots,Ask,3,0,0,tradingcmts,magicno,0,Blue);
        }
     }
   while(!done);

  }
Reason: