FX-AO_v1
Download scriptThe Accelerator/Decelerator Oscillator is a technical analysis tool designed to help traders visualize the momentum and strength of a market trend. Rather than simply showing price movement, this script focuses on the "speed" at which price is moving, helping to identify whether a current trend is gaining steam or beginning to exhaust.
How the Logic Works
The tool operates by calculating two distinct layers of data to provide a comprehensive view of market dynamics:
1. Establishing the Foundation (The MACD Component) The script begins by comparing two different moving averages. It looks at a "fast" average (representing recent price action) and a "slow" average (representing broader price trends). By subtracting the slow average from the fast one, it creates a baseline value that shows the current distance between short-term and long-term momentum.
2. Refining the Signal (The Smoothing Layer) To filter out market "noise" and prevent erratic signals, the script applies an additional smoothing calculation to that baseline. This creates a secondary "signal line." The relationship between the primary momentum and this smoothed signal line allows the tool to detect subtle shifts in direction before they become obvious on a standard price chart.
3. Visualizing Momentum Dynamics The final output is presented as a dual-histogram visualization. The logic evaluates whether the current momentum value is higher or lower than the previous point:
- Positive Movement: When the momentum is increasing, the tool highlights this activity to show where the trend is accelerating.
- Negative Movement: When the momentum begins to decline, the tool captures these shifts independently.
What This Means for the User
By separating these movements into distinct visual bars (Gold and Red), the script allows you to see the "tug-of-war" between buyers and sellers. Instead of just seeing where the price is, you can see how aggressively the market is moving toward a target. It effectively highlights whether a trend is still healthy and "accelerating" or if it is beginning to "decelerate," which can be an early warning sign of a potential trend reversal or a period of consolidation.
//+------------------------------------------------------------------+
//| 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 Gold
#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("FX-AO");
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_SMMA,PRICE_TYPICAL,i)-iMA(NULL,0,34,0,MODE_SMMA,PRICE_TYPICAL,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