ColorOsMA_v3

ColorOsMA_v3

This tool is a specialized technical analysis indicator designed to provide visual clarity on market momentum by combining and refining several classic trading concepts into one streamlined display. Instead of looking at standard price movements alone, this script calculates the relationship between different moving averages to identify trends and potential turning points.

How the Logic Works

The indicator operates through a three-step mathematical process:

1. Momentum Detection The script first calculates a "MACD" (Moving Average Convergence Divergence) value. It does this by comparing two different types of moving averages—one that reacts quickly to price changes and one that reacts more slowly. By subtracting the slow average from the fast one, the tool determines the current strength and direction of the market's momentum.

2. Signal Smoothing To filter out "market noise" (minor, insignificant price fluctuations), the script takes that momentum value and applies a secondary smoothing calculation (a Simple Moving Average). This creates a "Signal Line," which acts as a baseline to help identify the overall trend more reliably.

3. Dynamic Visualization (The Color Logic) The final step is where the data becomes user-friendly for visual trading. The script compares the raw momentum against the smoothed signal line:

  • Positive Momentum: If the momentum is higher than the signal line, the tool highlights this as upward movement (represented by a specific color).
  • Negative Momentum: If the momentum falls below the signal line, it highlights downward movement (represented by a different color).

Summary for the User

By using this logic, the indicator transforms complex calculations into a clear, color-coded histogram. Rather than forcing you to interpret multiple overlapping lines on a chart, it condenses that information into a single window where colors clearly signal whether the current trend strength is leaning bullish or bearish. This allows you to see at a glance whether the market's "pulse" is moving up or down relative to its recent history.

Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
ColorOsMA_v3
//+------------------------------------------------------------------+
//|                                                    ColorOsMA.mq4 |
//|                                                           duckfu |
//|                                         http://www.dopeness.org/ |
//+------------------------------------------------------------------+
#property  copyright "duckfu"
#property  link      "http://www.dopeness.org/"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 2
#property  indicator_color1  DodgerBlue
#property  indicator_color2  FireBrick
//---- indicator parameters
extern int FastEMA=8;
extern int SlowEMA=12;
extern int SignalSMA=9;
//---- indicator buffers
double OsMAUpBuffer[];
double OsMADownBuffer[];
double OsMABuffer[];
double MACDBuffer[];
double SignalBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 2 additional buffers are used for counting.
   IndicatorBuffers(5);
//---- drawing settings
   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2);
   SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,2);
   SetIndexDrawBegin(0,SignalSMA);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);
//---- 3 indicator buffers mapping
   if(!SetIndexBuffer(0,OsMAUpBuffer) &&
      !SetIndexBuffer(1,OsMADownBuffer) &&
      !SetIndexBuffer(2,OsMABuffer) &&
      !SetIndexBuffer(3,MACDBuffer) &&
      !SetIndexBuffer(4,SignalBuffer))
      Print("cannot set indicator buffers!");
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("ColorOsMA("+FastEMA+","+SlowEMA+","+SignalSMA+")");
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Moving Average of Oscillator                                     |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
//---- 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++)
     {
      MACDBuffer[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
     }
//---- signal line counted in the 2-nd additional buffer
     for(i=0; i<limit; i++)
     {
      SignalBuffer[i]=iMAOnArray(MACDBuffer,Bars,SignalSMA,0,MODE_SMA,i);
     }
//---- main loop
     for(i=0; i<limit; i++)
     {
      OsMABuffer[i]=(MACDBuffer[i]-SignalBuffer[i]);
        if(OsMABuffer[i]>0)
        {
         OsMAUpBuffer[i]=OsMABuffer[i];
         OsMADownBuffer[i]=0;
         }
         else if(OsMABuffer[i]<0)
         {
            OsMADownBuffer[i]=OsMABuffer[i];
            OsMAUpBuffer[i]=0;
            }
            else
            {
         OsMAUpBuffer[i]=0;
         OsMADownBuffer[i]=0;
        }
     }
//---- done
   return(0);
  }
//+------------------------------------------------------------------+

Comments