Download MetaTrader 5

How can i draw a dot on my chart?

To add comments, please log in or register
EagleEye
305
EagleEye  

I would like to have a dot on my screen everytime a specific pattern is reached.

I can see that something like this could be used:
SetIndexArrow(2, 251); // cross code in Wingdings

But i'm sure i need more code than this one line.

Viffer
614
Viffer  

You are going to have to tell it where to place the dot.... have a look at OBJECTS

https://docs.mql4.com/objects/ObjectCreate

V

EagleEye
305
EagleEye  

Thanks Viffer,

But how can i use the sample?

I need a round circle on top of the bar/candle that is at the privious bar of the current bar when a specific pattern has occured.

I cannot see how i can control that with the x and y distance.

Viffer
614
Viffer  

The x and Y co ordinates are the time for x and a price for y. So the x and y for the high of the prev bar would be Time[1] and High[1].

V

EagleEye
305
EagleEye  

After hours of searching i have finally found this peace of code to draw my dot's, but it's only drawing one red dot and not a red dot over each bar that meet my critia.

      string objName = "Bullseye"; 
      if (ObjectFind(objName) != -1) {
         ObjectDelete(objName);
      }
         double price = High[1]; 
         ObjectCreate(objName, OBJ_TEXT, 0, Time[1], High[1]); 
         ObjectSetText(objName, CharToStr(159), 14, "Wingdings", Red); 
    }

Can anyone see what wrong in my code?

   double Bar1, Bar2, Buttom, Top;
   double OpenPrice1=Open[1]; 
   double ClosePrice1=Close[1]; 
   double HighPrice1=High[1]; 
   double LowPrice1=Low[1];
   
   double OpenPrice2=Open[2]; 
   double ClosePrice2=Close[2]; 
   double HighPrice2=High[2]; 
   double LowPrice2=Low[2];
      
   
   // Find high/low of the two doji bars
   if (HighPrice1 > HighPrice2)  {
         Top = HighPrice1;
      }  else  { 
         Top = HighPrice2;
      }

   if (LowPrice1 > LowPrice2) {
         Buttom = LowPrice1;
      }  else  {
         Buttom = LowPrice2;
      }

   if (( MathAbs(OpenPrice1-ClosePrice1) <= 4*Point) && ( MathAbs(OpenPrice2-ClosePrice2) <= 4*Point)) {
         DrawDot();
      }
}      

    void DrawDot()
    {
      string objName = "TouchDown"; 
      if (ObjectFind(objName) != -1) {
         ObjectDelete(objName);
      }
         double price = High[1]; 
         ObjectCreate(objName, OBJ_TEXT, 0, Time[1], price); 
         ObjectSetText(objName, CharToStr(159), 14, "Wingdings", Red); 
    }
Viffer
614
Viffer  

Each dot will need its own object name if you want lots of dots. Typically, that can be achieved like so..

string objName = "Bullseye"+Time[1];
V
Viffer
614
Viffer  

And just to expand... in your code you are using

      if (ObjectFind(objName) != -1) {
         ObjectDelete(objName);

Which means, if the object called "objName" already exists, delete it.

V

EagleEye
305
EagleEye  

Ohh yeah.... that works much better :) Thanks a lot!

Do you know how i can make a distance so that the red dot is not in the middle of the bar but on top of the bar with a few pips distance?

Viffer
614
Viffer  
EagleEye:

Ohh yeah.... that works much better :) Thanks a lot!

Do you know how i can make a distance so that the red dot is not in the middle of the bar but on top of the bar with a few pips distance?

just add how ever many pips on to the High[1]. It doesn't have to be THE price just any number that is on the price axis of your chart
EagleEye
305
EagleEye  

Ok i have now cooked it down to this. And it works perfect. Thanks!

    void DrawDot()   {  
         string objName = "Bullseye" + Time[1]; 
         ObjectCreate(objName, OBJ_TEXT, 0, Time[1], High[1]+10*Point); 
         ObjectSetText(objName, CharToStr(159), 14, "Wingdings", Red); 
      }
Szilard Kallai
145
Szilard Kallai  
EagleEye:

Ok i have now cooked it down to this. And it works perfect. Thanks!

Thank you for the code! It helped me out form lots or trying!

12
To add comments, please log in or register