Check trade

 
Hello

i looking to find a code that check the order history. if in the order historiy to the reference time of the last day an order, dont take a new one
there is something wrong with the code

     for (cnt=0;cnt<OrdersTotal();cnt++){
      OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY);
      if(OrderComment()==Text ){
         
         if(Hour() >= 00 && Hour() < 7  && (Ask >= Kauf || Bid <= Verkauf) ){
         
           if (OrderOpenTime() <= (  TimeCurrent()  - (Hour()*60*60 + 7*60*60 + 11*60*60) )  ) SetOrders(Text,MagicNumber);
           }
           
           if(Hour() >= 7           && (Ask >= Kauf || Bid <= Verkauf) ){
         
           if (OrderOpenTime() <= (  TimeCurrent - ( Hour() *60*60 - 7*60*60 + 1*60*60) ) ) SetOrders(Text,MagicNumber);

         }
         
        }
      }     
 

i use as reference time 7 am. this means, if in the last our to the last 7am an old order dont set a new one. i like to select it with the order comment.
the only reason that there is an order is, one order get a stoploss
 
  1. U should use OrdersHistoryTotal() and not OrdersTotal() to get the number of orders in the history pool.
  2. Order comments are partially overwritten by the server sometimes (especially when they are closed). It's potentially dangerous to use OrderComment() to identify trades; magic number is much more reliable.
  3. You should test if OrderSelect() was successful (check it's return).
  4. Note that your expert will only see the history that has been filtered by the user in 'Account History' tab (if the user sets it to "Last Month", then those are the only orders the expert would see...).
Reason: