MMA_color
Download scriptThe MMA Color tool is a visual technical analysis indicator designed to help traders identify trends and momentum shifts by calculating the difference between two moving averages. It provides a dynamic, color-coded histogram that simplifies the interpretation of price action.
Core Logic and Functionality
1. The Foundation: Moving Average Difference The script works by comparing two different Moving Averages (MA) based on your chosen settings (such as Simple, Exponential, or Weighted averages). It calculates a specific moving average for the current price and subtracts a second moving average that is "shifted" forward in time (the distance of this shift is customizable).
The result of this subtraction creates a base value. If the current average is significantly higher than the shifted average, the value is positive; if it is lower, the value is negative. This is conceptually similar to how oscillators like the MACD function.
2. Trend Detection and Sensitivity To ensure that minor market "noise" doesn't cause the indicator to change colors too frequently, the script utilizes a sensitivity threshold. The logic checks if the current value has moved beyond a specific decimal limit compared to the previous value. Only when this movement exceeds your set sensitivity does the tool consider the trend to have officially changed.
3. Visual Output: Color Coding Instead of just providing a line on a chart, this script translates the mathematical data into a visual histogram in a separate window:
- Bullish Momentum: When the calculation shows upward momentum (the current value is greater than the previous), the histogram highlights the data in one color (Blue).
- Bearish Momentum: When the calculation shows downward momentum (the current value falls below the previous), the indicator switches to a different color (Red).
Summary for the User
Essentially, this tool acts as a visual "momentum thermometer." It looks at the relationship between current price trends and past price data. By providing a colored histogram, it allows you to see at a glance whether the momentum is currently pushing upward or downward, filtering out insignificant price fluctuations so you can focus on the primary trend direction.
//+------------------------------------------------------------------+
//| MMA color.mq4 |
//| Copyright © 2006, Rustem Bigeev. |
//| http://www.parch.ru |
//+------------------------------------------------------------------+
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Black
#property indicator_color2 Blue
#property indicator_color3 Red
//---- indicator buffers
double ExtBuffer0[];
double ExtBuffer1[];
double ExtBuffer2[];
extern int PeriodMA=120;
extern int TypeMA=1;
extern string Mode1_ = "0 - MODE_SMA Ïðîñòîå ñêîëüçÿùåå ñðåäíåå ";
extern string Mode2_ = "1 - MODE_EMA Ýêñïîíåíöèàëüíîå ñêîëüçÿùåå ñðåäíåå ";
extern string Mode3_ = "2 - MODE_SMMA Ñãëàæåííîå ñêîëüçÿùåå ñðåäíåå ";
extern string Mode4_ = "3 - MODE_LWMA Ëèíåéíî-âçâåøåííîå ñêîëüçÿùåå ñðåäíåå ";
extern int PriceMA=4;
extern string Price1_ = "0 - PRICE_CLOSE Öåíà çàêðûòèÿ";
extern string Price2_ = "1 - PRICE_OPEN Öåíà îòêðûòèÿ";
extern string Price3_ = "2 - PRICE_HIGH Öåíà ìàêñèìóìà";
extern string Price4_ = "3 - PRICE_LOW Öåíà ìèíèìóìà" ;
extern string Price5_ = "4 - PRICE_MEDIAN Öåíà ñåðåäèíû" ;
extern string Price6_ = "5 - PRICE_TYPICAL Öåíà òèïè÷åñêàÿ";
extern string Price7_ = "6 - PRICE_WEIGHTED Öåíà âçâåøåííàÿ" ;
extern int Shift=6;
extern double Sensit=0.0001;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
SetIndexStyle(0,DRAW_NONE);
SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexStyle(2,DRAW_HISTOGRAM);
IndicatorDigits(Digits+1);
SetIndexDrawBegin(0,34);
SetIndexDrawBegin(1,34);
SetIndexDrawBegin(2,34);
//---- 3 indicator buffers mapping
SetIndexBuffer(0,ExtBuffer0);
SetIndexBuffer(1,ExtBuffer1);
SetIndexBuffer(2,ExtBuffer2);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("MMA color("+PeriodMA+", "+Shift+", "+TypeMA+", "+PriceMA+", "+Sensit+")");
SetIndexLabel(1,NULL);
SetIndexLabel(2,NULL);
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Awesome Oscillator |
//+------------------------------------------------------------------+
int start()
{
double prev,current;
int counted_bars = IndicatorCounted();
if(counted_bars < 0) return(-1);
if(counted_bars > 0) counted_bars--;
int limit = Bars - counted_bars;
if(counted_bars==0) limit--;
//---- macd
for(int i=0; i<limit; i++)
ExtBuffer0[i]=iMA(NULL,0,PeriodMA,1,TypeMA,PriceMA,i)-iMA(NULL,0,PeriodMA,1,TypeMA,PriceMA,i+Shift);
//---- dispatch values between 2 buffers
bool up=true;
for(i=limit-1; i>=0; i--)
{
current=ExtBuffer0[i];
prev=ExtBuffer0[i+1];
if(current>prev+Sensit) up=true;
if(current<prev-Sensit) up=false;
if(!up)
{
ExtBuffer2[i]=current;
ExtBuffer1[i]=0.0;
}
else
{
ExtBuffer1[i]=current;
ExtBuffer2[i]=0.0;
}
}
//---- done
return(0);
}
Comments