Body candle statistics

Author: Copyright © 2018-2019, Vladimir Karputov
Price Data Components
0 Views
0 Downloads
0 Favorites
Body candle statistics
ÿþ//+------------------------------------------------------------------+

//|                                       Body candle statistics.mq5 |

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

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

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

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

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

#property version   "1.001"

#property description "Statistics of the body of the candle (average size for N-bars) at this hour"

#property indicator_separate_window

#property indicator_buffers 1

#property indicator_plots   1

//--- plot Histogram

#property indicator_label1  "Body"

#property indicator_type1   DRAW_HISTOGRAM

//---

#property indicator_color1  clrDeepPink

#property indicator_style1  STYLE_SOLID

#property indicator_width1  2

//--- input parameters

input int      Inp_ma_period=9;     // averaging period

//--- buffer of values

double         HistogramBuffer[];

//---

int m_digits=-1;

double m_point=-1.0;

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

   m_digits=Digits();

   if(m_digits<0)

      m_digits=0;

   m_point=Point();

//--- indicator buffer mapping

   SetIndexBuffer(0,HistogramBuffer,INDICATOR_DATA);

//---

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);

//--- name for Dindicator subwindow label

   IndicatorSetString(INDICATOR_SHORTNAME,"Body candle statistics ("+IntegerToString(Inp_ma_period)+")");

//---

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

  {

//---

   if(rates_total<Inp_ma_period)

      return(0);

   int limit=prev_calculated-1;

   if(prev_calculated==0)

     {

      limit=Inp_ma_period;

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

         HistogramBuffer[i]=0.0;

     }

//---

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

     {

      double body=0.0;

      for(int j=i-Inp_ma_period; j<i; j++)

         body+=MathAbs(open[j]-close[j]);

      body/=m_point;

      body/=(double)Inp_ma_period;

      HistogramBuffer[i]=body;

     }

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