OsMA Color_004
Download scriptThis script functions as a specialized visual momentum indicator designed to help traders identify the strength and direction of market trends. It works by calculating and refining the data from the "Awesome Oscillator" (OsMA) to provide clearer visual cues on a trading chart.
How the Logic Works
1. Data Foundation The tool starts by gathering raw data based on three key settings: a Fast Moving Average, a Slow Moving Average, and a Signal Average. These are used to determine the current momentum of the market. It looks at these values to see whether the price is moving significantly upward or downward over a specific period.
2. Momentum Detection The script calculates the relationship between these averages to establish a baseline of market movement. This baseline helps the indicator distinguish between "active" momentum (where the market is making meaningful moves) and "flat" momentum (where the market is merely drifting).
3. Directional Filtering and Coloring The core intelligence of this script lies in how it interprets the direction of that momentum. It categorizes movement into two primary states:
- Bullish Momentum (Upward): When the trend is moving higher, the script identifies these peaks. It specifically highlights instances where the price is moving upward, using green and lime tones to signal strength.
- Bearish Momentum (Downward): When the trend is moving lower, the script captures these troughs. It uses red and maroon tones to alert the user to downward pressure.
4. Visual Presentation Instead of showing a cluttered line of data, the logic filters the "Awesome Oscillator" values into distinct visual bars. It intelligently switches between different colors based on two conditions:
- The Trend Direction: Is the market currently in an uptrend or a downtrend?
- The Velocity Change: Is the current momentum getting stronger or weaker compared to the previous moment?
Summary for the Trader
Essentially, this script acts as a "translator" for complex momentum data. It takes the raw math of the Awesome Oscillator and translates it into a color-coded histogram. By looking at the colors, you can quickly see if the market's strength is accelerating in one direction or if it is beginning to lose steam, allowing for a cleaner, more intuitive view of price action.
//+------------------------------------------------------------------+
//| 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
//---- indicator buffers
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
extern int ApplyTo=PRICE_CLOSE;
double ind_buffer1[], ind_buffer1s[];
double ind_buffer2[], ind_buffer2s[];
double ind_buffer3[];
//+------------------------------------------------------------------+
//| 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(Digits+2);
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,ApplyTo,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;
}
}
}
//---- done
return(0);
}
Comments