MQL - Change Round Number Indicator

Hello,

I have this tool which I find it to be very helpful, it draws lines at round numbers but it only draws every 00s and I need it to draw also at 50s, another words I need it to draw a line every fifty pips instead of 100 pips.

There’s another problem with it also, it doesn’t work with the Japanese pairs which are 3 digits, I would like to fix that too.

My knowledge in programming is very limited but I’ve tried a few things to no avail.

Any help would be greatly appreciated

Code:

//+------------------------------------------------------------------+
//|                                               !Round Numbers.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+

#property indicator_chart_window

extern double LineSpace     = 1; // 1 unit = 0.01 of basic value (e.g. 1 USD cent)
extern color  LineColor     = DeepPink;
extern int    LineStyle     = 2;
extern string LineStyleInfo = "0=Solid,1=Dash,2=Dot,3=DashDot,4=DashDotDot";
extern string LineText      = "RoundNr ";

double LineSpaceOld;
double Hoch;
double Tief;
bool   FirstRun = true;

int deinit()
{
   double AbSpace = 0.01*LineSpace;
   double Oben    = MathRound(110*Hoch)/100;
   double Unten   = MathRound(80*Tief)/100;
   for(double i=0; i<=Oben; i+=AbSpace)
   {
      if(i<Unten) { continue; }
      ObjectDelete(LineText+DoubleToStr(i,2));
   }
   return(0);
}

int start()
{
   if(FirstRun)
   {
      Hoch = NormalizeDouble( High[iHighest(NULL,0,MODE_HIGH,Bars-1,0)], 2 );
      Tief = NormalizeDouble( Low[iLowest(NULL,0,MODE_LOW,Bars-1,0)], 2 );
      FirstRun = false;
   }
   else if(LineSpace != LineSpaceOld)
   {
      deinit();
      Hoch = NormalizeDouble( High[iHighest(NULL,0,MODE_HIGH,Bars-1,0)], 2 );
      Tief = NormalizeDouble( Low[iLowest(NULL,0,MODE_LOW,Bars-1,0)], 2 );
   }
   DrawLines();
   LineSpaceOld = LineSpace;
   return(0);
}

void DrawLines()
{
   double AbSpace = 0.01*LineSpace;
   double Oben    = MathRound(110*Hoch)/100;
   double Unten   = MathRound(80*Tief)/100;

   for(double i=0; i<=Oben; i+=AbSpace)
   {
      if(i<Unten) { continue; }
      string StringNr = DoubleToStr(i,2); // 2 digits number in object name
      if (ObjectFind(LineText+StringNr) != 0) // HLine not in main chartwindow
      {                     
         ObjectCreate(LineText+StringNr, OBJ_HLINE, 0, 0, i);
         ObjectSet(LineText+StringNr, OBJPROP_STYLE, LineStyle);
         ObjectSet(LineText+StringNr, OBJPROP_COLOR, LineColor);
      }
      else // Adjustments
      {
         ObjectSet(LineText+StringNr, OBJPROP_PRICE1, i);
         ObjectSet(LineText+StringNr, OBJPROP_STYLE, LineStyle);
         ObjectSet(LineText+StringNr, OBJPROP_COLOR, LineColor);
      }
   }
   WindowRedraw();
}

Hi,

You have written a nice piece of code. If you change these minor parts, it will work with the 50 levels and on Japanese pairs too:

[I]double AbSpace = 0.01LineSpace;[/I]
becomes
[I]double AbSpace = [B]500
MathPow(0.1, Digits())[/B]*LineSpace;[/I]
(twice, in line 22 and 54)

[I]ObjectDelete(LineText+DoubleToStr(i,2));
[/I]becomes[I]
ObjectDelete(LineText+DoubleToStr(i,[B]Digits()-2[/B]));[/I]
(in line 28)

and
[I]string StringNr = DoubleToStr(i,2); // 2 digits number in object name[/I]
becomes
[I]string StringNr = DoubleToStr(i,[B]Digits()-2[/B]); // 3 digits number in object name[/I]
(in line 61)

With these changes the code will take into consideration the number of digits after the decimal points.

Here is the new code (I had to remove the link in line 4, because I don’t have enough posts). Have fun with it!


//+------------------------------------------------------------------+
//|                                               !Round Numbers.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//
//+------------------------------------------------------------------+

#property indicator_chart_window

extern double LineSpace     = 1; // 1 unit = 0.01 of basic value (e.g. 1 USD cent)
extern color  LineColor     = DeepPink;
extern int    LineStyle     = 2;
extern string LineStyleInfo = "0=Solid,1=Dash,2=Dot,3=DashDot,4=DashDotDot";
extern string LineText      = "RoundNr ";

double LineSpaceOld;
double Hoch;
double Tief;
bool   FirstRun = true;

int deinit()
{
   double AbSpace = 500*MathPow(0.1, Digits())*LineSpace;
   double Oben    = MathRound(110*Hoch)/100;
   double Unten   = MathRound(80*Tief)/100;
   for(double i=0; i<=Oben; i+=AbSpace)
   {
      if(i<Unten) { continue; }
      ObjectDelete(LineText+DoubleToStr(i,Digits()-2));
   }
   return(0);
}

int start()
{
   if(FirstRun)
   {
      Hoch = NormalizeDouble( High[iHighest(NULL,0,MODE_HIGH,Bars-1,0)], 2 );
      Tief = NormalizeDouble( Low[iLowest(NULL,0,MODE_LOW,Bars-1,0)], 2 );
      FirstRun = false;
   }
   else if(LineSpace != LineSpaceOld)
   {
      deinit();
      Hoch = NormalizeDouble( High[iHighest(NULL,0,MODE_HIGH,Bars-1,0)], 2 );
      Tief = NormalizeDouble( Low[iLowest(NULL,0,MODE_LOW,Bars-1,0)], 2 );
   }
   DrawLines();
   LineSpaceOld = LineSpace;
   return(0);
}

void DrawLines()
{
   double AbSpace = 500*MathPow(0.1, Digits())*LineSpace;
   double Oben    = MathRound(110*Hoch)/100;
   double Unten   = MathRound(80*Tief)/100;

   for(double i=0; i<=Oben; i+=AbSpace)
   {
      if(i<Unten) { continue; }
      string StringNr = DoubleToStr(i,Digits()-2); // 3 digits number in object name
      if (ObjectFind(LineText+StringNr) != 0) // HLine not in main chartwindow
      {                     
         ObjectCreate(LineText+StringNr, OBJ_HLINE, 0, 0, i);
         ObjectSet(LineText+StringNr, OBJPROP_STYLE, LineStyle);
         ObjectSet(LineText+StringNr, OBJPROP_COLOR, LineColor);
      }
      else // Adjustments
      {
         ObjectSet(LineText+StringNr, OBJPROP_PRICE1, i);
         ObjectSet(LineText+StringNr, OBJPROP_STYLE, LineStyle);
         ObjectSet(LineText+StringNr, OBJPROP_COLOR, LineColor);
      }
   }
   WindowRedraw();
}

Thanks for the help, actually I did not write the code, I think I’ve had this tool for some time, because I have used third party charts in the past with this feature which I liked very much so I wanted to find something for MT4 that could do the same, I came across this code and I don’t even remember where I got it from and played with it and soon gave up and now I started playing with it again since I was reading a little bit about mql but still could get it to work. This definitely is a good tool if you like to pay attention to round numbers.

Best regards,
Ed

Did the solution mentioned above resolve the issue? I am asking out of curiosity.

Yes it did. If you want it you can download it here.