BatMA_MAx23poleGF

Download script
Author: Copyright � 2004, MetaQuotes Software Corp.,Copyright � 2008, YUBA
BatMA_MAx23poleGF

This custom technical indicator is designed to provide traders with a smoothed visualization of price action by combining two distinct mathematical approaches: a standard Moving Average and a sophisticated "Batterwort" (Gaussian) filter.

By integrating these two layers, the tool aims to reduce market "noise"—the random fluctuations that can often trigger false signals—while maintaining a clearer view of the underlying price trend.

Core Components and Logic

1. Dual Layer Visualization The script handles two separate data lines on your chart simultaneously:

  • The Moving Average (MA): This acts as a baseline calculation. It follows the standard behavior of a moving average, which you can customize based on your preferred period, calculation method (such as Simple or Exponential), and price source.
  • The Batterwort Filter: This is the primary unique feature of the script. It takes the data from the Moving Average and subjects it to a Gaussian filtering process. Unlike standard averages that look back at a simple window of time, this filter uses specific mathematical coefficients to "smooth out" the curve more fluidly.

2. Advanced Filtering Options (2-Pole vs. 3-Pole) The logic allows for two different levels of smoothing intensity through the Gaussian filter:

  • Standard Smoothing (2-Pole): This is a balanced approach that reduces minor price vibrations while keeping the indicator relatively responsive to recent price changes.
  • Enhanced Smoothing (3-Pole): For markets with high volatility or heavy noise, this option applies a deeper mathematical filter. It looks further back into the data sequence to ensure the resulting line is exceptionally smooth, prioritizing the long-term trend over immediate, jagged price movements.

3. Dynamic Calculation Processing The script automatically calculates "weighting factors" based on the time period you select. As you increase the period, the math adjusts itself to ensure that the smoothing remains proportional to the timeframe. This ensures that whether you are looking at short-term scalping charts or long-term daily trends, the curve maintains its intended character.

Summary for the User

In practical terms, this tool allows you to see a "cleaned up" version of the market trend. While a standard moving average might appear jagged and jumpy, the Batterwort logic rounds off those sharp corners. Depending on your preference, you can toggle between different levels of smoothness to find the perfect balance between reacting quickly to new price information and ignoring the distractions of minor market fluctuations.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
11 Views
0 Downloads
0 Favorites
BatMA_MAx23poleGF
//+------------------------------------------------------------------+
//|                                        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--;
   }
 }
//+------------------------------------------------------------------+

Comments