Please i Need help i want to code a delay waiting seconds

 
 let me say after lastclosedorder wait 15 seconds before open new trade

so let me say a sell order and a but order is open

when sell hit take profit wait for 15Seconds before open another sell order

please i need this delay seconds, thanks

the code below was handed to me by my teacher but after using this code it screwed up my code and made it to be opening double sells which is not supposed to be so the waiting seconds is only after a sell order closes and an active buy is on after 15 seconds new sells open again, so after adding the waiting seconds and the for loop my code wait for the seconds but now opens same trade for example if a buy is on after 15 seconds another buy opens instead of sell please help me i don't know what's wrong

/+------------------------------------------------------------------+
//|                                                     DMF Real.mq4 |
//|                 Copyright 2021, ITace Inc. (Marve)Software Corp. |
//|                                             https://www.ITace.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, ITace Inc. (Marve)Software Corp."
#property link      "https://www.ITace.com"
#property version   "1.00"
#property strict
input string TradingBetween = "16:00-23:59";
input double SL= 100;
input double TP= 50;
input double TND= 50;
input double LotSize= 1.6;
input double SLS= 12;
input double SSL=12;
input double STP=12;
input double CLS=1;
input double CTP=5;
input double CSL=5;
input double ElapsedSECONDS = 1*60;
int OnInit()
{
   int AccountLists_AcceptData[];
   int number_of_accounts = 3;
   ArrayResize(AccountLists_AcceptData, number_of_accounts);
   AccountLists_AcceptData[0] = 47807636; 
   AccountLists_AcceptData[1] = 2200659; 
   AccountLists_AcceptData[2] = 47809298;
   
   bool isAccountNumberOK = false;
   for (int i = 0; i < number_of_accounts; i++)
   {
      if (AccountNumber() == AccountLists_AcceptData[i])
      {
         isAccountNumberOK = true;
         break;
      }
   }

   if (!isAccountNumberOK)
   {
      Print("License is not authorized! Contact Itace Inc. (Marve)");
      return(INIT_FAILED);
   }
   else
   {
      return(INIT_SUCCEEDED);
   }
}
void OnTick()
  {
   bool validTime = isValidTime2Trade(TradingBetween);
   double ask = MarketInfo(Symbol(), MODE_ASK),bid = MarketInfo(Symbol(), MODE_BID);
   double iHi = iHigh(Symbol(), PERIOD_M1, 0);
   double iLo = iLow(Symbol(), PERIOD_M1, 0);
   bool SEL_condition =  ask<iHi+TND;
   bool BUY_condition = ask<iHi+TND;
   int ticket0, ticket1,OrdrTotal = OrdersTotal();
   if(OrdrTotal==0 && validTime==true && SEL_condition==true)
     {
      ticket0=OrderSend(Symbol(),OP_SELL, LotSize, NormalizeDouble(bid,Digits),0,NormalizeDouble(bid+SL,Digits),NormalizeDouble(bid-TP,Digits),"Order0",1000,0,clrRed);
     }
   else
      {
         //Print(" waiting4Order1... ElapsSec:",ElapsSec);
      }
      
   if(OrdrTotal==0 && validTime==true && BUY_condition==true)
     {
      ticket0=OrderSend(Symbol(),OP_BUY,SLS, NormalizeDouble(ask,Digits),0,NormalizeDouble(ask-SSL,Digits),NormalizeDouble(ask+STP,Digits),"Order0",2000,0,clrGreen);
     }
    else
         {
               //Print(" waiting4Order1... ElapsSec:",ElapsSec);
         }
   if(OrdrTotal==1 && OrderSelect(SELECT_BY_POS,MODE_TRADES))
     {
      if(OrderMagicNumber()==2000 && OrderSymbol()==_Symbol)
        {
         long ElapsSec = MathMin(MinOrdOpElaps(_Symbol),MinOrdClElaps(_Symbol));
         bool LastClosedByLoss = LastOrdClosedByLoss(_Symbol);
         if(LastClosedByLoss)Print("LastClosedByLoss!!!");
         if((OrderType()==OP_BUY) && validTime==true)
           {
            if(ElapsSec>ElapsedSECONDS)
              {
               Print(" OrderSend... "," ElapsSec:",ElapsSec,"  ElapsedSECONDS:",ElapsedSECONDS);
               ticket1=OrderSend(_Symbol,OP_SELL,CLS, NormalizeDouble(bid,Digits),0,NormalizeDouble(bid+CSL,Digits),NormalizeDouble(bid-CTP,Digits),"Order1",2000,0,clrRed);
              }
             }
            else
             {
               if(OrderMagicNumber()==1000 && OrderSymbol()==_Symbol)
              {
                 if((OrderType()==OP_SELL) && validTime==true)
                {
                  if(ElapsSec>ElapsedSECONDS)
                    {
               Print(" OrderSend... "," ElapsSec:",ElapsSec,"  ElapsedSECONDS:",ElapsedSECONDS);
               ticket1=OrderSend(_Symbol,OP_BUY,CLS, NormalizeDouble(ask,Digits),1,NormalizeDouble(ask-CSL,Digits),NormalizeDouble(ask+CTP,Digits),"Order1",2000,0,clrGreen);
                   }
                }
               }
             }
            }
          }
      }
//+------------------------------------------------------------------+ //this line was handed to me for the waiting seconds
long MinOrdOpElaps(string symb)
  {
   long dif=1e+16;
   for(int o=0; o<OrdersTotal(); o++)
     {
      if(OrderSelect(o,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==symb)
           {
            if(TimeCurrent()-OrderOpenTime()<dif)
               dif=TimeCurrent()-OrderOpenTime();
           }
        }
     }
   return(dif);
  }
//+------------------------------------------------------------------+
long MinOrdClElaps(string symb)
  {
   long dif=1e+16;
   int o = OrdersHistoryTotal(),a = OrdersHistoryTotal() - 10,b = OrdersHistoryTotal();
   for(o = a; o < b ; o++)
     {
      if(OrderSelect(o,SELECT_BY_POS,MODE_HISTORY))
        {
         if(OrderSymbol()==symb)
           {
            if(TimeCurrent()-OrderOpenTime() <dif)
               dif=TimeCurrent()-OrderOpenTime();
            if(TimeCurrent()-OrderCloseTime()<dif)
               dif=TimeCurrent()-OrderCloseTime();
           }
        }
     }
   return(dif);
  }
//+------------------------------------------------------------------+
bool LastOrdClosedByLoss(string symb)
  {
   bool ClosedByLoss=false;
   static datetime lastOrderCloseTime;
   int o = OrdersHistoryTotal(),a = OrdersHistoryTotal() - 10,b = OrdersHistoryTotal();
   for(o = a; o < b ; o++)
     {
      if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))
        {
         if(OrderSymbol()==symb &&  OrderCloseTime()> lastOrderCloseTime)
           {
            lastOrderCloseTime = OrderCloseTime();
            ClosedByLoss = MathAbs(OrderClosePrice()-OrderStopLoss())  < MathAbs(OrderClosePrice()-OrderTakeProfit()) ;
           }
        }
     }
   return(ClosedByLoss);
 
Well, you need to find the close time of your TP.

Multiple Options available.

One would be: OnTrade ().

Then you add 15 to the close time and compare it with TimeCurrent ()

Et voila.
 
Marvelous Agbor:

THis is the last time that you will be warned about posting multiple times about the same subject.

Next time you will be banned.

I have deleted some of your other posts.

Post your code or nobody can help you.

link

This is the general section, but your other posts have been in the MQL4 section. So what are you using, MQL4 or 5?

Set a delay timer between trades
Set a delay timer between trades
  • 2011.01.25
  • www.mql5.com
Im wondering if its possible to set a delay timer between trades...
 
Keith Watford:

THis is the last time that you will be warned about posting multiple times about the same subject.

Next time you will be banned.

I have deleted some of your other posts.

Post your code or nobody can help you.

link

This is the general section, but your other posts have been in the MQL4 section. So what are you using, MQL4 or 5?

Oh my bad i'm just not used to this platform even how to navigate around thanks for the hint

i make use of mql4 i don't  know is there any where i can specify my platform before posting or where can i find mql4 section? thanks

 
Dominik Egert:
Well, you need to find the close time of your TP.

Multiple Options available.

One would be: OnTrade ().

Then you add 15 to the close time and compare it with TimeCurrent ()

Et voila.
thanks bro
 
Marvelous Agbor:

Oh my bad i'm just not used to this platform even how to navigate around thanks for the hint

i make use of mql4 i don't  know is there any where i can specify my platform before posting or where can i find mql4 section? thanks

Click on Forum at the top of the page and then you will see the sections.

I will move this topic to the correct section now.

 
Marvelous Agbor: i make use of mql4 i don't  know is there any where i can specify my platform before posting or where can i find mql4 section? thanks

The forum is divided into sections. It is the last one of the list:

  • General
  • Trading Systems
  • Trading stocks, futures, options and other exchange instruments
  • Expert Advisors and Automated Trading
  • Technical Indicators
  • Articles, Library comments
  • MQL4 and MetaTrader 4
 
Fernando Carreiro:

The forum is divided into sections. It is the last one of the list:

  • General
  • Trading Systems
  • Trading stocks, futures, options and other exchange instruments
  • Expert Advisors and Automated Trading
  • Technical Indicators
  • Articles, Library comments
  • MQL4 and MetaTrader 4
ok thanks is done
Reason: