mfcs_gridlines

Author: Copyright 2015, Mansukh Patidar, All rights reserved.
2 Views
0 Downloads
0 Favorites
mfcs_gridlines
//+------------------------------------------------------------------+
//|                                               MFCS GridLines.mq5 |
//|            Copyright 2015, Mansukh Patidar, All rights reserved. |
//|                                    http://www.mansukhpatidar.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, Mansukh Patidar, All rights reserved."
#property link      "http://www.mansukhpatidar.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_plots 0
//--- input parameters
input int      lines=100;
input int      interval=200;
input ENUM_LINE_STYLE   line_style=STYLE_DOT;
input int   line_width = 1;
input color line_color = C'128, 50, 50';
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void ClearExistingGridLines()
  {
   int index = 0;
   for(index = 0; index < lines*5; index++)
     {
      string n1 = _Symbol + "_MFCS_GRID_LINES_ABOVE_" + (string)index;
      string n2 = _Symbol + "_MFCS_GRID_LINES_BELOW_" + (string)index;
      ObjectDelete(0,n1);
      int e1=ObjectFind(0,n1);
      ObjectDelete(0,n2);
      int e2=ObjectFind(0,n1);
      //---
      if(e1>=0 || e2>=0)
        {
         printf("error in removing gridlines");
        }
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   ClearExistingGridLines();
  }
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   ClearExistingGridLines();
//---
   MqlTick last_tick;  //structure for last tick
   SymbolInfoTick(_Symbol,last_tick); //filling last_tick with recent prices
//---
   double base_price= last_tick.ask;
   double pip_value = SymbolInfoDouble(_Symbol,SYMBOL_POINT);
   int multipler=(int) pow(10,SymbolInfoInteger(_Symbol,SYMBOL_DIGITS));
//---
   long temp_price=(long)(base_price*multipler);
   temp_price=temp_price-temp_price%1000;
//---
   base_price=temp_price*pip_value;
//---
   int index = 0;
   for(index = 0; index < lines; index++)
     {
      double p1 = base_price + index * interval * pip_value;
      double p2 = base_price - index * interval * pip_value;
      string n1 = _Symbol + "_MFCS_GRID_LINES_ABOVE_" + (string)index;
      string n2 = _Symbol + "_MFCS_GRID_LINES_BELOW_" + (string)index;
      //---
      ObjectCreate(0,n1,OBJ_HLINE,0,0,p1);
      ObjectCreate(0,n2,OBJ_HLINE,0,0,p2);
      //---
      bool back=false;
      //--- set line color
      ObjectSetInteger(0,n1,OBJPROP_COLOR,line_color);
      //--- set line display style
      ObjectSetInteger(0,n1,OBJPROP_STYLE,line_style);
      //--- set line width
      ObjectSetInteger(0,n1,OBJPROP_WIDTH,line_width);
      //--- display in the foreground (false) or background (true)
      ObjectSetInteger(0,n1,OBJPROP_BACK,back);
      //--- set line color
      ObjectSetInteger(0,n2,OBJPROP_COLOR,line_color);
      //--- set line display style
      ObjectSetInteger(0,n2,OBJPROP_STYLE,line_style);
      //--- set line width
      ObjectSetInteger(0,n2,OBJPROP_WIDTH,line_width);
      //--- display in the foreground (false) or background (true)
      ObjectSetInteger(0,n2,OBJPROP_BACK,back);
     }
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
//---
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

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 ---