Close Orders on MT4

 

I have created a trading system that is used on relatively short time frames (1M, 5M) for scalping. The problem I have having is the buy and sell indicators are based on current OHLC data. As the currency crosses the buy/sell indicators for trading, it might fluctuate before it finally breaks out. The fluctuation at that point causes numerous trades to be opened and close before the final trade is triggered. Is there a way to force the EA to hold the first buy or sell trade as the lines cross for a set period of time before it triggers the closing trade?


Thanks in advance.

 
if (XXX && YYY)
   {
   Sleep(1000*2*60); //sleep for 2 minutes
   OrderSend(......);
   }
u can do something like this
 
  1. u can do something like this
    If you sleep, you MUST RefreshRates()
  2. static datetime lastChange;
    if (TimeCurrent() > lastChange +2 *60){
       ...
       int ticket = OrderSend(...);
       if (ticket < 0) Alert("OrderSend failed: ", GetLastError();
       else            lastChange = TimeCurrent();
    }