Shadow to body ratio

Author: Copyright © 2020, Vladimir Karputov
Price Data Components
0 Views
0 Downloads
0 Favorites
Shadow to body ratio
ÿþ//+------------------------------------------------------------------+

//|                                         Shadow to body ratio.mq5 |

//|                              Copyright © 2020, Vladimir Karputov |

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

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

#property copyright "Copyright © 2020, Vladimir Karputov"

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

#property version   "1.000"

#property description "The body of the candle is always taken as 100%"

#property indicator_separate_window

#property indicator_buffers 2

#property indicator_plots   2

//--- plot UpperShadow

#property indicator_label1  "UpperShadow"

#property indicator_type1   DRAW_HISTOGRAM

#property indicator_color1  clrPaleTurquoise

#property indicator_style1  STYLE_SOLID

#property indicator_width1  2

//--- plot BottomShadow

#property indicator_label2  "BottomShadow"

#property indicator_type2   DRAW_HISTOGRAM

#property indicator_color2  clrNavajoWhite

#property indicator_style2  STYLE_SOLID

#property indicator_width2  2

//--- input parameters

input bool  InpInversion   = false;       // Inversion

input ulong InpCoarsening  = 0;           // Coarsening, in points (1.00045-1.00055=10 points)

//--- indicator buffers

double   UpperShadowBuffer[];

double   BottomShadowBuffer[];

//---

double   m_coarsening         = 0.0;      // Coarsening     -> double

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,UpperShadowBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,BottomShadowBuffer,INDICATOR_DATA);

//--- an empty value

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);

   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);

//---

   if(InpCoarsening>0)

      m_coarsening      = InpCoarsening   * Point();

//--- name for Dindicator subwindow label

   string inversion=(InpInversion)?"true":"false";

   IndicatorSetString(INDICATOR_SHORTNAME,"Shadow to body ratio("+inversion+","+IntegerToString(InpCoarsening)+")");

//---

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

     {

      double upper_shadow=0.0;

      double body=0.0;

      double bottom_shadow=0.0;

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

        {

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

         body           = close[i]-open[i];

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

        }

      else

        {

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

         body           = open[i]-close[i];

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

        }

      if(InpCoarsening>0)

        {

         if(upper_shadow<=m_coarsening)

            upper_shadow=0.0;

         if(body<=m_coarsening)

            body=0.0;

         if(bottom_shadow<=m_coarsening)

            bottom_shadow=0.0;

        }

      //---

      if(body==0.0)

        {

         UpperShadowBuffer[i]=0.0;

         BottomShadowBuffer[i]=0.0;

        }

      else

        {

         if(!InpInversion)

           {

            UpperShadowBuffer[i]=upper_shadow/**100.0*//body;

            BottomShadowBuffer[i]=-(bottom_shadow/**100.0*//body);

           }

         else

           {

            if(upper_shadow*100.0/body==0.0)

               UpperShadowBuffer[i]=0.0;

            else

               UpperShadowBuffer[i]=1.0/(upper_shadow/**100.0*//body);

            if(bottom_shadow*100.0/body==0.0)

               BottomShadowBuffer[i]=0.0;

            else

               BottomShadowBuffer[i]=-1.0/(bottom_shadow/**100.0*//body);

           }

        }

     }

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

   return(rates_total);

  }

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

Comments