//+------------------------------------------------------------------+ //| New Grid Builder.mq4 | //| Naguisa Unada | //| https://www.mql5.com/en/users/unadajapon/news | //+------------------------------------------------------------------+ #property copyright "Naguisa Unada" #property link "https://www.mql5.com/en/users/unadajapon/news" #property version "1.00" #property strict #property indicator_chart_window //--- input parameters input int GridSpace = 50; //Grid Space (Pips) input int Num_above = 0; //Number of lines above center (0 = "AUTO") input int Num_below = 0; //Number of lines below center (0 = "AUTO") input ENUM_LINE_STYLE Line_Style = STYLE_DOT; //Line Style input color Line_Color = clrDimGray; //Line Color input int Line_Width = 1; //Line Width //--- int price_high, price_low; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //---- for(int shift = price_low; shift <= price_high; shift++) ObjectDelete("Grid_" + IntegerToString(shift)); //---- } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ 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[]) { //--- int i, Divisor, price_current, difference, price_center; string obj_name; Divisor = (int)(0.1 / Point); price_current = (int)MathRound(close[1] * Divisor); difference = (int)MathMod(price_current, GridSpace); if (difference - GridSpace / 2 > 0) price_center = price_current - difference + GridSpace; else price_center = price_current - difference; if (Num_above == 0) price_high = (int)MathRound(high[ArrayMaximum(high, 0, 1)] * Divisor); else price_high = price_center + GridSpace * Num_above; if (Num_below == 0) price_low = (int)MathRound(low[ArrayMinimum(low, 0, 1)] * Divisor); else price_low = price_center - GridSpace * Num_below; for (i = price_low; i <= price_high; i++) { if (MathMod(i, GridSpace) == 0) { obj_name = "Grid_" + IntegerToString(i); if (ObjectFind(obj_name) < 0) { ObjectCreate(obj_name, OBJ_HLINE, 0, time[1], (double)i / (double)Divisor); ObjectSet(obj_name, OBJPROP_STYLE, Line_Style); ObjectSet(obj_name, OBJPROP_WIDTH, Line_Width); ObjectSet(obj_name, OBJPROP_COLOR, Line_Color); } } } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+