Volume Change Histogram

Author: Copyright © 2020, Vladimir Karputov
0 Views
0 Downloads
0 Favorites
Volume Change Histogram
ÿþ//+------------------------------------------------------------------+

//|                                      Volume Change Histogram.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 indicator_separate_window

#property indicator_buffers 1

#property indicator_plots   1

//--- plot VolumeChange

#property indicator_label1  "VolumeChange"

#property indicator_type1   DRAW_HISTOGRAM

#property indicator_color1  clrMediumSeaGreen

#property indicator_style1  STYLE_SOLID

#property indicator_width1  2

//--- input parameters

input double                  InpCoefficient    = 1.99;           // Volume Change Coefficient

input ENUM_APPLIED_VOLUME     InpAppliedVolume  = VOLUME_TICK;    // Volume type for calculation

//--- indicator buffers

double   VolumeChangeBuffer[];

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,VolumeChangeBuffer,INDICATOR_DATA);

//--- an empty value for plotting, for which there is no drawing

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

  {

   if(rates_total<1)

      return(0);

//---

   int limit=prev_calculated-1;

   if(prev_calculated==0)

     {

      VolumeChangeBuffer[0]=0.0;

      limit=1;

     }

//--- main loop

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

     {

      //--- calculate with appropriate volumes

      if(InpAppliedVolume==VOLUME_TICK)

        {

         if(tick_volume[i]>tick_volume[i-1]*InpCoefficient)

            VolumeChangeBuffer[i]=(double)tick_volume[i];

         else

            VolumeChangeBuffer[i]=0.0;

        }

      else

        {

         if(volume[i]>volume[i-1]*InpCoefficient)

            VolumeChangeBuffer[i]=(double)volume[i];

         else

            VolumeChangeBuffer[i]=0.0;

        }

     }

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