Acceleration&Speed
Download scriptThis tool is designed to help traders visualize the momentum of a financial asset by calculating two primary metrics: Speed and Acceleration. By translating raw price movements into these physical concepts, the script helps identify whether a trend is gaining strength, losing steam, or beginning to exhaust itself.
Core Logic Overview
The script operates by analyzing price data over a specific look-back period (defined by the user). It breaks down the market movement into three distinct layers of analysis:
1. Price Selection
Before calculating any movement, the tool determines which specific price point to track. Users can choose from several options, such as the opening price, closing price, highs, lows, or various mathematical averages (like the midpoint of a candle or the average of all four main data points). This allows the user to tailor the "input" to their specific trading style.
2. Speed Calculation
The "Speed" metric measures the direct distance traveled by the selected price over a set number of bars. Instead of looking at a single candle, it compares the current price to the price from several periods ago.
- Simple Interpretation: If the speed value is high, it means the price is moving significantly fast in a specific direction.
3. Acceleration Calculation
The "Acceleration" metric takes the Speed data one step further. It measures how much the Speed itself is changing from one period to the next.
- Simple Interpretation: If the speed is high but acceleration is decreasing, it suggests that while the price is still moving, it is slowing down (decelerating). Conversely, increasing acceleration indicates a surging trend that is gaining velocity.
4. Historical Offset Views
The tool also provides "Offset" versions of both Speed and Acceleration. These are essentially shifted historical versions of the primary data. This allows traders to visualize the relationship between past momentum and current price action on the same chart, making it easier to spot repeating patterns or delayed reactions in the market.
Visual Representation
The script outputs four distinct lines:
- Speed: The primary velocity of the price.
- Acceleration: The rate at which that velocity is changing.
- Speed + Offset: A shifted historical view of velocity.
- Acceleration + Offset: A shifted historical view of the acceleration rate.
By monitoring these four lines simultaneously, a trader can move beyond simply seeing where the price is going and start understanding how much effort the market is putting into that movement.
//+------------------------------------------------------------------+
//| Acceleration & Speed.mq4 |
//| Copyright © 2005, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, Kharko"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 Green
#property indicator_color3 Yellow
#property indicator_color4 Aqua
//---- indicator parameters
extern int Bar = 24; // Ïåðèîä
extern int Cena = 0; // Öåíà: 1 - îòêðûòèÿ; 2 - çàêðûòèÿ; 3 - ìàêñèìóì; 4 - ìèíèìóì;
// 5 - (H + L)/2; 6 - (H+L+C)/3; 7 - (H+L+C+O)/4;
// 0 - (H+L+C+O)/4
extern bool Sp_vis = true; // ïîêàçàòü/ñïðÿòàòü ãðàôèê ñêîðîñòè
extern bool Ac_vis = true; // ïîêàçàòü/ñïðÿòàòü ãðàôèê óñêîðåíèÿ
extern bool SpOf_vis = true; // ïîêàçàòü/ñïðÿòàòü ãðàôèê ñêîðîñòè ñî ñäâèãîì âíóòðü èñòîðèè
extern bool AcOf_vis = true; // ïîêàçàòü/ñïðÿòàòü ãðàôèê óñêîðåíèÿ ñî ñäâèãîì âíóòðü èñòîðèè
//---- indicator buffers
double ExtBuffer0[];
double ExtBuffer1[];
double ExtBuffer2[];
double ExtBuffer3[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
SetIndexStyle(2,DRAW_LINE);
SetIndexStyle(3,DRAW_LINE);
//---- 4 indicator buffers mapping
SetIndexBuffer(0,ExtBuffer0);
SetIndexBuffer(1,ExtBuffer1);
SetIndexBuffer(2,ExtBuffer2);
SetIndexBuffer(3,ExtBuffer3);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("A&S");
SetIndexLabel(0,"Speed");
SetIndexLabel(1,"Acceleration");
SetIndexLabel(2,"Speed+Offset");
SetIndexLabel(3,"Acceleration+Offset");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Accelerator/Decelerator Oscillator |
//+------------------------------------------------------------------+
int start()
{
int limit,Error;
//---- last counted bar will be recounted
int counted_bars=IndicatorCounted();
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars-Bar;
if(limit<1)limit=1;
//----
if(ExtBuffer0[0]!=0)ExtBuffer0[0]=0;
if(ExtBuffer1[0]!=0)ExtBuffer1[0]=0;
if(ExtBuffer2[Bar]!=0)ExtBuffer2[Bar]=0;
if(ExtBuffer3[Bar]!=0)ExtBuffer3[Bar]=0;
for(int i=0; i<limit; i++)
{
ExtBuffer0[i]=(value(i)-value(i+Bar))/Point;
ExtBuffer2[i+Bar]=ExtBuffer0[i];
}
for(i=0; i<limit; i++)
{
ExtBuffer1[i]=ExtBuffer0[i]-ExtBuffer0[i+Bar];
ExtBuffer3[i+Bar]=ExtBuffer1[i];
}
if(Sp_vis==false)ArrayInitialize(ExtBuffer0,0.0);
if(SpOf_vis==false)ArrayInitialize(ExtBuffer2,0.0);
if(Ac_vis==false)ArrayInitialize(ExtBuffer1,0.0);
if(AcOf_vis==false)ArrayInitialize(ExtBuffer3,0.0);
Error=GetLastError();
if(Error!=0 && Error!=1) {Print("Error START : ",Error);RefreshRates();}
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double value(int i)
{
switch(Cena)
{
case 1:
return(Open[i]);
case 2:
return(Close[i]);
case 3:
return(High[i]);
case 4:
return(Low[i]);
case 5:
return((High[i]+Low[i])/2);
case 6:
return((High[i]+Low[i]+Close[i])/3);
case 7:
return((High[i]+Low[i]+Close[i]+Open[i])/4);
default:
return((High[i]+Low[i]+Close[i]+Open[i])/4);
}
}
Comments