Candle shadow percent histogram

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

//|                              Candle shadow percent histogram.mq5 |

//|                              Copyright © 2019, Vladimir Karputov |

//|                                           http://wmua.ru/slesar/ |

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

#property copyright "Copyright © 2019, Vladimir Karputov"

#property link      "http://wmua.ru/slesar/"

#property version   "1.001"

#property indicator_separate_window

#property indicator_buffers 2

#property indicator_plots   1

//--- plot Ratio

#property indicator_label1  "Ratio"

#property indicator_type1   DRAW_COLOR_HISTOGRAM

#property indicator_color1  clrOrangeRed,clrRoyalBlue

#property indicator_style1  STYLE_SOLID

#property indicator_width1  2

//--- set limit of the indicator values 

#property indicator_minimum 0 

#property indicator_maximum 1

//--- indicator buffers

double         RatioBuffer[];

double         RatioColors[];

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,RatioBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,RatioColors,INDICATOR_COLOR_INDEX);

//--- sets drawing line to empty value 

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);

//---

   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=0;i<rates_total;i++)

     {

      double body=(open[i]>close[i])?open[i]-close[i]:close[i]-open[i];

      double shadow=high[i]-low[i];

      if(shadow==0.0)

        {

         RatioBuffer[i]=0.0;

         RatioColors[i]=0;

        }

      else

        {

         if(i==0)

           {

            RatioBuffer[0]=0.0;

            RatioColors[0]=0;

           }

         else

           {

            RatioBuffer[i]=body/shadow;

            if(RatioBuffer[i]>RatioBuffer[i-1])

               RatioColors[i]=0;

            else

               RatioColors[i]=1;

           }

        }

     }

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