MACD_OsMA_Color
Download scriptThis tool is a specialized technical analysis indicator designed to help traders visualize momentum and price trends by combining three distinct mathematical models into a single visual display. Instead of looking at just one piece of data, it synthesizes the Moving Average Convergence Divergence (MACD), the OsMA (Oscillator of the Simple Moving Average), and their respective signal lines.
Core Logic and Functionality
The script operates by analyzing price data to determine the relationship between fast-moving trends and slower, long-term averages. Here is how it processes that information for the user:
1. Data Integration The tool simultaneously calculates three main components:
- MACD Main Line: Measures the distance between two different moving averages to show the strength of a trend.
- MACD Signal Line: A secondary smoothed line used to identify changes in momentum.
- OsMA: An oscillator that tracks the movement of a simple moving average, providing a clearer picture of "velocity" in price action.
2. Dynamic Visual Differentiation (Color Coding) The primary logic of this script is its ability to change the visual representation based on whether the momentum is rising or falling. It doesn't just show lines; it categorizes the data into specific "bins":
- Trend Detection: The script compares the current value of the OsMA against its previous value.
- Directional Mapping: If the momentum is moving in a downward direction (negative pressure), the tool highlights these values specifically using one set of visual markers. If the momentum is moving upward (positive pressure), it switches to a different set.
- Visual Separation: By separating these movements into distinct buffers, the tool allows a trader to see at a glance whether the current "pulse" of the market is accelerating or decelerating without having to manually interpret complex overlapping lines.
3. User Customization The logic allows for flexibility in how it views the market. Users can define:
- The speed of the "Fast" and "Slow" averages (which determines how sensitive the indicator is to price changes).
- The Signal period (which smooths out the data to reduce "noise").
- The specific price point used for calculations (such as the closing price, high/low averages, etc.).
Summary for the Trader
Essentially, this script acts as a sophisticated "momentum filter." By combining the MACD and OsMA logics, it filters out minor market fluctuations and highlights the underlying direction of the trend. The color-coded bars and lines provide an immediate visual cue: when the visual style shifts, it signifies a change in the momentum's behavior, helping traders identify potential entry or exit points based on whether the market is gaining or losing "velocity."
//+------------------------------------------------------------------+
//| MACD_OsMA_ColorLH.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 6
#property indicator_color1 LimeGreen
#property indicator_color2 DarkGreen
#property indicator_color3 Maroon
#property indicator_color4 Red
#property indicator_color5 Blue
#property indicator_color6 Orange
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
#property indicator_width4 2
#property indicator_width5 2
#property indicator_width6 1
//---- indicator buffers
extern int FastEMA =12;
extern int SlowEMA =26;
extern int SignalSMA =9;
extern int AppliedPrice =PRICE_CLOSE;
extern string note_AppliedPrice = "0O,1C 2H3L,4Md 5Tp 6WghC: Md(HL/2)4,Tp(HLC/3)5,Wgh(HLCC/4)6";
double ind_buffer1[], ind_buffer1s[];
double ind_buffer2[], ind_buffer2s[];
double ind_buffer3[];
double ind_buffer4[];
double ind_buffer5[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- 1 additional buffer used for counting.
IndicatorBuffers(7);
//---- drawing settings
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexStyle(2,DRAW_HISTOGRAM);
SetIndexStyle(3,DRAW_HISTOGRAM);
SetIndexStyle(4,DRAW_LINE);
SetIndexStyle(5,DRAW_LINE);
IndicatorDigits(Digits+2);
SetIndexDrawBegin(0,34);
SetIndexDrawBegin(1,34);
SetIndexDrawBegin(2,34);
SetIndexDrawBegin(3,34);
SetIndexDrawBegin(4,34);
SetIndexDrawBegin(5,34);
//---- 3 indicator buffers mapping
SetIndexBuffer(0,ind_buffer1) ;
//---- 3 indicator buffers mapping
if(!SetIndexBuffer(0,ind_buffer1) &&
!SetIndexBuffer(1,ind_buffer1s) &&
!SetIndexBuffer(2,ind_buffer2) &&
!SetIndexBuffer(3,ind_buffer2s) &&
!SetIndexBuffer(4,ind_buffer4) &&
!SetIndexBuffer(5,ind_buffer5) &&
!SetIndexBuffer(6,ind_buffer3))
Print("cannot set indicator buffers!");
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("MACD_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_buffer4[i]=iMACD(NULL,0,FastEMA,SlowEMA,SignalSMA,AppliedPrice,MODE_MAIN,i);
for(i=0; i<limit; i++)
ind_buffer5[i]=iMACD(NULL,0,FastEMA,SlowEMA,SignalSMA,AppliedPrice,MODE_SIGNAL,i);
for(i=0; i<limit; i++)
ind_buffer3[i]=iOsMA(NULL,0,FastEMA,SlowEMA,SignalSMA,AppliedPrice,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