Author: Mohammed
EMAOsMA

This tool is designed to provide traders with visual signals on their charts by analyzing price trends through a layered mathematical approach. Instead of looking at simple price movements, it uses a combination of moving averages to smooth out market "noise" and identify the underlying direction of the trend.

How the Logic Works

1. Data Processing (The Foundation) The script starts by calculating a specific type of smoothed average based on historical closing prices. This acts as the primary data source, filtering out minor fluctuations to reveal a clearer picture of where the price is headed.

2. Trend Smoothing (The Filter) Once the initial data is gathered, the script applies a second layer of calculation (an Exponential Moving Average). By applying this to the previous results, the tool creates a highly refined "signal line." This helps ensure that the signals generated are based on sustained trends rather than temporary spikes in price.

3. Signal Generation (The Alerts) The core functionality of the script is its ability to detect "crossovers." It constantly monitors the relationship between the current value and the previous value of this refined signal line:

  • Buy Signals: When the signal line moves from a negative state to a positive state, the script identifies this as an upward momentum shift. It automatically places a Gold arrow below the price candle to alert you of a potential bullish move.
  • Sell Signals: Conversely, when the signal line moves from a positive state to a negative state, it identifies downward momentum. The script then places a Dark Green arrow above the price candle to indicate a potential bearish move.

Visual Experience

The tool is designed to be clean and automated. It manages its own visual elements by creating specific markers on the chart whenever a trend shift occurs. Additionally, it includes a cleanup routine that ensures custom objects are managed properly, keeping your trading workspace organized and free of unnecessary clutter.

In short, this script does the heavy lifting of calculating complex price averages in the background and translates that data into simple, actionable visual cues on your screen.

Indicators Used
Moving Average of OscillatorMoving average indicator
Miscellaneous
Implements a curve of type %1
23 Views
0 Downloads
0 Favorites
EMAOsMA
//+------------------------------------------------------------------+
//|                                                      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