+OsMA Color
Download scriptThis script is a specialized trading tool designed to visualize market momentum by analyzing the relationship between different price averages. It functions as a modified "Awesome Oscillator," which helps traders identify the strength and direction of a market trend more clearly than standard indicators might.
Core Logic Overview
The tool operates by calculating the difference between two moving averages: a "Fast" average (which reacts quickly to recent price changes) and a "Slow" average (which tracks long-term trends). By subtracting the slow data from the fast data, the script identifies the current momentum of the market.
However, rather than simply showing these raw numbers as a single line, this script adds a layer of sophisticated visual logic to categorize the movement into specific types of price action.
How it Processes Data
- Momentum Calculation: The tool first calculates a base value based on weighted prices. This provides the foundation for understanding whether the market is currently pushing upward or downward.
- Trend Directionality: The script then evaluates the "flow" of this momentum. It checks if the current value is higher or lower than the previous one to determine if the trend is accelerating or decelerating.
- Visual Categorization: To make this information easier for a human to read, the logic splits the data into four distinct visual categories (represented as different colors):
- Bullish Momentum: When the market is moving upward and gaining strength, it highlights specific bars to show positive growth.
- Bearish Momentum: When the market is moving downward and losing value, it identifies those segments.
- Weakening Trends: The script specifically distinguishes between a "strong" move and a "fading" move. For example, if the price is still going up but at a slower pace than before, or if it is falling but slowing down, the script assigns these to different visual buffers.
Summary for the User
Instead of giving you a cluttered graph of raw numbers, this tool acts as a filter. It interprets the complex math of moving averages and translates them into a clear, color-coded histogram. This allows you to see at a glance not just where the price is going, but how much energy is behind the current move, helping you distinguish between a powerful trend and a tired market that may be nearing a reversal.
//+------------------------------------------------------------------+
//| 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=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
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(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;
}
}
}
//---- done
return(0);
}
Comments