OsMA_Color2Alert

Download script
OsMA_Color2Alert

This script functions as a custom visual indicator for the MetaTrader trading platform. It is designed to simplify the interpretation of market momentum by taking a standard technical analysis tool (the Awesome Oscillator) and adding a sophisticated color-coding system to help traders identify trend shifts more clearly.

Core Logic Overview

The primary goal of this script is to track the "momentum" of a price movement and translate that data into four distinct visual states. Instead of just showing a single fluctuating line, it separates the data into different categories based on whether the momentum is moving upward or downward, and whether that momentum is positive or negative relative to the zero line.

How the Data is Processed

  1. Base Calculation: The script begins by calculating a standard Awesome Oscillator using three adjustable timeframes (Fast, Slow, and Signal). This provides the raw "momentum" data used for all subsequent steps.
  2. Trend Direction Analysis: The script looks at the relationship between the current momentum value and the previous one. It determines if the momentum is accelerating (increasing) or decelerating (decreasing).
  3. Momentum Filtering: By comparing these movements against the zero line, the script categorizes the market activity into four specific scenarios:
    • Strong Upward Momentum: Highlighted to show active growth.
    • Weakening Upward Momentum: Highlighting a slowdown in a positive trend.
    • Strong Downward Momentum: Highlighting active decline.
    • Weakening Downward Momentum: Highlighting a slowdown in a negative trend.

Visual Representation

The indicator displays these results as a series of colored histograms in a separate window on your chart. This allows you to see at a glance not just where the price is going, but the strength and health of that movement:

  • Lime Green / Green: Represent different intensities of upward movement.
  • Red / Maroon: Represent different intensities of downward movement.

Automated Notifications

The script also includes a "Change Detection" logic. It constantly monitors the colors of these histograms. If the momentum shifts from an "upward" state to a "downward" state (or vice versa), the script can automatically trigger notifications. Depending on your personal settings, it can provide these alerts via:

  • On-screen pop-ups: Immediate visual and audio alerts within the platform.
  • Email notifications: Sending an alert directly to your registered email address.

This logic essentially acts as a "momentum filter," stripping away market noise to highlight the most significant shifts in trend strength, making it easier for a trader to identify when a move is gaining steam or beginning to exhaust itself.

Indicators Used
Moving Average of Oscillator
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screenIt sends emails
11 Views
0 Downloads
0 Favorites
OsMA_Color2Alert
//+------------------------------------------------------------------+
//|                                                         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 4
#property  indicator_color1  LimeGreen
#property  indicator_color2  Green
#property  indicator_color3  Red
#property  indicator_color4  Maroon

//#property  indicator_level1  0.0003
//#property  indicator_level2  -0.0003

//---- indicator buffers
extern int FastEMA=40;
extern int SlowEMA=50;
extern int SignalSMA=100;
extern bool AlertOn = false;
extern bool EmailOn = false;


double     ind_buffer1[], ind_buffer1s[];
double     ind_buffer2[], ind_buffer2s[];
double     ind_buffer3[];



bool NewBar() {

	static datetime LastTime = 0;

	if (Time[0] != LastTime) {
		LastTime = Time[0];		
		return (true);
	} else
		return (false);
}





//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 1 additional buffer used for counting.
   IndicatorBuffers(5);
   //---- drawing settings
   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,4);
   SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,4);
   SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,4);
   SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID,4);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
   SetIndexDrawBegin(0,34);
   SetIndexDrawBegin(1,34);
   SetIndexDrawBegin(3,34);
   SetIndexDrawBegin(4,34);
//---- 3 indicator buffers mapping
   if(!SetIndexBuffer(0,ind_buffer1) &&
      !SetIndexBuffer(1,ind_buffer1s) &&
      !SetIndexBuffer(2,ind_buffer2) &&
      !SetIndexBuffer(3,ind_buffer2s) &&
      !SetIndexBuffer(4,ind_buffer3))
      Print("cannot set indicator buffers!");
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("OsMA("+FastEMA+","+SlowEMA+","+SignalSMA+")");
//---- 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]=iOsMA(NULL,0,FastEMA,SlowEMA,SignalSMA,PRICE_WEIGHTED,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<0)&&(prev>0))||(current<0))   up= false;    
      if (((current>0)&&(prev<0))||(current>0))   up= true;  
      
      if(!up)
        {
         if(current > prev)
           {
            ind_buffer2s[i]=current;
            ind_buffer2[i]=0.0;
            ind_buffer1[i]=0.0;
            ind_buffer1s[i]=0.0;             
           }        
         else
           {
            ind_buffer2[i]=current;
            ind_buffer2s[i]=0.0;
            ind_buffer1[i]=0.0;
            ind_buffer1s[i]=0.0;            
           }             
        }
        else
        {
         if(current < prev)
           {
            ind_buffer1s[i]=current;
            ind_buffer1[i]=0.0;
            ind_buffer2[i]=0.0;
            ind_buffer2s[i]=0.0;
           }
        else
           {
            ind_buffer1[i]=current;
            ind_buffer1s[i]=0.0;
            ind_buffer2[i]=0.0;
            ind_buffer2s[i]=0.0;
            }           
         }       
     }
     
     if (NewBar())
     {
      string CurrColor;
      string PrevColor;
      
      //calc CurrColor
      if (ind_buffer1[1] != 0)
          CurrColor = "LimeGreen";
      if (ind_buffer1s[1] != 0)
          CurrColor = "Green";
      if (ind_buffer2[1] != 0)
          CurrColor = "Red";
      if (ind_buffer2s[1] != 0)
          CurrColor = "Maroon";
          
      //Calc PrevColor
      if (ind_buffer1[2] != 0)
          PrevColor = "LimeGreen";
      if (ind_buffer1s[2] != 0)
          PrevColor = "Green";
      if (ind_buffer2[2] != 0)
          PrevColor = "Red";
      if (ind_buffer2s[2] != 0)
          PrevColor = "Maroon";
          
      
      
      if (CurrColor != PrevColor)
      {
         
         string AlertText = Symbol() + ": oSMA Color Change";
        
         if (AlertOn)
            Alert(AlertText);
         if (EmailOn)              
            SendMail(AlertText,"");
      }   
}
     
//---- done
   return(0);
  }


Comments