Author: Gregory A. Kakhiani
Gaus_MA

This technical indicator is designed to provide a highly sophisticated method of smoothing price data on a trading chart. Instead of using standard moving averages that can often be laggy or overly simplistic, this script utilizes a specialized mathematical approach known as a Radial Basis Function (specifically the Gaussian function) to determine how much influence past prices should have on the current trend.

Core Logic and Mechanism

1. Advanced Weighting System The primary strength of this logic lies in how it calculates "importance." In a standard moving average, every price point in a period might carry equal weight, or the weights might decrease linearly. This script uses an exponential formula to calculate coefficients. By adjusting specific parameters (Degree of Exponent and Power Coefficient), the user can define exactly how quickly the indicator "forgets" old data versus how much it prioritizes recent price action.

2. Dynamic Price Selection The tool is versatile in its data sourcing. It is not locked to just the closing price; it allows the user to calculate the smoothed average based on various price types, including:

  • Opening and Closing prices
  • Highs and Lows
  • Median (Average of High/Low)
  • Typical Price
  • Weighted Price

3. Volume Integration A key feature of the logic is the optional inclusion of trading volume. When enabled, the indicator doesn't just look at the price movement; it scales the smoothing weight based on how much trading activity occurred at that time. This helps in identifying "heavy" price moves supported by high volume versus "weak" moves on low liquidity.

4. Precise Smoothing Control The algorithm includes several administrative controls to fine-tune the visual output:

  • Period: Defines the look-back window for the calculation.
  • Smoothing Parameters (A and N): These are the "engine" of the Gaussian function, allowing for a custom curvature of the moving average line.
  • Shifts: The script allows for both a visual shift (moving the entire line forward or backward on the chart) and a coefficient shift (adjusting which part of the calculated weight curve is applied to the current price).

Summary for the User

Essentially, this indicator provides a "smoother" trend line that reacts more intelligently than standard tools. By utilizing Gaussian math, it attempts to filter out market noise more effectively, providing a clearer picture of the underlying price direction while giving you the flexibility to factor in volume and specific price types to suit your personal trading style.

Miscellaneous
Implements a curve of type %1
10 Views
0 Downloads
0 Favorites
Gaus_MA
//+-----------------------------------------------------------------------------+
//|                                                                 Gaus_MA.mq4 |
//|                                                         Gregory A. Kakhiani |
//|                                                         gkakhiani@gmail.com |
//+-----------------------------------------------------------------------------+
//Óñðåäíåíèå (Ñãëàæèâàíèå êðèâîé öåí) öåí ïðè ïîìîùè ìîäèôèöèðîâàííîãî àëãîðèòìà|
//ëèíåéíî-âçâåøåííîãî ñêîëüçÿùåãî ñðåäíåãî ãäå êîýôôèöèåíòû ñãëàæèâàíèÿ         |
//ðàñ÷èòûâàþòñÿ ïðè ïîìîùè ðàäèàëüíî-áàçèñíîé ôóíêöè (ôóíêöèÿ ãàóñà)            |
//+-----------------------------------------------------------------------------+
#property copyright "Gregory A. Kakhiani"
#property link      "gkakhiani@gmail.com"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red

//---- input parameters
extern int       period=10;      //Ïåðèîä óñðåäíåíèÿ 
extern double    N=2;            //Ñòåïåíü ýêñïîíåíòû
extern double    A=-0.001;       //Êîýôèöèåíò ñòåïåíè å
extern bool      Vol=false;      //Óìíîæèòü íà îáúåì
extern int       applied_price=0;//Èñïîëüçóåìàÿ öåíîâàÿ êîíñòàíòà - èñïîëüçóþòñÿ ñòàíäàðòíûå öåíîâûå êîíñòàíòû
extern int       ma_shift=0;     //Ñäâèã èíäèêàòîðà îòíîñèòåëüíî öåíîâîãî ãðàôèêà
extern int       koef_shift=0;   //Ñäâèã èíäåêñà ìàñèâà êîåôôèöèåíòîâ

//---- buffers
double GaussAverage[];

//Ãëîáàëüíûå ïåðåìåííûå
   int MaxBars=10000; //Êîëè÷åñòâî àíàëèçèðóåìûõ áàðîâ
    
   double Coefs[50]; //Ìàññèâ äëÿ õðàíåíèÿ êîýôôèöèåíòîâ
 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,GaussAverage);
   
    SetIndexLabel(0,"GaussAverage") ;

 if(applied_price>6) applied_price=0;

  //îôîðìëÿåì èíäèêàòîð  
 string applied_priceText="";
 switch(applied_price)
 {
  case PRICE_CLOSE:// 0 Öåíà çàêðûòèÿ
   {applied_priceText="Close";}break;   
  case PRICE_OPEN://1 Öåíà îòêðûòèÿ 
   {applied_priceText="Open";}break;
  case PRICE_HIGH://2 Ìàêñèìàëüíàÿ öåíà 
   {applied_priceText="High";}break;
  case PRICE_LOW://3 Ìèíèìàëüíàÿ öåíà 
   {applied_priceText="Low";}break;
  case PRICE_MEDIAN://4 Ñðåäíÿÿ öåíà, (high+low)/2 
   {applied_priceText="Median price";}break;
  case PRICE_TYPICAL://5 Òèïè÷íàÿ öåíà, (high+low+close)/3 
   {applied_priceText="Typical price";}break;
  case PRICE_WEIGHTED:// 6 Âçâåøåííàÿ öåíà çàêðûòèÿ, (high+low+close+close)/4 
   {applied_priceText="Weighted price";}break;
 }
    
    
   IndicatorShortName("GaussAverage("+A+","+N+","+period+","+applied_priceText+",koef_shift="+koef_shift+", Shift="+ma_shift+")");
    
    //Çàïîëíåíèå ìàññèâà êîýôèöèåíòîâ 
    CalcCoefs(A, N, period);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   //Ñîáñòâåííî ñãëàæèâàíèå   
   for(int i=MaxBars;i>=0;i--)
   {
    GaussAverage[i+ma_shift]=GetGausAverage(period, applied_price, Vol, koef_shift,i);
   }
//----
   return(0);
  }
  
  
//+------------------------------------------------------------------+
//Âîçâðàùàåò öåíó â çàâèñèìîñòè îò PriceType ñî ñäâèãîì Index        |
//+------------------------------------------------------------------+
double GetPrice(int Index,int PriceType)
{
 switch(PriceType)
 {
  case PRICE_CLOSE:// 0 Öåíà çàêðûòèÿ
   {return (Close[Index]);}
  case PRICE_OPEN://1 Öåíà îòêðûòèÿ 
   {return (Open[Index]);}
  case PRICE_HIGH://2 Ìàêñèìàëüíàÿ öåíà 
   {return (High[Index]);}
  case PRICE_LOW://3 Ìèíèìàëüíàÿ öåíà 
   {return (Low[Index]);}
  case PRICE_MEDIAN://4 Ñðåäíÿÿ öåíà, (high+low)/2 
   {return ((High[Index]+Low[Index])/2);}
  case PRICE_TYPICAL://5 Òèïè÷íàÿ öåíà, (high+low+close)/3 
   {return ((High[Index]+Low[Index]+Close[Index])/3);}
  case PRICE_WEIGHTED:// 6 Âçâåøåííàÿ öåíà çàêðûòèÿ, (high+low+close+close)/4 
   {return ((High[Index]+Low[Index]+Close[Index]+Close[Index])/4);}
  default:
   {return (Close[Index]);}
}
 return (0);
}


//+-----------------------------------------------------------------+
//Ôóíêöèÿ ñãëàæèâàíèÿ                                               |
//Ìîäèôèöèðîâàííûé àëãîðèòì ëèíåéíî-âçâåøåííîãî ñêîëüçÿùåãî ñðåäíåãî|
//+-----------------------------------------------------------------+
//AvPeriod - ïåðèîä ñãëàæèâàíèÿ                                     |
//applied_price - Èñïîëüçóåìàÿ öåíîâàÿ êîíñòàíòà                    |
//Vol - Óìíîæèòü íà îáúåì                                           |
//Sh - Ñäâèã                                                        |
//+-----------------------------------------------------------------+
double GetGausAverage(double AvPeriod, int applied_price, bool Vol, int koef_shift,int Sh)
{
 double sum=0; //Âðåìåííûå ïåðåìåííûå äëÿ ñóìì 
 double W=0;   //ó÷àñòâóþùèõ â èñëèòåëå è çíàìåíàòåëå
 
 for(int j=AvPeriod;j>=0;j--)
  {
   if(Vol==true)
    {
     sum+=GetPrice(Sh+j,applied_price)*Volume[Sh]*Coefs[j+koef_shift];
     W+=Coefs[j+koef_shift]*Volume[Sh];
    } else {
            sum+=GetPrice(Sh+j,applied_price)*Coefs[j+koef_shift]; 
            W+=Coefs[j+koef_shift];
           }
  }
 return (sum/W);
}

//
//+-----------------------------------------------------------------+
//Ðàñ÷¸ò êîýôôèöèåíòîâ äëÿ ðàäèàëüíî-áàçèñíîé ôóíêöèè ñãëàæèâàíèÿ   |
//+-----------------------------------------------------------------+
//AvPeriod - ïåðèîä ñãëàæèâàíèÿ                                     |
//A - Êîýôèöèåíò ñòåïåíè å                                          |
//N - Ñòåïåíü ýêñïîíåíòû                                            |
//+-----------------------------------------------------------------+
double CalcCoefs(double A, double N, double AvPeriod)
{
    //Ïðîâåðêà ïàðàìåòðîâ
    if(AvPeriod>=50) AvPeriod=49;
    if(MathAbs(N)>5) N=5;
    
    //Çàïîëíåíèå ìàññèâà êîåôôèöèåíòîâ
    for(int i=0;i<=AvPeriod;i++)
     Coefs[i]=MathExp(A*MathPow(i,N));     
 return (0);
}

Comments