xpMA_v2FATL
Download scriptThe XP Moving Average is a versatile technical analysis tool designed to help traders visualize price trends and momentum by smoothing out market volatility. It functions as a multi-functional indicator that allows you to choose from several different calculation methods to determine how the "average" price of an asset should be displayed on your chart.
Core Functionality
At its heart, the script calculates a moving average based on a specific time period and a specific price point (such as the closing price, the opening price, or a combination of high/low prices). However, unlike standard indicators that only offer one type of calculation, this script provides a comprehensive suite of mathematical models:
- Standard Calculations: It supports basic moving averages like Simple (SMA), Exponential (EMA), Smoothed (SMMA), and Linear Weighted (LWMA).
- Advanced Smoothing: It includes more complex proprietary and high-performance models, including Double Exponential (DEMA), Triple Exponential (TEMA), T3 Moving Average, Jurik Moving Average (JMA), and the FATL Moving Average.
Dynamic Visual Logic
The script does not just plot a single line; it uses sophisticated logic to interpret the direction of the trend in real-time. It compares the current calculated value against the previous value to determine movement:
- Trend Detection: The indicator automatically monitors whether the average is rising or falling.
- Visual Differentiation: By analyzing these changes, the script manages three distinct visual buffers. When the average moves upward, it identifies the trend; when it moves downward, it captures that shift.
- Clean Display: It is designed to keep the chart organized by only displaying specific signals based on whether the price momentum is gaining or losing strength at any given moment.
User Customization
The logic is built to be highly adjustable, allowing users to define the "personality" of the indicator:
- Period: You can set how many past candles the average considers (e.g., a short period for fast reactions or a long period for identifying major trends).
- Calculation Type: You can switch between the various mathematical models mentioned above to find which one best fits the specific asset you are trading.
- Applied Price: You can choose which part of the candle's data (High, Low, Close, etc.) the indicator should focus on to generate its values.
In summary, this script acts as a sophisticated "trend filter" that offers a wide variety of mathematical lenses through which to view market movement, highlighting whether the current momentum is pushing prices higher or lower.
//+------------------------------------------------------------------+
//| XP Moving Average |
//| xpMA.mq4 |
//| Developed by Coders Guru |
//| 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
#define MODE_DEMA 4
#define MODE_TEMA 5
#define MODE_T3MA 6
#define MODE_JMA 7
#define MODE_FATL 8
/* 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_FATL 8 FATL 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 = MODE_FATL;
extern int MA_Applied = PRICE_CLOSE;
extern double T3MA_VolumeFactor = 0.8;
extern double JMA_Phase = 0;
double UpBuffer[];
double DownBuffer[];
double Buffer3[];
double buffer[];
double tempbuffer[];
double matriple[];
int init()
{
IndicatorBuffers(6);
SetIndexStyle(2,DRAW_LINE,STYLE_DOT,2);
SetIndexBuffer(2,UpBuffer);
SetIndexStyle(1,DRAW_LINE,STYLE_DOT,2);
SetIndexBuffer(1,DownBuffer);
SetIndexStyle(0,DRAW_LINE,STYLE_DOT,2);
SetIndexBuffer(0,Buffer3);
SetIndexBuffer(3,buffer);
SetIndexBuffer(4,tempbuffer);
SetIndexBuffer(5,matriple);
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--;
limit=Bars-counted_bars-1;
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_Applied,i);
}
}
break;
case 4:
{
for(i=0; i<limit; i++)
{
tempbuffer[i] = iMA(NULL,0,MA_Period,0,MODE_EMA,MA_Applied,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_Applied,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,"T3MA",MA_Period,T3MA_VolumeFactor,0,i);
}
}
case 7:
{
for(i=0; i<limit; i++)
{
buffer[i] = iCustom(NULL,0,"JMA",MA_Period,JMA_Phase,0,i);
}
}
case 8:
{
for(i=0; i<limit; i++)
{
buffer[i] = iCustom(NULL,0,"FATL",MA_Period,JMA_Phase,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] = CLR_NONE;
DownBuffer[shift] = CLR_NONE;
}
}
return(0);
}
Comments