Candle shadow percent histogram 2

Author: Copyright © 2019-2020, Vladimir Karputov
0 Views
0 Downloads
0 Favorites
Candle shadow percent histogram 2
ÿþ//+------------------------------------------------------------------+

//|                            Candle shadow percent histogram 2.mq5 |

//|                         Copyright © 2019-2021, Vladimir Karputov |

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

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

#property copyright "Copyright © 2019-2020, Vladimir Karputov"

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

#property version   "2.001"

#property indicator_separate_window

#property indicator_buffers 3

#property indicator_plots   1

//--- plot Ratio

#property indicator_label1  "Ratio"

#property indicator_type1   DRAW_COLOR_HISTOGRAM2

#property indicator_color1  clrOrangeRed,clrRoyalBlue

#property indicator_style1  STYLE_SOLID

#property indicator_width1  2

//--- set limit of the indicator values

#property indicator_minimum -100

#property indicator_maximum 100

//--- indicator buffers

double   RatioBuffer1[];

double   RatioBuffer2[];

double   RatioColors[];

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,RatioBuffer1,INDICATOR_DATA);

   SetIndexBuffer(1,RatioBuffer2,INDICATOR_DATA);

   SetIndexBuffer(2,RatioColors,INDICATOR_COLOR_INDEX);

//--- set accuracy

   IndicatorSetInteger(INDICATOR_DIGITS,0);

//--- sets drawing line to empty value

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);

//--- set the display of the symbol

   PlotIndexSetString(0,PLOT_LABEL,"Upper shadow;"+"Bottom shadow;");

//---

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

     {

      //--- high_low -> 100%

      double high_low=high[i]-low[i]; // 100%

      double upper_shadow,bottom_shadow;

      if(open[i]>close[i])

        {

         RatioColors[i]=0;

         upper_shadow=high[i]-open[i];

         bottom_shadow=close[i]-low[i];

        }

      else

        {

         RatioColors[i]=1;

         upper_shadow=high[i]-close[i];

         bottom_shadow=open[i]-low[i];

        }

      //--- high_low     -> 100%

      //--- upper_shadow -> x%

      //--- x = upper_shadow * 100 / high_low

      if(high_low==0.0)

         RatioBuffer1[i]=0.0;

      else

         RatioBuffer1[i]=upper_shadow * 100.0 / high_low;

      if(high_low==0.0)

         RatioBuffer2[i]=0.0;

      else

         RatioBuffer2[i]=-(bottom_shadow * 100.0 / high_low);

     }

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

   return(rates_total);

  }

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

Comments