Drawing a square or rectangle. Really need help...

 

How can I make a square or rectangle be drawn on the chart when the price of a currency pair changes, keep it for 15 seconds, delete it and appear again the next time the price changes?

Please help, I have been struggling with this for a long time. Just drawing is easy, but when the price changes - no way =(.

 

Sorry, no time to write the code myself and debug it, but I think you can handle my TOR. I need to make this indicator:

1) Declare static variable static double PrevPrice=0.0;

2) At start we write the following construct

if(PrevPrice!=Bid)

{

DeleteBox(...); /* delete rectangle (in case it is still there) */

DrawBox(...); /* draw rectangle */

Sleep(15000); /* wait 15 seconds */

DeleteBox(...); /* delete rectangle */

PrevPrice=Bid; /* remember new price for new check */

}

 

DeleteBox(...);

DrawBox(...);



I couldn't even find these functions in the help, but thanks for the answer.

 

The Sleep function does not work in indicators.

You need an Expert Advisor or a script that works in an infinite loop.

 

I need to do this in an EA, the second function. There is an EA like this:


static double mSaveAsk;
 
int init()
{
   mSaveAsk = Ask;
}
 
int start()
{
   if ( Ask != mSaveAsk )
   {
      PlaySound("alert.wav");
   }
   mSaveAsk = Ask;
}
 
Chaos666 писал (а) >>

I need to do this in an EA, the second function. There is an EA like this:

To add MQL4 code, please use the add source code command in the editor:

 
Good.
 
Chaos666 писал (а) >>

DeleteBox(...);

DrawBox(...);

I couldn't even find these functions in the help, but thanks for the answer.

And you won't. You will have to do these functions yourself.

 
That's how I understood it. Unfortunately I am very unfamiliar with it, just learning. I need examples, so I asked for help....
 
#property copyright "Copyright © 2008, D500"
#property link      "http://www.metaquotes.net"
extern int Timer=15;
extern color Coler=OrangeRed;
 
double PrevPrice;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   if(PrevPrice!=Bid)
 
{
 
if (ObjectFind("QUADRO")==0)  DeleteBox(); /* удаляем прямоугольник (на случай если он все еще есть) */
 
DrawBox(); /* рисуем прямоугольник */
 
Sleep(Timer*1000); /* ждем 15 секунд */
 
PrevPrice=Bid; /* запоминаем новую цену для новой проверки */
 
}
//----
   return(0);
  }
//+------------------------------------------------------------------+
void DrawBox()
{
     ObjectCreate("QUADRO",OBJ_RECTANGLE,0,Time[5],Close[0]-10*Point,Time[0],Close[0]+10*Point);
     ObjectSet("QUADRO",6,Coler);
     return;
}
//-------------------------------------------------------------------+
void DeleteBox()
{
      ObjectDelete("QUADRO");
      return;
}
This is an advisor for you as an example. Experiment.
 
Thank you very much.
Reason: