xpMA_v2_SATL_FATL_T3

Download script
xpMA_v2_SATL_FATL_T3

This script is a versatile technical analysis tool designed to calculate and display various types of Moving Averages (MA) on a trading chart. Its primary purpose is to smooth out price fluctuations, helping traders identify the underlying trend of an asset more clearly.

Core Functionality

The tool provides a comprehensive suite of moving average calculations in one package. Depending on your preference, it can calculate standard averages or more complex mathematical models, including:

  • Standard Averages: Simple (SMA), Exponential (EMA), Smoothed (SMMA), and Linear Weighted (LWMA).
  • Advanced Derivatives: Double Exponential (DEMA), Triple Exponential (TEMA), and several specialized types like T3, Jurik (JMA), SATL, and FATL.

Key Features & Logic

1. Customizable Input Parameters The script allows users to tailor the moving average to specific trading styles through several adjustable settings:

  • Period: Determines how many previous data points are used to calculate the average (e.g., a 34-period average).
  • MA Type: Allows you to switch between the different mathematical models listed above.
  • Applied Price: You can choose which price data the average should be based on, such as the Closing price, Opening price, Highs, Lows, or even weighted averages of these values.

2. Dynamic Trend Visualization Beyond simply drawing a line, the script includes logic to highlight the direction of the trend visually:

  • It compares the current value of the moving average against its previous value.
  • By identifying whether the average is currently rising or falling, it helps distinguish between bullish (upward) and bearish (downward) momentum.

3. Performance Optimization The script includes a "Max Bars to Count" feature. This ensures that the software remains responsive by limiting how much historical data it processes at one time, preventing unnecessary lag on charts with large amounts of history.

Summary for the User

Essentially, this tool acts as a multi-purpose trend tracker. It takes raw market noise and converts it into smooth, readable lines. By offering high-end mathematical averages (like DEMA or JMA) alongside standard ones, it provides both beginner and advanced traders with the flexibility to choose the specific "smoothness" and "responsiveness" that best fits their trading strategy.

Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
15 Views
0 Downloads
0 Favorites
xpMA_v2_SATL_FATL_T3
//+------------------------------------------------------------------+
//|                       XP Moving Average                          | 
//|                                                         xpMA.mq4 |
//|                                         Developed by Coders Guru |
//| mod2007forextsd.com      ki                http://www.xpworx.com |
//+------------------------------------------------------------------+

#property link      "http://www.xpworx.com"


#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Yellow
#property indicator_color2 Red
#property indicator_color3 Blue


/* Moving average types constants:
------------------------------------
MODE_SMA       0     Simple moving average, 
MODE_EMA       1     Exponential moving average, 
MODE_SMMA      2     Smoothed moving average, 
MODE_LWMA      3     Linear weighted moving average.
MODE_DEMA      4     Double Exponential Moving Average. 
MODE_TEMA      5     Triple Exponential Moving Average.
MODE_T3MA      6     T3 Moving Average. 
MODE_JMA       7     Jurik Moving Average. 
MODE_SATL      8     SATL Moving Average.
MODE_FATL      8     FATL (RFTL) Moving Average.

------------------------------------*/

/* Applied price constants:
-------------------------------
PRICE_CLOSE    0     Close price. 
PRICE_OPEN     1     Open price. 
PRICE_HIGH     2     High price. 
PRICE_LOW      3     Low price. 
PRICE_MEDIAN   4     Median price, (high+low)/2. 
PRICE_TYPICAL  5     Typical price, (high+low+close)/3. 
PRICE_WEIGHTED 6     Weighted close price, (high+low+close+close)/4.
--------------------------------- */

 
extern   int      MA_Period               = 34;
extern   int      MA_Type                 = 0;
extern   int      MA_Mode                 = 0;
extern   int      MA_AppliedPrice         = PRICE_CLOSE;
extern   double   T3b                    = 0.618;
extern   double   JMA_Phase               = 0;
extern   int      MaxBarsToCount          = 900;
extern string  note__MA_Type_Mode ="SMA0 EMA1 SMMA2 LWMA3 DEMA4 TEMA5 T3MA6 JMA7 SATL8 FATL9";
extern string  MA_Price_ ="0C 1O 2H3L 4Md 5Tp 6WghC: Md(HL/2)4,Tp(HLC/3)5,Wgh(HLCC/4)6";

double UpBuffer[];
double DownBuffer[];
double Buffer3[];
double buffer[];
double tempbuffer[];
double matriple[];

int init()
{
 string short_name;

   IndicatorBuffers(6); 

   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,UpBuffer);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,DownBuffer);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(3,Buffer3);
   SetIndexBuffer(0,buffer);
   SetIndexBuffer(4,tempbuffer);
   SetIndexBuffer(5,matriple);

   switch(MA_Type)
     {
      case 1 : short_name= " EMA(" ; break;
      case 2 : short_name= " SMMA("; break;
      case 3 : short_name= " LWMA("; break;
      case 4 : short_name= " DEMA("; break;
      case 5 : short_name= " TEMA("; break;
      case 6 : short_name= " T3MA("; break;
      case 7 : short_name= " JMA(" ; break;
      case 8 : short_name= " SATL("; break;
      case 9 : short_name= " FATL("; break;
      default: short_name= " SMA(" ;
     }

   SetIndexLabel(0,"xpMA "+short_name +" ("+ MA_Period+") ");
   IndicatorShortName( "xpMA "+short_name +" ("+ MA_Period+")");


   return(0);
}

int deinit()
{
   return(0);
}



void start()
{
   int limit;
   int i = 0;
   
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
//  if(counted_bars<0) return(-1);
//   limit=Bars-counted_bars-1;
   limit=Bars-counted_bars;
   limit=MathMin(limit,MaxBarsToCount);  

   switch (MA_Type)
   {
      case 0:
      case 1:
      case 2:
      case 3:
            {
                  for(i=0; i<limit; i++)
                  {
                     buffer[i] = iMA(NULL,0,MA_Period,0,MA_Type,MA_AppliedPrice,i);
                  }
            }
            break;
      
      case 4:
            {
                  for(i=0; i<limit; i++)
                  {
                     tempbuffer[i] = iMA(NULL,0,MA_Period,0,MODE_EMA,MA_AppliedPrice,i);
                  }
                  for(i=0; i<limit; i++)
                  {
                     matriple[i] = iMAOnArray(tempbuffer,0,MA_Period,0,MODE_EMA,i);
                  }
                  for(i=0; i<limit; i++)
                  {
                     buffer[i] = iMAOnArray(matriple,0,MA_Period,0,MODE_EMA,i);
                  }
            }
            break;
      
      case 5:
            {
                  for(i=0; i<limit; i++)
                  {
                     tempbuffer[i] = iMA(NULL,0,MA_Period,0,MODE_EMA,MA_AppliedPrice,i);
                  }
                  for(i=0; i<limit; i++)
                  {
                     buffer[i] = iMAOnArray(tempbuffer,0,MA_Period,0,MODE_EMA,i);
                  }
            }
            break;
      
      case 6:
            {
                  for(i=0; i<limit; i++)
                  {
                     buffer[i] = iCustom(NULL,0,"T3_clean",MA_Period,MA_AppliedPrice,T3b,0,i);
                  }
            }
             break;
      case 7:
            {
                  for(i=0; i<limit; i++)
                  {
                     buffer[i] = iCustom(NULL,0,"JMA",MA_Period,JMA_Phase,0,i);
                  }
            }
             break;
        
      case 8:
            {
                  for(i=0; i<limit; i++)
                  {
                     buffer[i] = iCustom(NULL,0,"SATL",0,i);
                  }
             }     
             break;
      case 9:
            {
                  for(i=0; i<limit; i++)
                  {
                     buffer[i] = iCustom(NULL,0,"RFTL",MaxBarsToCount,0,i);
                  }
             }
                
            
            break;
   }

   for(int shift=0; shift<limit; shift++)
   {
       UpBuffer[shift] = buffer[shift];
       DownBuffer[shift] = buffer[shift];
       Buffer3[shift] = buffer[shift];
   }                   
   for(shift=0; shift<limit; shift++)
   {
      if (buffer[shift]<buffer[shift+1])
      {
         UpBuffer[shift] = EMPTY_VALUE;
      }
      else if (buffer[shift]>buffer[shift+1] )
      {
         DownBuffer[shift] = EMPTY_VALUE;
      } 
      else
      {
         UpBuffer[shift] = EMPTY_VALUE;
         DownBuffer[shift] = EMPTY_VALUE;
      }
   }
   
   return(0);
}



Comments