Indicators Used
Miscellaneous
0
Views
0
Downloads
0
Favorites
BatMA_23poleGF
//+------------------------------------------------------------------+
//| Custom Moving Average.mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| Copyright © 2008, YUBA |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
//mod batma - 2/3-pole Gaussian filter
#property copyright "Copyright © 2004, MetaQuotes Software Corp.,Copyright © 2008, YUBA"
#property link "http://www.metaquotes.net/"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 OrangeRed
//---- indicator parameters
extern int MA_Period=15;
extern int MA_Method=4;
extern int MA_Price=0;
extern int MA_Shift=0;
extern string note_Price = "0C 1O 2H 3L 4Md 5Tp 6WghC: Md(HL/2)4,Tp(HLC/3)5,Wgh(HLCC/4)6";
extern string MA_Method_ = "SMA0 EMA1 SMMA2 LWMA3 2pGF4 3pGF5";
//---- indicator buffers
double ExtMapBuffer[], pr;
//----
int ExtCountedBars=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
int draw_begin;
string short_name;
//---- drawing settings
SetIndexStyle(0,DRAW_LINE);
SetIndexShift(0,MA_Shift);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
if(MA_Period<2) MA_Period=2;
draw_begin=MA_Period-1;
//---- indicator short name
switch(MA_Method)
{
case 1 : short_name="SMA("; draw_begin=0; break;
case 1 : short_name="EMA("; break;
case 2 : short_name="SMMA("; break;
case 3 : short_name="LWMA("; break;
case 4 : short_name="2poleEF("; break;
case 5 : short_name="3poleEF(";
}
IndicatorShortName(short_name+MA_Period+")");
SetIndexDrawBegin(0,draw_begin);
//---- indicator buffers mapping
SetIndexBuffer(0,ExtMapBuffer);
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
if(Bars<=MA_Period) return(0);
ExtCountedBars=IndicatorCounted();
//---- check for possible errors
if (ExtCountedBars<0) return(-1);
//---- last counted bar will be recounted
if (ExtCountedBars>0) ExtCountedBars--;
//----
int limit=Bars-ExtCountedBars;
switch(MA_Method)
{
case 0 : MA_Method=0; break;
case 1 : MA_Method=1; break;
case 2 : MA_Method=2; break;
case 3 : MA_Method=3; break;
case 4 : pr=MathSqrt(2.0/(1.0+MA_Period));
GF2pole(pr); break;
case 5 : pr=MathSqrt(2.0/(1.0+MA_Period));
GF3pole(pr);
}
for(int i=limit; i>=0; i--)
if (MA_Method<4)
ExtMapBuffer[i]=iMA(NULL,0,MA_Period,0,MA_Method,MA_Price,i);
if (MA_Method>5)MA_Method=5;
//---- done
return(0);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Batterwort Moving Average //gaussian2pole filter |
//+------------------------------------------------------------------+
void GF2pole(double Kf)
{
double p=2.0/(MA_Period+1);
double p1,p2,p3;
int pos=Bars-2;
p1=Kf*Kf;
p2=2.0*(1-Kf);
p3=(1-Kf)*(1-Kf);
if(ExtCountedBars>2) pos=Bars-ExtCountedBars-1;
//---- main calculation loop
while(pos>=0)
{
double price =iMA(NULL,0,1,0,1,MA_Price,pos);
double price1 =iMA(NULL,0,1,0,1,MA_Price,pos+1);
if(pos==Bars-2) ExtMapBuffer[pos+1]=price1;
ExtMapBuffer[pos]=p1*price+p2*ExtMapBuffer[pos+1]-p3*ExtMapBuffer[pos+2];
pos--;
}
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| BatMA // gaussian3pole filter
//+------------------------------------------------------------------+
void GF3pole(double Kf)
{
double p=2.0/(MA_Period+1);
double p1,p2,p3,p4;
int pos=Bars-2;
p1=Kf*Kf*Kf;
p2=3.0*(1-Kf);
p3=3.0*(1-Kf)*(1-Kf);
p4=(1-Kf)*(1-Kf)*(1-Kf);
if(ExtCountedBars>2) pos=Bars-ExtCountedBars-1;
//---- main calculation loop
while(pos>=0)
{
double price =iMA(NULL,0,1,0,1,MA_Price,pos);
double price1 =iMA(NULL,0,1,0,1,MA_Price,pos+1);
if(pos==Bars-2) ExtMapBuffer[pos+1]=price1;
ExtMapBuffer[pos]=p1*price+p2*ExtMapBuffer[pos+1]-p3*ExtMapBuffer[pos+2]+p4*ExtMapBuffer[pos+3];
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
---