Pause between trades.

 

Hey Guys.

I wrote an expert and have only one problem. He makes 100 trades in few minutes and loose all the money. I want to make a 15min/1h. break after every closed trade.

So i wrote:

 if(OrdersHistoryTotal()>0)
   {
     for(int a=0;a<OrdersHistoryTotal();a++)
     { 
      if(OrderSelect(a,SELECT_BY_POS,MODE_HISTORY))
            {
               if(TimeCurrent()-OrderCloseTime()<3600) // 15 min. or 1hour, doesnt matter
               {
                  return(0);
               }
            } 
      }
   }     

 It does not work, my expert still makes hundreds of trades on the same candle in the past...He makes no pause between trades... why ?

 
lawbreaker13: why ?
  1. Because it is broken somewhere else. Put Print statements (including variable values) and track it down. Start with just before the return and after the loop. You'll see why quick enough.
  2. The IF(history) is unnecessary. If there's no history the loop does nothing.
  3. Get in the habit of always counting down.
  4. That code make the EA incompatible with every other including itself on other charts and manual trading - no MN.
 
lawbreaker13:

Hey Guys.

I wrote an expert and have only one problem. He makes 100 trades in few minutes and loose all the money. I want to make a 15min/1h. break after every closed trade.

So i wrote:

 It does not work, my expert still makes hundreds of trades on the same candle in the past...He makes no pause between trades... why ?


It does work but you forget that if there is a open trade and there is after the first new opend it opens a new one because the last closed is still older then the 15min/1h. break .  you also have to check the open trades before you open a new one....
Reason: