iAnchMom_v1

Download script
iAnchMom_v1

This tool is designed to provide a visual representation of price momentum by measuring the relationship between two different types of moving averages. Rather than looking at raw price action, it focuses on how quickly the market is trending relative to its historical average.

How the Logic Works

The indicator calculates its value by comparing two distinct mathematical averages of the market's closing prices:

  1. The Fast Average: The script first identifies a "Fast" average (based on a very short period). This represents the most recent, immediate price movement.
  2. The Slow Average: It then calculates a "Slow" average using a significantly longer timeframe. This acts as a baseline, representing the broader, long-term trend of the market.

The Momentum Calculation

The core logic works by dividing the Fast Average by the Slow Average to determine the percentage difference between them.

  • Momentum Strength: By subtracting this result from the baseline and converting it into a percentage, the script creates a "Momentum" value.
  • Visual Interpretation: The resulting line shows you how much the current short-term price is deviating from the long-term trend. When the line moves upward, it indicates that recent price action is accelerating faster than the historical average. When it moves downward, it suggests the recent price action is weakening or pulling back relative to the broader trend.

Key Technical Features

  • Historical Depth: The script is configured to analyze a specific number of past bars (defaulting to 300) to ensure the calculations are grounded in sufficient historical context.
  • Smooth Visuals: The resulting data is plotted as a solid teal line in a separate window, allowing traders to see "waves" of momentum without the visual clutter of the main price chart.
  • Dynamic Scaling: The logic automatically adjusts to the available data on your chart, ensuring that the calculation remains consistent regardless of how much history you have loaded.
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
iAnchMom_v1
//+------------------------------------------------------------------+
//|                                                    iAnchMom.mq4  |
//|                                                                  |
//+------------------------------------------------------------------+


#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Teal

//---- input parameters
extern int EMA_period=3;
extern int MomPeriod=8;
extern int CountBars=300;
//---- buffers
double MomBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- indicator line
   IndicatorBuffers(1);
   SetIndexBuffer(0, MomBuffer);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2,Teal);
//---- name for DataWindow and indicator subwindow label
   short_name="iAnchMom("+MomPeriod+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
//----
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| AnchMom                                                         |
//+------------------------------------------------------------------+
int start()
  {
   if (CountBars>Bars) CountBars=Bars;
   SetIndexDrawBegin(0,Bars-CountBars+MomPeriod + MomPeriod + 1);
   int i,counted_bars=IndicatorCounted();
   double a,b;
   int SMA_Period = MomPeriod + MomPeriod + 1;

   if(Bars<=SMA_Period) return(0);

//---- initial zero
   if(counted_bars<1)
      for(i=1;i<=SMA_Period;i++) MomBuffer[Bars-i]=0.0;
//----
   i=CountBars-SMA_Period-1;
//   if(counted_bars>=SMA_Period) i=Bars-counted_bars-1;
   while(i>=0)
     {
      a = iMA(NULL,0,EMA_period,0, MODE_EMA,PRICE_CLOSE, i);
      b = iMA(NULL,0,SMA_Period,0, MODE_SMA, PRICE_CLOSE, i);
      MomBuffer[i]= 100*((a / b)-1);
                          

      i--;
     }
   return(0);
  }
//+------------------------------------------------------------------+

Comments