Author: T.Y
AO2

This custom technical indicator is designed to provide traders with a visual representation of market momentum by analyzing price trends through two distinct layers of moving averages. Instead of looking at the raw, volatile price action, this tool smooths out the data to identify the underlying direction of the market.

Core Logic and Functionality

The script operates on a dual-layered logic system, essentially creating "fast" and "slow" momentum signals that are displayed simultaneously in a separate window on your chart.

1. The Dual-Layer Momentum Analysis The indicator calculates two different types of momentum:

  • Short-Term Momentum: This layer reacts quickly to recent price changes, helping to identify immediate shifts in sentiment.
  • Long-Term (Magnified) Momentum: This layer uses a "magnification" factor based on the timeframe you are currently viewing (e.g., 1-minute vs. 4-hour charts). By adjusting the sensitivity automatically according to your timeframe, it provides a broader view of the current trend, filtering out minor market noise.

2. Dynamic Timeframe Adaptation One of the key features of this logic is its intelligence regarding timeframes. The script automatically recognizes which period you are trading and adjusts the "Magnification" accordingly. For example, it applies a different weight to the data on a 1-minute chart compared to a 4-hour chart. This ensures that the indicator remains relevant and readable regardless of whether you are scalping short-term moves or swing trading long-term trends.

3. Visual Signal Representation The script translates these mathematical calculations into four distinct visual bars (histograms):

  • Positive Momentum: When the current momentum value is higher than the previous one, the indicator draws an upward-facing histogram.
  • Negative Momentum: When the momentum drops below the previous value, it shifts to a downward-facing histogram.

How to Interpret the Results

By looking at the different colors and widths of the bars, a trader can differentiate between immediate "fast" price action and the broader "slow" trend.

  • When both layers move in the same direction (e.g., both showing upward momentum), it suggests strong confirmation of the current trend.
  • When the fast momentum moves against the long-term magnified trend, it may indicate a temporary pullback or a potential exhaustion of the current move.

In summary, this tool serves as a visual "speedometer" for the market, smoothing out the erratic movements of price to show you exactly how fast and in what direction the momentum is traveling at any given moment.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
17 Views
0 Downloads
0 Favorites
AO2
//+------------------------------------------------------------------+
//|                                                          AO2.mq4 |
//|                                                              T.Y |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "T.Y"
#property link      "http://www.metaquotes.net"

#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 RoyalBlue
#property indicator_color2 PaleVioletRed
#property indicator_color3 Aqua
#property indicator_color4 Red
#property indicator_width1 5
#property indicator_width2 5
#property indicator_width3 3
#property indicator_width4 3

extern int Magnification = 0;

double Buf0[], Buf1[];
double Buf2[], Buf3[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
    SetIndexBuffer(0, Buf0);
    SetIndexBuffer(1, Buf1);
    SetIndexBuffer(2, Buf2);
    SetIndexBuffer(3, Buf3);
    SetIndexStyle(0, DRAW_HISTOGRAM);
    SetIndexStyle(1, DRAW_HISTOGRAM);
    SetIndexStyle(2, DRAW_HISTOGRAM);
    SetIndexStyle(3, DRAW_HISTOGRAM);

    if(Magnification>0)     return(0);
   int tf = Period();
   if(tf==1)    Magnification = 10;    
   if(tf==5)    Magnification = 6;  
   if(tf==15)   Magnification = 4;  
   if(tf==30)   Magnification = 4;  
   if(tf==60)   Magnification = 4;  
   if(tf==240)  Magnification = 6;      
    return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
    int    counted_bars = IndicatorCounted();
    int    limit        = Bars - counted_bars;
    double ao1, ao2;

    if(limit==Bars)     limit -= (34*Magnification+1);
    for(int i=limit-1; i>=0; i--){  
        ao1 = iMA(NULL, 0, 5,  0, MODE_SMA, PRICE_MEDIAN, i)   
            - iMA(NULL, 0, 34, 0, MODE_SMA, PRICE_MEDIAN, i);
        ao2 = iMA(NULL, 0, 5,  0, MODE_SMA, PRICE_MEDIAN, i+1)
            - iMA(NULL, 0, 34, 0, MODE_SMA, PRICE_MEDIAN, i+1);
        if(ao1>ao2){
            Buf2[i] = ao1;
            Buf3[i] = 0.0;
        }else{
            Buf2[i] = 0.0;
            Buf3[i] = ao1;
        }
        ao1 = iMA(NULL, 0, Magnification*5,  0, MODE_SMA, PRICE_MEDIAN, i)   
            - iMA(NULL, 0, Magnification*34, 0, MODE_SMA, PRICE_MEDIAN, i);
        ao2 = iMA(NULL, 0, Magnification*5,  0, MODE_SMA, PRICE_MEDIAN, i+1)
            - iMA(NULL, 0, Magnification*34, 0, MODE_SMA, PRICE_MEDIAN, i+1);
        if(ao1>ao2){
            Buf0[i] = ao1;
            Buf1[i] = 0.0;
        }else{
            Buf0[i] = 0.0;
            Buf1[i] = ao1;
        }
    }
    
    return(0);
  }
//+------------------------------------------------------------------+

Comments