Author: Mohammed
EMAOsMA_v2

This script is designed as a technical analysis tool for the MetaTrader platform, specifically created to identify potential trend shifts and price momentum by calculating a specialized moving average sequence.

Core Logic Overview

The primary function of this indicator is to filter out "market noise" by analyzing price data through two distinct layers of mathematical processing. Instead of looking at raw price movements, it transforms the data into a smoothed trend line and then applies a secondary smoothing layer on top of that result.

How It Works Step-by-Step

  1. Primary Data Processing (OsMA): The script first calculates a specific type of moving average known as OsMA. This serves as the foundation for the indicator, capturing the underlying momentum of the asset.
  2. Secondary Smoothing (EMA): The script then takes that OsMA data and applies an Exponential Moving Average (EMA) to it. By doing this, the indicator produces a much smoother line that reacts to significant trends while ignoring minor, insignificant price fluctuations.
  3. Trend Detection: The system constantly monitors the value of this final smoothed line. It looks for specific "cross-over" points where the line moves from a negative value to a positive value (or vice versa).

Visual Signals

To make these mathematical transitions easy for a trader to see, the script automatically places visual markers on the chart:

  • Upward Signals: When the smoothed trend line crosses from below zero to above zero, the script places a Gold arrow at the bottom of the price candle. This suggests a potential shift toward bullish momentum.
  • Downward Signals: When the smoothed trend line crosses from above zero to below zero, the script places a Dark Green arrow at the top of the price candle. This suggests a potential shift toward bearish momentum.

Summary for the User

Essentially, this tool acts as a "trend filter." It takes complex price movements, smooths them out twice to find the true direction of the market, and alerts you with visual arrows whenever that trend undergoes a significant change in polarity.

Indicators Used
Moving Average of OscillatorMoving average indicator
Miscellaneous
Implements a curve of type %1
21 Views
0 Downloads
0 Favorites
EMAOsMA_v2
//+------------------------------------------------------------------+
//|                                                      EMAOsMA.mq4 |
//|                                                         Mohammed |
//|                                         http://www.forex-tsd.com |
//+------------------------------------------------------------------+
#property copyright "Mohammed"
#property link      "http://www.forex-tsd.com"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
//----
extern int EmaPeriod=12;
extern color UpCross=Gold;
extern color DownCross=DarkGreen;
extern int ArrowCode1=233;
extern int ArrowCode2=234;
//---- buffers
double ExtMapBuffer1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);
//----
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
//----
   int I=WindowsTotal();
   for(int count=0; count < WindowsTotal(); count++)
     {
      int nObjects=ObjectsTotal();
      for(int i=nObjects; i>=0; i--)
        {
         string objName=ObjectName(i);
         if(StringFind(objName, "acustom", 0)>=0)
            ObjectDelete(objName);
        }
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   int I=WindowsTotal();
   for(int count=0; count < WindowsTotal(); count++)
     {
      int nObjects=ObjectsTotal();
      for(int i=nObjects; i>=0; i--)
        {
         string objName=ObjectName(i);
         if(StringFind(objName, "acustom", 0)>=0)
            ObjectDelete(objName);
        }
     }
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
  void DrawArrow( int bar , double value , int trend)
  {
   static int cnt=0;
   cnt++;
   string crossing="acustom_" + cnt;
//----
   ObjectCreate(crossing, OBJ_ARROW, 0, Time[bar], value);
//----
   if(trend==1)
     {
      ObjectSet(crossing, OBJPROP_ARROWCODE, ArrowCode1);
      ObjectSet(crossing, OBJPROP_COLOR , UpCross);
     }
   if(trend==2)
     {
      ObjectSet(crossing, OBJPROP_ARROWCODE, ArrowCode2);
      ObjectSet(crossing, OBJPROP_COLOR , DownCross);
     }
   ObjectSet(crossing, OBJPROP_WIDTH  , 1);
   ObjectsRedraw();
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int i, limit;
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   limit=Bars-IndicatorCounted();
//----
   double marray[];
//----
   ArrayResize( marray, limit);
   ArraySetAsSeries(marray,true);
//----
   for(i=0; i<limit; i++)
     {
      marray[i]=iOsMA(NULL,0,10,26,9,PRICE_CLOSE,i);
      ExtMapBuffer1[i]=marray[i];
     }
   for(i=0; i<limit; i++)
     {
      ExtMapBuffer1[i]=iMAOnArray(marray,limit,EmaPeriod,0,MODE_EMA,i);
     }
   while(limit>0)
     {
      if (ExtMapBuffer1[limit] > 0 && ExtMapBuffer1[limit+1] < 0)
         DrawArrow (limit , Low[limit] - 1 * Point , 1);
      if (ExtMapBuffer1[limit] < 0 && ExtMapBuffer1[limit+1] > 0)
         DrawArrow (limit , High[limit] + 5 * Point , 2);
      limit--;
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments