Author: Copyright � 2007, MetaQuotes Software Corp.
CHV
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
CHV
//+------------------------------------------------------------------+
//|                                                          CHO.mq4 |
//|                      Copyright © 2007, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property  indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 DarkBlue
//---- input parameters
extern int       SmoothPeriod=10;
extern int       ROCPeriod=10;
extern int       TypeSmooth=1;// 0 - SMA, 1 - EMA
//---- buffers
double CHV[];
double HL[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   string name,smoothString;
   if (TypeSmooth<0 || TypeSmooth>1) TypeSmooth=1;
   if (TypeSmooth==0) smoothString="SMA"; else smoothString="EMA";
   name="Chaikin Volatility("+SmoothPeriod+","+smoothString+")";

   IndicatorBuffers(2);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,CHV);
   SetIndexLabel(0,name);
   SetIndexEmptyValue(0,0.0);
   SetIndexBuffer(1,HL);
   SetIndexEmptyValue(1,0.0);
   IndicatorShortName(name);
   IndicatorDigits(1);
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   int limit,i;
   double curr_value,shift_value;
//----
   if (counted_bars<0) return(-1);

   if (counted_bars==0) 
      {
      limit=Bars-1;
      for (i=limit;i>=0;i--)
        {
         HL[i]=High[i]-Low[i];
        }
      for(i=limit-2*SmoothPeriod;i>=0;i--)
        {
         curr_value=iMAOnArray(HL,0,SmoothPeriod,0,TypeSmooth,i);
         shift_value=iMAOnArray(HL,0,SmoothPeriod,0,TypeSmooth,i+ROCPeriod);
         CHV[i]=(curr_value-shift_value)/shift_value*100;
        }
      }

   if (counted_bars>0) 
     {
      limit=Bars-counted_bars;
      for (i=limit;i>=0;i--)
        {
         HL[i]=High[i]-Low[i];
        }
      for(i=limit;i>=0;i--)
        {
         curr_value=iMAOnArray(HL,0,SmoothPeriod,0,TypeSmooth,i);
         shift_value=iMAOnArray(HL,0,SmoothPeriod,0,TypeSmooth,i+ROCPeriod);
         CHV[i]=(curr_value-shift_value)/shift_value*100;
        }
      }            
//----
   return(0);
  }
//+------------------------------------------------------------------+

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