accelerator_v1
Download scriptThe Accelerator/Decelerator Oscillator is a technical analysis tool designed to provide traders with a visual representation of the momentum behind price movements. Rather than simply showing where the price is going, this indicator focuses on the "speed" and "strength" of that movement, helping users identify whether a current trend is gaining steam or beginning to lose its power.
How the Logic Works
The script operates by analyzing two specific layers of market data:
1. Calculating Momentum (The Core Data) The tool begins by looking at two different types of Moving Averages (MAs). It compares a faster-moving average (which reacts quickly to price changes) against a slower-moving average (which represents the broader trend). By subtracting the slow average from the fast one, the script generates a base momentum value.
2. Identifying the Signal Line To smooth out the data and filter out "noise," the script takes that base momentum value and applies another layer of smoothing. This creates a "Signal Line." The relationship between the raw momentum and this signal line is what ultimately determines the oscillator's behavior.
3. Determining Directional Strength (The Visual Output) The final step of the logic involves comparing the current gap between the momentum and the signal line against the gap from the previous period.
- Positive Momentum: If the gap is widening or increasing, the tool recognizes this as accelerating strength. It plots this data in Green on the chart.
- Negative Momentum: If the gap is narrowing or decreasing, the tool recognizes this as decelerating strength (even if the price is still moving in the same direction). It plots this data in Red on the chart.
What This Means for the User
By observing these Green and Red histograms, a trader can see more than just "Up" or "Down." The indicator highlights the internal mechanics of a trend:
- Acceleration: When the histogram grows in size, it suggests the current trend has significant fuel and may continue.
- Deceleration: When the histogram begins to shrink or change color, it acts as an early warning that the trend is exhausting, potentially signaling a future reversal or a period of consolidation.
//+------------------------------------------------------------------+
//| Accelerator.mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Red
//---- indicator buffers
double ind_buffer1[];
double ind_buffer2[];
double ind_buffer3[];
double ind_buffer4[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- 2 additional buffers are used for counting.
IndicatorBuffers(4);
//---- drawing settings
SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,3);
SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,3);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);
SetIndexDrawBegin(0,38);
SetIndexDrawBegin(1,38);
//---- 4 indicator buffers mapping
if(!SetIndexBuffer(0,ind_buffer1) &&
!SetIndexBuffer(1,ind_buffer2) &&
!SetIndexBuffer(2,ind_buffer3) &&
!SetIndexBuffer(3,ind_buffer4))
Print("cannot set indicators\' buffers!");
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("AC");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Accelerator/Decelerator Oscillator |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
double prev,current;
//---- 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++)
ind_buffer3[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++)
ind_buffer4[i]=iMAOnArray(ind_buffer3,Bars,5,0,MODE_SMA,i);
//---- dispatch values between 2 buffers
bool up=true;
for(i=limit-1; i>=0; i--)
{
current=ind_buffer3[i]-ind_buffer4[i];
prev=ind_buffer3[i+1]-ind_buffer4[i+1];
if(current>prev) up=true;
if(current<prev) up=false;
if(!up)
{
ind_buffer2[i]=current;
ind_buffer1[i]=0.0;
}
else
{
ind_buffer1[i]=current;
ind_buffer2[i]=0.0;
}
}
//---- done
return(0);
}
Comments