Exponential Volume Average

Author: Copyright � 2009, Obaidah.
Exponential Volume Average
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
Exponential Volume Average
//+------------------------------------------------------------------+
//|                                   Exponential Volume Average.mq4 |
//|                                       Copyright © 2009, Obaidah. |
//|                                               clefts@hotmail.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, Obaidah."
#property link      "clefts@hotmail.com"

extern int Period1=12;

int ExtCountedBars=0;
double ExtMapBuffer[];
double Vol[];

#property  indicator_separate_window
#property  indicator_minimum 0
#property  indicator_buffers 2
#property  indicator_color1  White
#property  indicator_color2  White
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorBuffers(2);
   
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   
   SetIndexDrawBegin(0,Period1);
   SetIndexDrawBegin(1,Period1);
   
   SetIndexBuffer(0,ExtMapBuffer);
   SetIndexBuffer(1,Vol);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   if(Bars<=Period1) return(0);
   ExtCountedBars=IndicatorCounted();
//---- check for possible errors
   if (ExtCountedBars<0) return(-1);
//---- last counted bar will be recounted
   if (ExtCountedBars>0) ExtCountedBars--;
   ema();
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

void ema()
  {
   double pr=2.0/(Period1+1);
   int    pos=Bars-2;
   if(ExtCountedBars>2) pos=Bars-ExtCountedBars-1;
//---- main calculation loop
   while(pos>=0)
     {
      if(pos==Bars-2) ExtMapBuffer[pos+1]=Volume[pos+1];
      ExtMapBuffer[pos]=Volume[pos]*pr+ExtMapBuffer[pos+1]*(1-pr);
 	   pos--;
 	   Vol[pos]=Volume[pos];
     }
  }

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