Ultimate_MA

Download script
Author: Copyright © 2007, MetaQuotes Software Corp.
Ultimate_MA

This script is designed to generate a sophisticated technical analysis indicator called the Ultimate Moving Average (UMA). Unlike standard moving averages that rely on a single timeframe, this logic combines three different timeframes—Fast, Middle, and Slow—to provide a more balanced view of market trends while reducing "noise" or false signals.

Data Foundation

The logic begins by establishing a baseline for the price action. Instead of just looking at the closing price, it calculates a weighted average of every candle's movement. It specifically looks at the open, high, low, and close prices, giving more weight to the center of the price action (the midpoint between open/close and high/low). This creates a smoother underlying data set for the remaining calculations.

Multi-Timeframe Integration

The core strength of this script lies in its three-layered approach:

  • Fast Component: Tracks immediate, short-term price changes.
  • Middle Component: Observes intermediate trends to bridge the gap between rapid moves and long-term shifts.
  • Slow Component: Monitors the broader, long-term market direction.

By merging these three layers, the script attempts to capture both the current momentum and the historical context simultaneously.

Dynamic Volatility Adjustment

A key feature of this logic is how it handles market volatility. The script incorporates an Average True Range (ATR) calculation for each of the three components.

Essentially, the indicator "knows" when the market is volatile. When price swings are large and erratic, the ATR values increase. The script uses these values to adjust the weight of each timeframe. If one timeframe becomes excessively volatile, it doesn't allow that volatility to over-influence the final result. Instead, it normalizes the data so that the indicator remains steady and provides a more reliable "smoothed" line on your chart.

Final Calculation

In the final step, the script takes the weighted results of all three timeframes (adjusted for their specific volatility) and divides them by a combined total. This produces a unified "Ultimate" value.

The result is a single moving average line that is designed to be responsive enough to catch trends early but stable enough to ignore temporary market fluctuations that often trick simpler indicators.

Indicators Used
Indicator of the average true rangeMoving average indicator
Miscellaneous
Implements a curve of type %1
14 Views
0 Downloads
0 Favorites
Ultimate_MA
ÿþ//+------------------------------------------------------------------+

//|                                                  Ultimate MA.mq4 |

//|                      Copyright © 2007, MetaQuotes Software Corp. |

//|                                        http://www.metaquotes.ru/ |

//+------------------------------------------------------------------+

#property copyright "Copyright © 2007, MetaQuotes Software Corp."

#property link      "http://www.metaquotes.ru/"

//----

#property indicator_chart_window

#property indicator_buffers 1

#property indicator_color1 MediumVioletRed



//---- input parameters

extern ENUM_MA_METHOD MA_Method = MODE_SMA;  // Method

extern int fastperiod=5;                     // Fast Period

extern int middleperiod=34;                  // Middle Period

extern int slowperiod=55;                    // Slow Period

extern int fastK=4;                          // Fast Multiplier

extern int middleK=2;                        // Middle Multiplier

extern int slowK=1;                          // Slow Multiplier

//---- buffers

double UOBuffer[];

double BPBuffer[];

double divider;

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int init()

  {

//---- indicators

   string name;

   name="UMA("+fastperiod+", "+middleperiod+", "+slowperiod+")";

   IndicatorBuffers(2);

   SetIndexStyle(0,DRAW_LINE,EMPTY);

   SetIndexBuffer(0,UOBuffer);

   SetIndexDrawBegin(0,slowperiod);

   SetIndexBuffer(1,BPBuffer);

   IndicatorShortName(name);

   IndicatorDigits(5);

   divider=fastK+middleK+slowK;

//----

   return(0);

  }

//+------------------------------------------------------------------+

//| Custom indicator deinitialization function                       |

//+------------------------------------------------------------------+

int deinit()

  {

//----

   return(0);

  }

//+------------------------------------------------------------------+

//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

int start()

  {

   int counted_bars=IndicatorCounted();

//----

   int i,limit,limit2;

   double RawUO;

   if(counted_bars==0)

     {

      limit=Bars-2;

      limit2=Bars-slowperiod;

     }

   if(counted_bars>0)

     {

      limit=Bars-counted_bars;

      limit2=limit;

     }

   for(i=limit; i>=0; i--)

     {

      BPBuffer[i]=(2*((Open[i]+Close[i])/2)+((High[i]+Low[i])/2))/3;

     }

   for(i=limit2; i>=0; i--)

     {

      RawUO=(fastK+3*iATR(NULL, 0, fastperiod, i))*iMAOnArray(BPBuffer,0,fastperiod,0,MA_Method,i)

            +(middleK+3*iATR(NULL, 0, middleperiod, i))*iMAOnArray(BPBuffer,0,middleperiod,0,MA_Method,i)

            +(slowK+3*iATR(NULL, 0, slowperiod, i))*iMAOnArray(BPBuffer,0,slowperiod,0,MA_Method,i);

            

      divider=(fastK+3*iATR(NULL, 0, fastperiod, i))+(middleK+3*iATR(NULL, 0, middleperiod, i))+(slowK+3*iATR(NULL, 0, slowperiod, i));

      UOBuffer[i]=RawUO/divider;

     }

//----

   return(0);

  }

//+------------------------------------------------------------------+

Comments