HVR 1[1].00

Author: mladen
Indicators Used
Moving average indicator
0 Views
0 Downloads
0 Favorites
HVR 1[1].00
this //+------------------------------------------------------------------+
//|                            Historical Volatility ratio indicator |
//|                                                          HVR.mq4 |
//|                                                           mladen |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link      ""

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
#property indicator_minimum 0

//
//
//
//
//

extern int ShortPeriod   =   6;
extern int LongPeriod    = 100;
extern int AverageMethod =   0;

//
//
//
//
//

double   HvrValue[];
double   LogValue[];


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

int init()
{
   IndicatorBuffers(2);
   SetIndexBuffer(0,HvrValue);
   SetIndexBuffer(1,LogValue);
   
   //
   //
   //
   //
   //
   
   IndicatorShortName("HVR ("+ShortPeriod+","+LongPeriod+")");
   return(0);
}
int deinit()
{
   return(0);
}


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

int start()
{
   double dev;
   int    counted_bars=IndicatorCounted();
   int    limit,i,k;


   if(counted_bars < 0) return(-1);
   limit = Bars-counted_bars;

   //
   //
   //
   //
   //
   
   for (i = limit; i>=0; i--)
      if (Close[i+1]!=0)
            LogValue[i] = MathLog(Close[i]/Close[i+1]);
      else  LogValue[i] = 0;
      
   //
   //
   //
   //
   //
         
   for (i = limit; i>=0; i--) {
      dev = hvDeviation(LongPeriod,i);
      if (dev!=0)
            HvrValue[i] = hvDeviation(ShortPeriod,i)/dev;
      else  HvrValue[i] = 0;
   }
   return(0);
}


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

double hvDeviation(int period,int shift)
{
   double dMA  = iMAOnArray(LogValue,0,period,0,AverageMethod,shift);
   double dSum = 0;
   int    i;

   for(i=0; i<period; i++) dSum += (LogValue[shift+i]-dMA)*(LogValue[shift+i]-dMA);
   
   return(MathSqrt(dSum/period));
}

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