# Help with setting a timer on trades?

So I made this simple exponential and simple moving average expert advisor nothing crazy but I'm having trouble with giving a timer for every trade it enters whether it be long or short it updates the trailing stop loss every 20 minutes can someone help or at least provided some resource that can help?

```void OnTick()
{

string signal = "";

double SlowMovingAverage = iMA(NULL,0,5,0,MODE_SMA,PRICE_CLOSE,0);

double LastSlowMovingAverage = iMA(NULL,0,5,0,MODE_SMA,PRICE_CLOSE,1);

double FastMovingAverage = iMA(NULL,0,3,0,MODE_EMA,PRICE_CLOSE,0);

double LastFastMovingAverage = iMA(NULL,0,3,0,MODE_EMA,PRICE_CLOSE,1);

if ((LastFastMovingAverage < LastSlowMovingAverage)&&(FastMovingAverage > SlowMovingAverage))
{
}

//we count all the orders
for (int b=OrdersTotal()-1;b>=0;b--)
{
//we select one of the orders
//we check if the order belongs to the current chart
if (OrderSymbol()==Symbol())
//if it is a buy order
{
//if the stop loss is below 150 points
if (OrderStopLoss() < Ask - (1000* _Point))
//we modify the stop loss
OrderModify(
OrderTicket(),  //for current order
OrderOpenPrice(),  //opened for the openprice
Ask - (1000* _Point),  //set stop loss
OrderTakeProfit(),  //unchanged take profit
0,                  // no experiation
CLR_NONE             //no color
);
}

}

if ((LastFastMovingAverage > LastSlowMovingAverage)&&(FastMovingAverage < SlowMovingAverage))
{
signal = "Sell";
}
//we count all the orders
if(signal=="Sell" && OrdersTotal()==0)
int sellTicket = OrderSend(Symbol(),OP_SELL,3,Bid,3,0,0,NULL,0,0,Red);
for (int s=OrdersTotal()-1;s>=0;s--)
{
//we select one of the orders
//we check if the order belongs to the current chart
if (OrderSymbol()==Symbol())
//if it is a buy order
if (OrderType()==OP_SELL)
{
//if the stop loss is below 150 points
if (OrderStopLoss()==0 || OrderStopLoss() > Bid + (1000* _Point))
//we modify the stop loss
OrderModify(
OrderTicket(),  //for current order
OrderOpenPrice(),  //opened for the openprice
Bid + (1000* _Point),  //set stop loss
OrderTakeProfit(),  //unchanged take profit
0,                  // no experiation
CLR_NONE             //no color
);
}

}
}

```

So I made this simple exponential and simple moving average expert advisor nothing crazy but I'm having trouble with giving a timer for every trade it enters whether it be long or short it updates the trailing stop loss every 20 minutes can someone help or at least provided some resource that can help?

Here is a simple example of how you can create a delay - in this case 3 secs. You could adjust this so it executes every 20 mins and apply it to your code where you need it

```//+------------------------------------------------------------------+
//|                                             429041-Timedelay.mq5 |
//|                                  Copyright 2022, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property version   "1.00"
//
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+

#define  delayInSecs 3
datetime nextActionTime = 0;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
{

if(nextActionTime <= TimeCurrent())
{
nextActionTime = TimeCurrent() + delayInSecs;
}

}
//+------------------------------------------------------------------+
```

R4tna C #:

Here is a simple example of how you can create a delay - in this case 3 secs. You could adjust this so it executes every 20 mins and apply it to your code where you need it

that totally worked dude appreciate the help thanks much appreciated