This script is designed as a visual trading tool for the MetaTrader platform, specifically engineered to help traders identify momentum and trend reversals by analyzing price action. It functions as a custom oscillator, providing a clear visual representation of whether market momentum is gaining strength or beginning to fade.
Core Logic and Functionality
The indicator operates based on three primary logical steps:
1. Momentum Calculation At its foundation, the script calculates the difference between two moving averages. By comparing a short-term average (which reacts quickly to price changes) against a longer-term average (which represents the broader trend), the tool determines the "speed" and "direction" of the market. This result creates a baseline value that fluctuates above and below a zero line.
2. Trend Direction Analysis The script then performs a comparative analysis between the current momentum value and the previous one. It constantly monitors whether these values are rising or falling:
- If the current value is higher than the previous one, the momentum is considered to be moving upward.
- If the current value is lower than the previous one, the momentum is considered to be moving downward.
3. Visual Representation (Color Coding) To make this data easy for a human to interpret at a glance, the script applies a dynamic coloring system to a histogram:
- Green Highlights: When the momentum is trending upwards, the values are plotted in green. This signals to the trader that buyers may be taking control or that the current upward move has strength behind it.
- Red Highlights: When the momentum starts to dip or turn downward, the values switch to red. This serves as a visual cue that selling pressure might be increasing or that an upward trend is losing steam.
Summary for Traders
Instead of forcing you to look at complex raw numbers, this tool simplifies market dynamics into a color-coded history. It filters out "noise" by focusing on the relationship between short and long-term price averages, highlighting the transition points where momentum shifts from positive to negative, helping you better time your entries and exits based on the prevailing trend.
//+------------------------------------------------------------------+
//| Awesome.mq4 |
//| Copyright © 2005, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Black
#property indicator_color2 Green
#property indicator_color3 Red
//---- indicator buffers
double ExtBuffer0[];
double ExtBuffer1[];
double ExtBuffer2[];
//+------------------------------------------------------------------+
//| 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("FX-AO");
SetIndexLabel(1,NULL);
SetIndexLabel(2,NULL);
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Awesome Oscillator |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
double prev,current;
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- macd
for(int i=0; i<limit; i++)
ExtBuffer0[i]=iMA(NULL,0,2,1,MODE_SMA,PRICE_MEDIAN,i)-iMA(NULL,0,13,8,MODE_SMA,PRICE_MEDIAN,i);
//---- 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) up=true;
if(current<prev) up=false;
if(!up)
{
ExtBuffer2[i]=current;
ExtBuffer1[i]=0.0;
}
else
{
ExtBuffer1[i]=current;
ExtBuffer2[i]=0.0;
}
}
//---- done
return(0);
}
//+------------------------------------------------------------------+
Comments