OsMA_v1

This script is designed as a specialized visual tool for financial charts, intended to help traders identify momentum and potential trend reversals by layering three different types of mathematical calculations. Instead of showing raw price movements, it creates a unique "Oscillator" that smooths out market noise to reveal the underlying strength of a trend.

How the Logic Works

The indicator operates through a three-step process of filtering and refining data:

1. Identifying Initial Momentum (MACD Foundation) The script begins by comparing two different types of moving averages: a "fast" average and a "slow" average. By calculating the difference between these two, it determines the immediate momentum of the price. If the fast average is significantly higher than the slow one, it indicates upward pressure; if lower, it suggests downward pressure.

2. Creating a Smoothing Signal To ensure that the data isn't too erratic or "choppy" for a trader to read easily, the script takes the result from the first step and applies a second layer of smoothing. This creates a "Signal Line." Think of this as a steady baseline that represents the average trend over a specific period, helping to filter out minor price fluctuations that might otherwise cause false signals.

3. Generating the Final Oscillator (OsMA) The final output shown on your chart is produced by subtracting this new Signal Line from the initial momentum value. This "Difference of Differences" results in the OsMA (Oscillator Moving Average).

What this means for the Trader

By using this multi-layered logic, the tool provides a clearer picture than standard indicators might offer alone:

  • Trend Strength: The height and direction of the histogram indicate how aggressively the price is moving.
  • Smoothing: Because it uses three layers of calculation (Fast EMA, Slow EMA, and Signal SMA), it is designed to be more stable and less reactive to "market noise" than a standard MACD.
  • Visual Clarity: The final result is displayed as a histogram in a separate window below your main chart, making it easier to spot where momentum is peaking or starting to fade.
Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
14 Views
0 Downloads
0 Favorites
OsMA_v1
//+------------------------------------------------------------------+
//|                                                         OsMA.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 1
#property  indicator_color1  Silver
#property  indicator_width1  2
//---- indicator parameters
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
//---- indicator buffers
double     OsmaBuffer[];
double     MacdBuffer[];
double     SignalBuffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 2 additional buffers are used for counting.
   IndicatorBuffers(3);
//---- drawing settings
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexDrawBegin(0,SignalSMA);
   IndicatorDigits(Digits+2);
//---- 3 indicator buffers mapping
   SetIndexBuffer(0,OsmaBuffer);
   SetIndexBuffer(1,MacdBuffer);
   SetIndexBuffer(2,SignalBuffer);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("OsMA("+FastEMA+","+SlowEMA+","+SignalSMA+")");
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Moving Average of Oscillator                                     |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
//---- 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];
//---- done
   return(0);
  }
//+------------------------------------------------------------------+

Comments