OsMA_Color2Alert_001
Download scriptThis script is a technical analysis tool designed for the MetaTrader trading platform. It functions as a visual oscillator that helps traders identify momentum and trend reversals by analyzing price movements over specific periods.
Core Logic and Functionality
1. Underlying Data Processing The tool begins by calculating a standard "Awesome Oscillator" (OsMA). It takes three primary inputs—Fast, Slow, and Signal periods—to determine the underlying momentum of the market. It uses these values to determine whether the price is trending upwards or downwards relative to its recent history.
2. Visual Representation (The Histogram) Instead of just showing a single line, the script translates the raw data into a multi-colored histogram. The logic categorizes the movement into four distinct visual states:
- Bullish Momentum: When the trend is positive and moving upward, the indicator uses shades of green to signal strength.
- Bearish Momentum: When the trend is negative and moving downward, the indicator uses shades of red to signal weakness.
3. Trend Directional Logic The script doesn't just look at whether the value is above or below zero; it looks at the relationship between the current bar and the previous bar. It compares the current state to the previous one to decide which color to display. This allows the tool to differentiate between a "strong" move (where momentum is accelerating) and a "weak" move (where momentum is slowing down), even if both are moving in the same general direction.
4. Automated Alerts One of the key features of this script is its ability to notify the user of significant shifts in market sentiment. The logic is programmed to monitor for "Color Changes." When the histogram flips from a green shade (bullish) to a red shade (bearish), or vice versa, the script recognizes this as a potential trend reversal.
Depending on your settings, the tool can perform two types of notifications when these shifts occur:
- Pop-up Alerts: A visual notification directly on your trading screen.
- Email Notifications: An automated email sent to your connected account.
Summary for the User
In simple terms, this tool acts as a "momentum thermometer." It smooths out market noise to show you the true direction of the price. By changing colors based on both the direction and the strength of the trend, it helps you visually identify when a move is gaining steam or losing power, providing clear signals for potential entry or exit points.
//+------------------------------------------------------------------+
//| 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 C'71,226,71'
#property indicator_color2 Green
#property indicator_color3 LightSalmon
#property indicator_color4 FireBrick
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
#property indicator_width4 2
//#property indicator_level1 0.0003
//#property indicator_level2 -0.0003
//---- indicator buffers
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
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);
SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID);
SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID);
SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID);
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