ColorOsMA_v1
Download scriptThis technical tool is designed to provide traders with a visual representation of market momentum by blending two well-known and reliable analysis methods into a single, easy-to-read display.
How the Logic Works
The indicator functions by performing a multi-step calculation to filter out market "noise" and highlight significant trends:
1. Establishing the Base Momentum (MACD) First, the script calculates the difference between two different types of moving averages: a "Fast" average and a "Slow" average. By comparing these, the tool identifies how quickly the price is moving relative to its recent history. This creates a raw momentum value that tells us whether the current trend is accelerating or decelerating.
2. Smoothing the Data (The Signal Line) To prevent the indicator from reacting too aggressively to minor, insignificant price flickers, the script then takes that raw momentum and applies a "Signal" average to it. This acts as a smoothing filter, ensuring that only sustained movements are highlighted while smaller fluctuations are ignored.
3. Calculating the Gap (The Oscillator) The core logic of this specific tool lies in measuring the distance between the Momentum value and the Signal Line. By subtracting one from the other, the script determines the "strength" of the current trend.
4. Visual Color Coding Finally, the script translates these mathematical results into a clear visual format for the user:
- Positive Values: When the momentum is stronger than the signal line, it populates a specific bar (colored in blue). This typically suggests upward pressure.
- Negative Values: When the momentum falls below the signal line, it populates a different bar (colored in red). This typically suggests downward pressure.
Summary for Traders
Instead of looking at multiple complex charts, this indicator condenses three layers of data into one window. It allows you to see at a glance not just where the price is going, but how much "power" is behind the current move, using distinct colors to separate bullish and bearish sentiment instantly.
//+------------------------------------------------------------------+
//| ColorOsMA.mq4 |
//| duckfu |
//| http://www.dopeness.org/ |
//+------------------------------------------------------------------+
#property copyright "duckfu"
#property link "http://www.dopeness.org/"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 DodgerBlue
#property indicator_color2 FireBrick
//---- indicator parameters
extern int FastEMA=8;
extern int SlowEMA=12;
extern int SignalSMA=9;
//---- indicator buffers
double OsMAUpBuffer[];
double OsMADownBuffer[];
double OsMABuffer[];
double MACDBuffer[];
double SignalBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- 2 additional buffers are used for counting.
IndicatorBuffers(5);
//---- drawing settings
SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2);
SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,2);
SetIndexDrawBegin(0,SignalSMA);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);
//---- 3 indicator buffers mapping
if(!SetIndexBuffer(0,OsMAUpBuffer) &&
!SetIndexBuffer(1,OsMADownBuffer) &&
!SetIndexBuffer(2,OsMABuffer) &&
!SetIndexBuffer(3,MACDBuffer) &&
!SetIndexBuffer(4,SignalBuffer))
Print("cannot set indicator buffers!");
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("ColorOsMA("+FastEMA+","+SlowEMA+","+SignalSMA+")");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Moving Average of Oscillator |
//+------------------------------------------------------------------+
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 additional buffer
for(int i=0; i<limit; i++){
MACDBuffer[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 additional buffer
for(i=0; i<limit; i++){
SignalBuffer[i]=iMAOnArray(MACDBuffer,Bars,SignalSMA,0,MODE_SMA,i);
}
//---- main loop
for(i=0; i<limit; i++){
OsMABuffer[i]=(MACDBuffer[i]-SignalBuffer[i]);
if(OsMABuffer[i]>0){
OsMAUpBuffer[i]=OsMABuffer[i];
OsMADownBuffer[i]=0;
}else if(OsMABuffer[i]<0){
OsMADownBuffer[i]=OsMABuffer[i];
OsMAUpBuffer[i]=0;
}else{
OsMAUpBuffer[i]=0;
OsMADownBuffer[i]=0;
}
}
//---- done
return(0);
}
//+------------------------------------------------------------------+
Comments