Speed4_001
Download scriptThis script is designed as a custom technical indicator for the MetaTrader platform, intended to visualize the "speed" or momentum of price movements by analyzing how price changes in relation to trading volume and historical data. Instead of looking at price in isolation, it seeks to identify the underlying intensity behind market trends.
Core Logic Overview
The tool operates by examining a series of consecutive price bars and calculating the relationship between two primary factors: Price Displacement and Volume Variation.
Specifically, the logic follows these steps:
- Comparative Analysis: The script looks back at multiple historical data points simultaneously (comparing current price action against previous bars). It retrieves essential data for each bar, including the high, low, open, close prices, and the total trading volume.
- Velocity Calculation: It calculates "velocity" by measuring the change in closing prices relative to the change in volume between consecutive periods. This helps in determining if a price move is being backed by significant trading activity or if it is occurring on thin liquidity.
- Range Sensitivity: The script also takes into account the total range (the distance between the high and low of a bar) to help contextualize how much movement occurred within a specific timeframe.
- Trend Smoothing: To create a readable visual output, the script performs an accumulation and subtraction process. It calculates the difference between current values and previous values, ensuring that the resulting lines on the chart reflect the rate of change rather than just the raw price.
Visual Output
The indicator produces two distinct lines in a separate window below the main price chart:
- Primary Movement (LightSeaGreen): This line tracks the direct difference in closing prices between consecutive bars, providing a visual representation of the immediate price trajectory.
- Volume-Adjusted Speed (Red): This line represents a specialized calculation that multiplies the price-to-volume velocity by a constant factor. It serves as a secondary layer of confirmation, highlighting how aggressively the price is moving relative to the amount of trading activity taking place.
Practical Purpose
For a trader, this logic provides a way to see "under the hood" of a price movement. By observing these two lines together, one can potentially identify whether a trend is accelerating (increasing speed), slowing down, or if a price move lacks the necessary volume support to be sustained.
//+------------------------------------------------------------------+
//| Speed.mq4 |
//| Copyright © 2005, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 LightSeaGreen
#property indicator_color2 Red
extern int pips_min=10;
extern int pips_max=300;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorShortName("Speed4(C0-C1)");
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,ExtMapBuffer2);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Accumulation/Distribution |
//+------------------------------------------------------------------+
int start()
{
int i,n,Bars1,counted_bars=IndicatorCounted();
RefreshRates();
//----
//i=0;
//n=Bars-counted_bars-1;
//while(i<=n)
Bars1=Bars/2;
i=Bars1;//Bars-counted_bars-1;
while(i>=0)
{
double high0 =High[i];
double low0 =Low[i];
double open0 =Open[i];
double close0=Close[i];
double pips0=close0/Point;
double vol0=Volume[i];
double high1 =High[i+1];
double low1 =Low[i+1];
double open1 =Open[i+1];
double close1=Close[i+1];
double pips1=close1/Point;
double vol1=Volume[i+1];
double high2 =High[i+2];
double low2 =Low[i+2];
double open2 =Open[i+2];
double close2=Close[i+2];
double pips2=close2/Point;
double vol2=Volume[i+2];
double vit1=(close0-close1)/(vol0-vol1);
double vit2=(close1-close2)/(vol1-vol2);
double vit3=(high0-low0)/(vol0-vol1);
double vit4=(high1-low1)/(vol1-vol2);
//ExtMapBuffer1[i]=ExtMapBuffer1[i+1]+Volume[i];
ExtMapBuffer1[i]=(close0-close1);//iMACD(NULL,0,14,26,9,PRICE_CLOSE,MODE_MAIN,0)-iMACD(NULL,0,14,26,9,PRICE_CLOSE,MODE_MAIN,1);//buy //-vit4; //(close-low)-(high-close);
ExtMapBuffer2[i]=vit1*100;//-(iMACD(NULL,0,14,26,9,PRICE_CLOSE,MODE_MAIN,0)-iMACD(NULL,0,14,26,9,PRICE_CLOSE,MODE_MAIN,1));//sell
/*
if(ExtMapBuffer1[i]!=0)
{
double diff=high-low;
if(0==diff)
ExtMapBuffer1[i]=0;
else
{
ExtMapBuffer1[i]/=diff;
ExtMapBuffer1[i]*=Volume[i];
}
}*/
if(i<Bars1-1)
{
ExtMapBuffer1[i]-=ExtMapBuffer1[i+1];
ExtMapBuffer2[i]-=ExtMapBuffer2[i+1];
}
i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments