Help Please (sleep or alternative)

 

Hello all, thank you in advance I am having a whole lot of trouble adding a sleep command or delay in my EA between time the last position was closed until the next one is opened. I am very inexperienced at MQL4 but have taken advantage of the many resources here and all over the net about coding this function. I am simply trying to create a delay between the time a trade closes until the next one is opened approx 8-12 hours. I understand the Milliseconds in the sleep command and the conversion of such but I cannot get in in the correct place in my EA. I have seen several articles about pausing between trades for back testing instead of using the sleep command and have tried these to no avail. So I have spent about 40 hours scouring the web for an answer and figured maybe one of you good folks could at least point me in the correct direction. I really do not care if it back tests correctly as my strategy live is sound just need the EA the mimic what i would do live, which is step back for a few hours after a good or bad play. If anyone could supply me with a code snippet or reference that may help you would have my eternal gratitude. thanks all!

Shawn

 

C

> ..I really do not care if it back tests correctly as my strategy live is sound..

Outstanding!

See if this snippet helps

int MinutesBetweenTrades = 240;

static datetime sdtNextTradeTime;

init()
{

  sdtNextTradeTime = Time[1]; // or lookup and set to close time of last trade

  return (0);
}

start()
{
    if (TimeCurrent() < sdtNextTradeTime) return (0); // Quit if too early to trade

    //===============================================
    
      // Open logic....

    //===============================================

     // Close logic....


     // when order closed
     
     sdtNextTradeTime = TimeCurrent() + (MinutesBetweenTrades * 60);



return (0);
}

FWIW

-BB-

 
int MinutesBetweenTrades = 240;
int start(){
    static datetime lastClose;
    if (TimeCurrent() < lastClose + MinutesBetweenTrades * 60) return(0);
    for(int pos=0; pos < OrdersHistoryTotal(); pos++) if (
        OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY)   // Only orders w/
    &&  OrderCloseTime()    > lastClose                 // not yet processed,
    &&  OrderMagicNumber()  == magic.number             // my magic number
    &&  OrderSymbol()       == Symbol()                 // and my pair.
    &&  OrderType()         <= OP_SELL){    // Avoid cr/bal forum.mql4.com/32363
        lastClose = OrderCloseTime();
    }
    ...
}
 
Just wanted to drop back in and say thanks so much for the help! I finally got it in the correct place and it seems to be working as intended!
Reason: