about for()

To add comments, please log in or register
Boripath Boonrit
31
Boripath Boonrit  
want  value "TimeOpenFirstOrder" to use
how to fix


int TimeOpenFirstOrder;
      for(int k=0;k<=OrdersHistoryTotal();k++)
      {
         if(OrderSelect(k,SELECT_BY_POS,MODE_HISTORY))
         {
            if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
            {
            
               if(OrderType()==OP_BUY ||OrderType()==OP_SELL ) 
                        {
                           if(OrderComment()=="onebuystop1" ||OrderComment()=="onesellstop1")
                              {
                                TimeOpenFirstOrder=TimeDayOfYear(OrderOpenTime());        /////////if have Order ... TimeOpenFirstOrder is ....
                               }
                        }
                if(OrdersHistoryTotal()==0)       //////if have not close order
                {
                TimeOpenFirstOrder=0;            /////// TimeOpenFirstOrder=0
                } 
                    
      Print("TimeOpenFirstOrder=",TimeOpenFirstOrder); 

////want  value "TimeOpenFirstOrder" to use down
                         
            for(int i=0;i<= (TimeDayOfYear( TimeCurrent() ) - TimeOpenFirstOrder );i++)
    
               {              

               }
}
Juvenille Emperor Limited
Moderator
10220
Eleni Anna Branou  

Please use the </> button to insert your above code.


William Roeder
20210
William Roeder  
  1. When you post code please use the CODE button (Alt-S)! (For large amounts of code, attach it.) Please edit your (original) post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. for(int k=0;k<=OrdersHistoryTotal();k++)
    If there are n entries their position is [0 .. n-1]. Drop the equal sign.

  3.  if(OrderComment()=="onebuystop1" ||OrderComment()=="onesellstop1")     
    Not a good idea to use comments, brokers can change comments, including complete replacement.

  4. if(OrdersHistoryTotal()==0)       //////if have not close order
                    {
                    TimeOpenFirstOrder=0;            /////// TimeOpenFirstOrder=0
                    } 
    This code will never run. If the total is zero, the for loop exits immediately. Initialize your variable when declared.
To add comments, please log in or register