//+------------------------------------------------------------------+
//|                                                    DojiLines.mq4 |
//|                                                          mwfx108 |
//|                                                mwfx108@gmail.com |
//+------------------------------------------------------------------+
#property copyright "mwfx108"
#property link      "mwfx108@gmail.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
//--- input parameters
input int               Tolerance_Points = 10;     // Open / Close Tolerance Points
input color             Line_Color = clrRed;       // Line Color
input ENUM_LINE_STYLE   Line_Style = STYLE_SOLID;  // Line Style
input int               Line_Width = 1;            // Line Width
input bool              Show_HLines = true;        // Show Horizontal Lines
input bool              Show_VLines = true;        // Show Vertical Lines
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
   
   RemoveObjects();
   
//---
}
//+------------------------------------------------------------------+
//| 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[])
  {
//---

   double ts = MarketInfo(_Symbol, MODE_TICKSIZE), tolPts = Tolerance_Points * ts;
   int linesCounter = 0;

   for (int i = 0; i < rates_total; i++)
   {
      if (MathAbs(open[i] - close[i]) <= tolPts && high[i] - open[i] >= tolPts && close[i] - low[i] >= tolPts)
      {
         string objName;
         
         if (Show_HLines)
         {
            objName = "DojiLine_H_" + string(linesCounter);
            double price = (open[i] + close[i]) / 2;
            ObjectCreate(objName, OBJ_HLINE, 0, 0, price);
            ObjectSetInteger(0, objName, OBJPROP_COLOR, Line_Color);
            ObjectSetInteger(0, objName, OBJPROP_WIDTH, Line_Width);
            ObjectSetInteger(0, objName, OBJPROP_STYLE, Line_Style);
            ObjectSetInteger(0, objName, OBJPROP_BACK, 1);
         }
         
         if (Show_VLines)
         {
            objName = "DojiLine_V_" + string(linesCounter);
            ObjectCreate(objName, OBJ_VLINE, 0, time[i], 0);
            ObjectSetInteger(0, objName, OBJPROP_COLOR, Line_Color);
            ObjectSetInteger(0, objName, OBJPROP_WIDTH, Line_Width);
            ObjectSetInteger(0, objName, OBJPROP_STYLE, Line_Style);
            ObjectSetInteger(0, objName, OBJPROP_BACK, 1);
         }
         
         linesCounter++;
      }
   }
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Remove our chart objects                                         |
//+------------------------------------------------------------------+
void RemoveObjects()
{
//---
   
   for (int i = ObjectsTotal(); i >= 0; i--)
   {
      string objName = ObjectName(i);
      if (StringFind(objName, "DojiLine_") >= 0)
         ObjectDelete(objName);
   }
   
//--- 
}
//+------------------------------------------------------------------+
