MT4. How to make a graphical object appear after a certain a period of time at the right coordinates relatitve to price and time?

 

Hello everyone.

I'm creating a simple indicator that draws an arrow when the price hits upper or lower Bollinger Band and then another arrow JUST AFTER A COUPLE OF MINUTES (let it be 2 mintes) at the current Time and Price coordinates.

Right now I'm trying to make it work with EA template with 1 include file through Sleep() function (idicator template does not pay attention to Sleep() (or it does but i cant get it yet))

Code of <include.mqh>:

#property copyright "Copyright 2022, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property strict
int bbPeriod = 20;
int bbStdDiv = 1;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void ArrowUp(double price)
  {
   ObjectCreate("ArrowUP", OBJ_ARROW_UP, 0, TimeCurrent(), price);
   ObjectSet("ArrowUP", OBJPROP_COLOR, clrYellow);
   ObjectSet("ArrowUP", OBJPROP_WIDTH, 2);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void ArrowDown(double price)
  {
   ObjectCreate("ArrowDown", OBJ_ARROW_DOWN, 0, TimeCurrent(), price);
   ObjectSet("ArrowDown", OBJPROP_COLOR, clrYellow);
   ObjectSet("ArrowDown", OBJPROP_WIDTH, 2);
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
double bbLowerBand = iBands(NULL, 0, bbPeriod, bbStdDiv, 0, PRICE_CLOSE, MODE_LOWER, 0);
double bbUpperBand = iBands(NULL, 0, bbPeriod, bbStdDiv, 0, PRICE_CLOSE, MODE_UPPER, 0);
double bbMidBand = iBands(NULL, 0, bbPeriod, bbStdDiv, 0, PRICE_CLOSE, MODE_MAIN, 0);

Code of the EA:

#property copyright "Copyright 2022, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#include <BBArrowsEA_include.mqh>
//Sleep(60000); - minute
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   Alert("");
   Alert("EA started");

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   Alert("");
   Alert("EA stopped");
   ObjectsDeleteAll();
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   double priceBid = Bid;


   if(Bid < bbLowerBand)
     {
      ArrowUp(Bid);
      Alert("1st obj created waitng");
      Sleep(120000);

      ArrowDown(priceBid);
      Alert("2nd obj created");

     }
   else
      if(Bid > bbUpperBand)
        {
         Alert("1st obj created waitng");
         ArrowDown(Bid);
         Sleep(120000);

         ArrowUp(priceBid);
         Alert("2nd obj created");

        }/**/
  }


The PROBLEM is that the second arrow is appearing at the right time but the price is wrong.It stays the same as the first arrow.(screenshot)

At first I thought that once the functions are executed they remember the bid price at the time of execution and just used them.

So I declated a new vairable that is expected to take the newest Bid price (which is updated every tick) and pass it into the second arrow function.

void OnTick()
  {
//---
   double priceBid = Bid;


   if(Bid < bbLowerBand)
     {
      ArrowUp(Bid);
      Alert("1st obj created waitng");
      Sleep(120000);
      Alert("2nd obj created");
      ArrowDown(priceBid);
      

     }
   else
      if(Bid > bbUpperBand)
        {
         Alert("1st obj created waitng");
         ArrowDown(Bid);
         Sleep(120000);

         ArrowUp(priceBid);
         Alert("2nd obj created");

        }/**/
  }

But for some reason it just wont budge.

I tried tinkering with creating arrows in different functions but that didnt work.

I tied to put the Ask price for the second arrow and it did in fact changed the price position but relative to the Ask OF THE FIRST ARROW. Not the current one.

I'm sure it has the simplest solution but i dont see it

Files:
 
tseby: I'm creating a simple indicator … and then another arrow JUST AFTER A COUPLE OF MINUTES
  1. Indicators can not sleep.
  2. Remember the current datetime. When a new tick arrives, and it is two minutes since, draw the new arrow.
 
William Roeder #:
  1. Indicators can not sleep.
  2. Remember the current datetime. When a new tick arrives, and it is two minutes since, draw the new arrow.
Thank you for the answer. I will do that