High Low Volume

Author: Copyright © 2019, Vladimir Karputov
Price Data Components
0 Views
0 Downloads
0 Favorites
High Low Volume
ÿþ//+------------------------------------------------------------------+

//|                                              High Low Volume.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 1

#property indicator_plots   1

//--- plot Force

#property indicator_label1  "HLW"

#property indicator_type1   DRAW_LINE

#property indicator_color1  clrRoyalBlue

#property indicator_style1  STYLE_SOLID

#property indicator_width1  2

//--- input parameters

input int      Inp_Number_Bars   = 3;  // Number of bars

//--- indicator buffers

double         HLWBuffer[];

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

   if(Inp_Number_Bars<1)

     {

      string err_text=(TerminalInfoString(TERMINAL_LANGUAGE)=="Russian")?

                      "0@0<5B@ \"Number of bars\" =5 <>65B 1KBL @025= =C;N!":

                      "Parameter \"Number of bars\" cannot be zero!";

      //--- when testing, we will only output to the log about incorrect input parameters

      Print(__FILE__," ",__FUNCTION__,", ERROR: ",err_text);

      return(INIT_PARAMETERS_INCORRECT);

     }

//--- indicator buffers mapping

   SetIndexBuffer(0,HLWBuffer,INDICATOR_DATA);

//--- set accuracy

   IndicatorSetInteger(INDICATOR_DIGITS,Digits());

//--- name for DataWindow

   IndicatorSetString(INDICATOR_SHORTNAME,"HLW"+"("+IntegerToString(Inp_Number_Bars)+")");

//---- sets drawing line 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[])

  {

//--- check for bars count

   if(rates_total<Inp_Number_Bars-1)

      return(0);// not enough bars for calculation

//--- main loop

   int i=0,limit=0;

//--- first calculation or number of bars was changed

   if(prev_calculated==0)// first calculation

     {

      ArrayInitialize(HLWBuffer,0.0);

      limit=Inp_Number_Bars;

      //---

      double firstValue=0.0;

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

         HLWBuffer[i]=0.0;

     }

   else

      limit=prev_calculated-1;

//--- main loop

   for(i=limit; i<rates_total && !IsStopped(); i++)

     {

      double firstValue=0.0;

      for(int j=i-Inp_Number_Bars+1; j<=i; j++)

         firstValue+=(high[j]-low[j])*tick_volume[j];



      HLWBuffer[i]=firstValue;

     }

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