RoundLevelsIndicator

Author: Copyright 2019, Peter
2 Views
0 Downloads
0 Favorites
RoundLevelsIndicator
ÿþ//+------------------------------------------------------------------+

//|                                           Copyright 2019, ZhSerg |

//|                                                https://zhserg.ru |

//+------------------------------------------------------------------+

#property copyright "Copyright 2019, Peter"

#property link      "https://www.mql5.com/en/users/m0rg4n"

#property version   "1.0"

#property strict 



#property indicator_chart_window



extern int              MainLevels              = 500;               //Size of grid

extern int              NumLinesAboveBelow      = 25;                //Quantity of levels

extern color            LineColor               = DarkBlue;          //Levels color

extern ENUM_LINE_STYLE  LineStyle               = STYLE_DOT;         //Levels Type

//+------------------------------------------------------------------+

int OnInit(){

   ObjectsDeleteAll(0,"RoundLevel");

   return INIT_SUCCEEDED;

}

//+------------------------------------------------------------------+

void OnDeinit(const int reason){

   ObjectsDeleteAll(0,"RoundLevel");

}

//+------------------------------------------------------------------+

int OnCalculate (const int rates_total,

                 const int prev_calculated,

                 const datetime& time[],

                 const double& open[],

                 const double& high[],

                 const double& low[],

                 const double& close[],

                 const long& tick_volume[],

                 const long& volume[],

                 const int& spread[])

  {

   static datetime timelastupdate= 0;

   static datetime lasttimeframe= 0;

   

    

   // no need to update these buggers too often   

   if (TimeCurrent()-timelastupdate < 600 && Period()==lasttimeframe)

      return (0);

   

   ObjectsDeleteAll(0,"RoundLevel");  // delete all previous lines

      

   int i, ssp1, ssp;

   double ds1;

   

   ssp1=(int)(Bid/_Point);

   ssp1=ssp1-ssp1%MainLevels;



   for (i= -NumLinesAboveBelow; i<NumLinesAboveBelow; i++) {

      ssp= ssp1+(i*MainLevels); 

      ds1= ssp*_Point;

      SetLevel(DoubleToString(ds1,_Digits), ds1, Time[10]);

   }



   return(0);

}

//+------------------------------------------------------------------+

void SetLevel(string text, double level, datetime startofday){



   string linename= "RoundLevel_" + text + " Line"; 



   if (ObjectFind(linename) != 0) {

      ObjectCreate(0,linename, OBJ_HLINE, 0, 0, level);

      ObjectSetInteger(0,linename, OBJPROP_STYLE, LineStyle);

      ObjectSetInteger(0,linename, OBJPROP_COLOR, LineColor);

      ObjectSetInteger(0,linename, OBJPROP_WIDTH, 1);

      ObjectSetString(0,linename,OBJPROP_TOOLTIP,text);

   }

   else {

      ObjectMove(0,linename, 0, Time[0], level);

   }

}     

//+------------------------------------------------------------------+

  

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---