This tool, known as the Accelerator/Decelerator Oscillator, is designed to help traders identify changes in market momentum by measuring the "speed" and "acceleration" of price movements. Instead of looking at price alone, it analyzes how quickly a trend is gaining or losing strength.
How the Logic Works
The script operates by performing a multi-step calculation to distill complex price action into a visual histogram:
1. Establishing the Foundation (MACD Calculation) First, the tool calculates a base momentum value. It does this by comparing two different types of moving averages: one that reacts quickly to price changes (a short-term average) and one that follows the broader trend (a long-term average). By subtracting the slower average from the faster one, the script identifies the core strength of the current move.
2. Determining the Signal (Smoothing) To ensure the data isn't too "noisy" or erratic, the script then takes that base momentum and applies a secondary smoothing process. This creates a "Signal Line," which acts as a baseline to help distinguish between minor price fluctuations and significant trend shifts.
3. Calculating the Gap (The Accelerator) The core logic focuses on the difference between these two results. By measuring the gap between the momentum and the signal line, the script determines whether the current move is accelerating (speeding up) or decelerating (slowing down).
4. Visual Representation Finally, the script translates these mathematical gaps into a visual histogram:
- Trend Detection: It tracks whether the distance between the momentum and the signal is increasing or decreasing compared to the previous point in time.
- Color Coding: It highlights these movements visually. When the gap expands in one direction, it paints the histogram to show increasing strength. When the gap begins to shrink, it changes the visual output to alert you that the current move may be losing steam, even if the price is still moving in the same direction.
Summary for Traders
Essentially, this script tells you what the "engine" of the market is doing. It helps you spot moments where a trend is becoming exhausted before the price actually reverses, allowing for a clearer understanding of whether a move has enough power to continue or if it is starting to stall.
//+------------------------------------------------------------------+
//| Accelerator.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[];
double ExtBuffer3[];
double ExtBuffer4[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- 2 additional buffers are used for counting.
IndicatorBuffers(5);
//---- drawing settings
SetIndexStyle(0,DRAW_NONE);
SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexStyle(2,DRAW_HISTOGRAM);
IndicatorDigits(Digits+2);
SetIndexDrawBegin(0,38);
SetIndexDrawBegin(1,38);
SetIndexDrawBegin(2,38);
//---- 4 indicator buffers mapping
SetIndexBuffer(0,ExtBuffer0);
SetIndexBuffer(1,ExtBuffer1);
SetIndexBuffer(2,ExtBuffer2);
SetIndexBuffer(3,ExtBuffer3);
SetIndexBuffer(4,ExtBuffer4);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("AC");
SetIndexLabel(1,NULL);
SetIndexLabel(2,NULL);
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Accelerator/Decelerator 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 counted in the 1-st additional buffer
for(int i=0; i<limit; i++)
ExtBuffer3[i]=iMA(NULL,0,5,0,MODE_SMA,PRICE_MEDIAN,i)-iMA(NULL,0,34,0,MODE_SMA,PRICE_MEDIAN,i);
//---- signal line counted in the 2-nd additional buffer
for(i=0; i<limit; i++)
ExtBuffer4[i]=iMAOnArray(ExtBuffer3,Bars,5,0,MODE_SMA,i);
//---- dispatch values between 2 buffers
bool up=true;
for(i=limit-1; i>=0; i--)
{
current=ExtBuffer3[i]-ExtBuffer4[i];
prev=ExtBuffer3[i+1]-ExtBuffer4[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;
}
ExtBuffer0[i]=current;
}
//---- done
return(0);
}
//+------------------------------------------------------------------+
Comments