b_v2_macd_osmax
Download scriptThis custom trading indicator is designed to provide a sophisticated, visual analysis of market momentum and trend direction by enhancing the standard Moving Averages Convergence/Divergence (MACD) framework. It transforms raw price data into a multi-layered visual display that helps traders identify trend strength, shifts in momentum, and potential entry or exit points.
Core Analytical Engine
The logic is built upon three primary mathematical components:
- Fast and Slow Moving Averages: The script calculates two different moving averages based on user-defined periods (defaulting to 12 and 26). By comparing these, the tool identifies the "spread" between short-term price action and long-term trends.
- The MACD Line: This is the primary difference between the fast and slow averages, representing the immediate momentum of the asset.
- The Signal Line: A secondary moving average applied to the MACD line itself, used to smooth out fluctuations and identify major trend changes.
Advanced Visual Logic: The Three-Color System
What sets this specific script apart from a standard MACD is its specialized "Three Color" logic. Instead of simply showing a single line, the tool analyzes the relationship between the current momentum and the previous bar's momentum to categorize price action into distinct visual segments:
- Trend Directionality: The script constantly monitors whether the current momentum value is higher or lower than the preceding one. This determines if the "speed" of the trend is accelerating or decelerating.
- Dynamic Color Coding: Based on these comparisons, the logic assigns different visual attributes to the histogram. It differentiates between:
- Positive Momentum Growth: When the price is moving up and gaining strength.
- Negative Momentum Growth: When the price is moving down and losing further ground.
- Momentum Shifts/Stagnation: It identifies "neutral" zones where momentum might be leveling off, helping traders spot potential exhaustion before a trend reversal occurs.
- Signal Multiplication: The script includes a multiplier (OsmaX) that allows for the amplification of certain data points, making it easier to see smaller fluctuations in volatile markets.
Summary for the Trader
Rather than just telling you if the price is going up or down, this indicator attempts to show you the quality of that movement. By visualizing momentum as a multi-colored histogram alongside traditional signal lines, it provides a clearer picture of when a trend is healthy and strong, versus when it is beginning to weaken, allowing for more informed decision-making in real-time trading.
//+------------------------------------------------------------------+
//| CoreWinTT æåëàåò Âàì óñïåõîâ è óäà÷è! :)
//+------------------------------------------------------------------+
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 6
#property indicator_color1 MediumPurple
#property indicator_color2 Magenta
#property indicator_color3 Aqua
#property indicator_color4 Silver
#property indicator_color5 Red
#property indicator_color6 Aquamarine
//---- indicator parameters
//extern string Setup = "Classic 12 26 9";
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalEMA=9;
extern int OsmaX=2;
double Zero_level=0.0;
double minuse;
double Vol;
//---- indicator buffers
double ind_buffer1[];
double ind_buffer2[];
double ind_buffer3[];
double ind_buffer4[];
double ind_buffer5[];
double ind_buffer6[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2);
SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,2);
SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,2);
SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(4,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(5,DRAW_LINE,STYLE_SOLID,1);
SetIndexDrawBegin(1,"OsMA");
//---- indicator buffers mapping
if(!SetIndexBuffer(0,ind_buffer1) &&
!SetIndexBuffer(1,ind_buffer2) &&
!SetIndexBuffer(2,ind_buffer3) &&
!SetIndexBuffer(3,ind_buffer4) &&
!SetIndexBuffer(4,ind_buffer5) &&
!SetIndexBuffer(5,ind_buffer6))
Print("cannot set indicator buffers!");
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("MACD("+FastEMA+","+SlowEMA+","+SignalEMA+")");
SetIndexLabel(0,"OsMAW");
SetIndexLabel(1,"OsMAS");
SetIndexLabel(2,"OsMAB");
SetIndexLabel(3,"OsMA");
SetIndexLabel(4,"Signal");
SetIndexLabel(5,"MACD");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
//---- 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 buffer
for(int i=0; i<limit; i++)
ind_buffer6[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
//---- signal line counted in the 2-nd buffer
for(i=0; i<limit; i++)
ind_buffer5[i]=iMAOnArray(ind_buffer6,Bars,SignalEMA,0,MODE_EMA,i);
for(i=0; i<limit; i++)
ind_buffer4[i]=((iOsMA(NULL,0,FastEMA,SlowEMA,SignalEMA,PRICE_CLOSE,i))*OsmaX);
for(i=0; i<limit; i++)
ind_buffer3[i]=ind_buffer4[i];
for(i=0; i<limit; i++)
ind_buffer2[i]=ind_buffer4[i];
for(i=0; i<limit; i++)
ind_buffer1[i]=ind_buffer4[i];
//---- done
//---- Three Colour MACD mapping
for(i=0; i<limit; i++)
{ //for open
if (ind_buffer6[i]>ind_buffer6[i+1])
{
ind_buffer2[i]=Zero_level;
Vol = ind_buffer1[i]; minuse = Vol - ind_buffer1[i+1];
if(minuse>0.0){ind_buffer3[i]=Vol; ind_buffer2[i]=0.0; ind_buffer1[i]=0.0;}
else {if(minuse<0.0){ind_buffer3[i]=0.0; ind_buffer2[i]=0.0; ind_buffer1[i]=Vol;}
else{ind_buffer3[i]=0.0; ind_buffer2[i]=0.0; ind_buffer1[i]=Vol;}}
} //if Close
else {
ind_buffer2[i]=Zero_level;
Vol = ind_buffer1[i]; minuse = Vol - ind_buffer1[i+1];
if(minuse>0.0){ind_buffer3[i]=0.0; ind_buffer2[i]=0.0; ind_buffer1[i]=Vol;}
else {if(minuse<0.0){ind_buffer3[i]=0.0; ind_buffer2[i]=Vol; ind_buffer1[i]=0.0;}
else{ind_buffer4[i]=0.0; ind_buffer2[i]=0.0; ind_buffer1[i]=Vol;}}
}
}//for Close
return(0);
}
Comments