I want my code to make one trade and then stop for two hours

 

I want a code that stop placing orders for x of time after place one in mql4.


void OnTick()

  {

//---


   if (OrdersTotal() < 1)

   {

      if(emafast(0) > emaslow(0)&& emafast(10) > emaslow(10)  && emafast(0) > emafast(5)) //&& emafast(1) > emafast(2))

      {

         if(histogram(0)<-0.0001 ||histogram(1)<-0.0001 ||histogram(2)<-0.0001 ||histogram(3)<-0.0001 ||histogram(3)<-0.0001 )//||histogram(5)<-0.0001 ||histogram(6)<-0.0001 || histogram(7)<-0.0001 )//||histogram(8)<-0.0001 ||histogram(9)<-0.0001 ||histogram(10)<-0.0001 ||histogram(11)<-0.0001)

         {

            if(macd()>= signal())

            {

               if(ema20(0)>ema50(0) && ema20(1)<ema50(1))

               {

                  if(OrderSend(NULL,0,1,Ask,10,Ask - 0.0006 ,0.0020 + Ask,NULL,0,0))

                  {

                     Sleep(14400000);

                  }

               }

            }

         }

      }

      

      

      if(emafast(0) < emaslow(0)&& emafast(10) < emaslow(10) && emafast(0) < emafast(5) )//&& emafast(1) < emafast(2))

      {

         if(histogram(0)>0.0001 ||histogram(1)>0.0001 ||histogram(2)>0.0001 ||histogram(3)>0.0001 ||histogram(3)>0.0001 )//||histogram(5)>0.0001 ||histogram(6)>0.0001||histogram(7)>0.0001 )//||histogram(8)>0.0001 ||histogram(9)>0.0001 ||histogram(10)>0.0001 ||histogram(11)>0.0001)

         {

            if(macd()<= signal())

            {

               if(ema20(0)<ema50(0) && ema20(1)>ema50(1))

               {

                  if (OrderSend(NULL,1,1,Ask,10,0.0006 + Ask,Ask - 0.0020,NULL,0,0))

                  {

                     Sleep(14400000);

                  }

               }

            }

         }

      }

   }

   

  }




as shown I tried sleep function but it does not work on backtesting. it there another way to do it ?

 
I have not yet had to use such a step-by-step, I can not help you with anything
 
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  2.                   if (OrderSend(NULL,1,1,Ask,10,0.0006 + Ask,Ask - 0.0020,NULL,0,0))

    OrderSend does not return a boolean.

  3. You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit and open at the Ask.

    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close to a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)
      Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY shows average spread = 26 points, but average maximum spread = 134 (your broker will be similar).

  4. static datetime disabled=0;
    datetime now=TimeCurrent(); if(now < disabled) return;
    if(OrderSend(…)>0){ disabled=now + 2*3600; …

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

  2. OrderSend does not return a boolean.

  3. You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit and open at the Ask.

    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close to a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)
      Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY shows average spread = 26 points, but average maximum spread = 134 (your broker will be similar).


 
Good