Miscellaneous
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 Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---