Limit Candles

Author: Copyright © 2021, Vladimir Karputov
Price Data Components
0 Views
0 Downloads
0 Favorites
Limit Candles
ÿþ//+------------------------------------------------------------------+

//|                                                Limit Candles.mq5 |

//|                              Copyright © 2021, Vladimir Karputov |

//|                     https://www.mql5.com/ru/market/product/43161 |

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

#property copyright "Copyright © 2021, Vladimir Karputov"

#property link      "https://www.mql5.com/ru/market/product/43161"

#property version   "1.00"

#property indicator_chart_window

#property indicator_buffers 5

#property indicator_plots   1

//--- plot ColorCandles

#property indicator_label1  "ColorCandles"

#property indicator_type1   DRAW_COLOR_CANDLES

#property indicator_color1  clrLimeGreen,clrLavender

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1

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

//| Enum Pips Or Points                                              |

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

enum ENUM_PIPS_OR_POINTS

  {

   pips=0,     // Pips (1.00045-1.00055=1 pips)

   points=1,   // Points (1.00045-1.00055=10 points)

  };

//--- input parameters

input ENUM_PIPS_OR_POINTS  InpPipsOrPoints   = points;   // Pips Or Points:

input uint                 InpNotPaint       = 40;       // Do not paint if the size is less than ...

//--- indicator buffers

double   OpenBuffer[];

double   HighBuffer[];

double   LowBuffer[];

double   CloseBuffer[];

double   ColorBuffer[];

//---

double   m_not_paint                = 0.0;      // Do not paint               -> double

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,OpenBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,HighBuffer,INDICATOR_DATA);

   SetIndexBuffer(2,LowBuffer,INDICATOR_DATA);

   SetIndexBuffer(3,CloseBuffer,INDICATOR_DATA);

   SetIndexBuffer(4,ColorBuffer,INDICATOR_COLOR_INDEX);

//--- an empty value

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);

//--- the name of the symbol, for which the bars are drawn

   string symbol=Symbol();

//--- set the display of the symbol

   PlotIndexSetString(0,PLOT_LABEL,symbol+" Open;"+symbol+" High;"+symbol+" Low;"+symbol+" Close");

   IndicatorSetString(INDICATOR_SHORTNAME,"DRAW_COLOR_CANDLES("+symbol+")");

//--- tuning for 3 or 5 digits

   int digits_adjust=1;

   if(Digits()==3 || Digits()==5)

      digits_adjust=10;

   double m_adjusted_point=Point()*digits_adjust;

   if(InpPipsOrPoints==pips) // Pips (1.00045-1.00055=1 pips)

     {

      m_not_paint                = InpNotPaint                 * m_adjusted_point;

     }

   else // Points (1.00045-1.00055=10 points)

     {

      m_not_paint                = InpNotPaint                 * Point();

     }

//---

   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[])

  {

//---

   int limit=prev_calculated-1;

   if(prev_calculated==0)

      limit=0;

   for(int i=limit; i<rates_total; i++)

     {

      if((open[i]<close[i] && close[i]-open[i]<m_not_paint) || (open[i]>close[i] && open[i]-close[i]<m_not_paint))

        {

         OpenBuffer[i]=0.0;

         HighBuffer[i]=0.0;

         LowBuffer[i]=0.0;

         CloseBuffer[i]=0.0;

         ColorBuffer[i]=0.0;

         continue;

        }

      //---

      OpenBuffer[i]=open[i];

      HighBuffer[i]=high[i];

      LowBuffer[i]=low[i];

      CloseBuffer[i]=close[i];

      ColorBuffer[i]=(open[i]<close[i])?1.0:0.0;

     }

//--- return value of prev_calculated for next call

   return(rates_total);

  }

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

Comments