//+------------------------------------------------------------------+ //| Custom Moving Average.mq4 | //| Copyright © 2004, MetaQuotes Software Corp. | //| Copyright © 2008, YUBA | //| http://www.metaquotes.net/ | //+------------------------------------------------------------------+ //mod batma ma+ 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 2 #property indicator_color1 Blue #property indicator_color2 OrangeRed //---- indicator parameters extern int Bat_Period = 10; extern int Bat_Shift =0; extern bool _3poleFilter = false;//3/2-poleGaussianFilter"; extern bool Show_Bat = true; extern bool Show_MA = false; extern int MA_Period = 1; extern int MA_Method = 1; extern int MA_Price = 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"; //---- indicator buffers double ExtMapBuffer0[],ExtMapBuffer[], pr; //---- int ExtCountedBars=0; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { int draw_begin; //---- drawing settings IndicatorBuffers(2); SetIndexBuffer(0,ExtMapBuffer0); SetIndexBuffer(1,ExtMapBuffer); if (Show_Bat) SetIndexStyle(1,DRAW_LINE); else SetIndexStyle(1,DRAW_NONE); SetIndexShift(1,Bat_Shift); if (Show_MA) SetIndexStyle(0,DRAW_LINE); else SetIndexStyle(0,DRAW_NONE); IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)); if(Bat_Period<2) Bat_Period=2; draw_begin=Bat_Period-1; //---- indicator short name IndicatorShortName("Bat ("+Bat_Period+")"); // IndicatorShortName(short_name+BatMA_Period+")"); SetIndexDrawBegin(0,draw_begin); //---- indicator buffers mapping SetIndexLabel(0,"Bat"); SetIndexLabel(0,"MA"); //---- initialization done return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int start() { if(Bars<=Bat_Period) return(0); ExtCountedBars=IndicatorCounted(); //---- check for possible errors if (ExtCountedBars<0) return(-1); if (ExtCountedBars>0) ExtCountedBars--; //---- int limit=Bars-ExtCountedBars; for(int i=limit; i>=0; i--) ExtMapBuffer0[i]=iMA(NULL,0,MA_Period,0,MA_Method,MA_Price,i); pr=MathSqrt(2.0/(1.0+Bat_Period)); BatMa(pr); //---- done return(0); } //+------------------------------------------------------------------+ //| Batterwort Moving Average //gaussian 2&3pole filter | //+------------------------------------------------------------------+ void BatMa(double Kf) { double p=2.0/(Bat_Period+1); double p1,p2,p3,p4; int pos=Bars-2; if(ExtCountedBars>2) pos=Bars-ExtCountedBars-1; //---- main calculation loop while(pos>=0) { if(pos==Bars-2) ExtMapBuffer[pos+1]=ExtMapBuffer0[pos+1]; if(!_3poleFilter) { p1=Kf*Kf; p2=2.0*(1-Kf); p3=(1-Kf)*(1-Kf); ExtMapBuffer[pos]=p1*ExtMapBuffer0[pos]+p2*ExtMapBuffer[pos+1]-p3*ExtMapBuffer[pos+2]; } else { p1=Kf*Kf*Kf; p2=3.0*(1-Kf); p3=3.0*(1-Kf)*(1-Kf); p4=(1-Kf)*(1-Kf)*(1-Kf); ExtMapBuffer[pos]=p1*ExtMapBuffer0[pos]+p2*ExtMapBuffer[pos+1]-p3*ExtMapBuffer[pos+2]+p4*ExtMapBuffer[pos+3]; } pos--; } } //+------------------------------------------------------------------+
Sample
Analysis
Market Information Used:
Indicator Curves created:
Implements a curve of type DRAW_LINE
Implements a curve of type DRAW_NONE
Indicators Used:
Moving average indicator
Custom Indicators Used:
Order Management characteristics:
Other Features: