Filter_AO

This script is a custom technical analysis tool designed to visualize and simplify market momentum by filtering the standard "Awesome Oscillator" data. Instead of showing a raw, fluctuating line that can be difficult to read at a glance, this tool categorizes price movements into distinct visual trends to help traders identify directional shifts more clearly.

Core Logic Overview

The script operates through three primary logical stages:

1. Momentum Calculation The foundation of the tool is based on the difference between two moving averages. It calculates a fast-moving average (representing recent price action) and subtracts a much slower-moving average (representing long-term price history). The resulting value represents the "momentum" of the market—essentially showing whether the current price is accelerating or decelerating compared to its historical norm.

2. Trend Direction Identification Once the momentum value is calculated, the script compares each new data point against the previous one. It looks for a "break" in the trend:

  • If the momentum is rising, it identifies an upward trend.
  • If the momentum is falling, it identifies a downward trend.

3. Visual Filtering and Separation The most unique feature of this script is how it handles the visual output. Rather than displaying all data in one continuous line, it splits the information into two separate histograms:

  • Bullish Momentum: When the market shows upward movement, the tool populates a lime-colored histogram.
  • Bearish Momentum: When the market shows downward movement, it switches to a red-colored histogram.

By zeroing out the opposing color during specific movements, the script eliminates visual "noise." This allows a trader to see exactly when momentum has shifted from positive to negative (or vice versa) without the distraction of overlapping data, providing a cleaner representation of whether the market is currently gaining or losing strength.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
10 Views
0 Downloads
0 Favorites
Filter_AO
//+------------------------------------------------------------------+
//|                                                    Filter_AO.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2004, MetaQuotes Software Corp."
#property  link      "http://www.metaquotes.net/"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 2
#property  indicator_color1  Lime
#property  indicator_color2  Red
//---- indicator buffers
double     ind_buffer1[];
double     ind_buffer2[];
double     ind_buffer3[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 1 additional buffer used for counting.
   IndicatorBuffers(3);
//---- drawing settings
   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2);
   SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,2);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
   SetIndexDrawBegin(0,34);
   SetIndexDrawBegin(1,34);
//---- 3 indicator buffers mapping
   if(!SetIndexBuffer(0,ind_buffer1) &&
      !SetIndexBuffer(1,ind_buffer2) &&
      !SetIndexBuffer(2,ind_buffer3))
      Print("cannot set indicator buffers!");
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("Filter_AO");
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Awesome Oscillator                                               |
//+------------------------------------------------------------------+
int start()
  {
   int    limit;
   int    counted_bars=IndicatorCounted();
   double prev,current;
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//---- macd counted in the 1-st additional buffer
   for(int i=0; i<limit; i++)
      ind_buffer3[i]=iMA(NULL,0,15,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,102,0,MODE_EMA,PRICE_CLOSE,i);
//---- dispatch values between 2 buffers
   bool up=true;
   for(i=limit-1; i>=0; i--)
     {
      current=ind_buffer3[i];
      prev=ind_buffer3[i+1];
      if(current>prev) up=true;
      if(current<prev) up=false;
      if(!up)
        {
         ind_buffer2[i]=current;
         ind_buffer1[i]=0.0;
        }
      else
        {
         ind_buffer1[i]=current;
         ind_buffer2[i]=0.0;
        }
     }
//---- done
   return(0);
  }
//+------------------------------------------------------------------+

Comments