Average Day Range v1.0
Download scriptThe Average Day Range (ADR) tool is designed to provide traders with a smoothed perspective on the typical price movement of a financial instrument over time. Instead of looking at just one day's volatility—which can often be misleading due to sudden news or temporary market noise—this script calculates a "weighted" average to help identify a more reliable range for daily price action.
How the Logic Works
The core purpose of this script is to determine how much a currency pair or asset typically moves from its highest point (high) to its lowest point (low) during a single day. It achieves this by looking at several different timeframes simultaneously:
- Recent Volatility: It captures the range of the most recent trading day.
- Short-Term Average: It calculates the average range of the last 5 days.
- Medium-Term Average: It calculates the average range of the last 10 days.
- Long-Term Average: It calculates the average range of the last 20 days.
The Calculation Process
The script doesn't just pick one of these numbers; it combines them into a single, cohesive metric. To do this:
- It finds the difference between the high and low prices for the specific days mentioned above.
- It averages those values individually (for the 5-day, 10-day, and 20-day periods).
- Finally, it takes the Average of these four averages (Yesterday + 5-Day Avg + 10-Day Avg + 20-Day Avg) divided by four.
Practical Application for Traders
By using this specific logic, the indicator provides a "Weighted Day Range." This is highly useful for:
- Setting Targets: Understanding what a "normal" move looks like helps in setting realistic profit targets.
- Identifying Abnormalities: If the current day's price movement significantly exceeds the ADR, it may indicate an exhausted trend or an overextended market.
- Risk Management: It helps traders gauge the expected "swing" of a pair, allowing for better placement of stop-loss orders based on historical volatility rather than guesswork.
In short, this script filters out the "noise" of single-day fluctuations by blending recent history with broader market trends, providing a more stable indicator of how much an asset actually moves in a typical day.
//+------------------------------------------------------------------+
//| Average Day Range v1.0.mq4 |
//| Copyright © 2006, Ogeima |
//| ph_bresson@yahoo.com |
//+------------------------------------------------------------------+
//Please find some notes at the end of the script
#property copyright "Copyright © 2006, Ogeima"
#property link "ph_bresson@yahoo.com"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Brown
#property indicator_minimum 0
double ADR[];
int cur_day;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorShortName("Average Day Range " + Symbol() + " ");
IndicatorBuffers(1);
SetIndexBuffer(0,ADR);
SetIndexStyle(0,DRAW_LINE,EMPTY,3,Brown);
SetIndexEmptyValue(0,EMPTY_VALUE);
SetIndexLabel(0,"ADR " + Symbol() + " " + Period());
/*
cur_day = TimeDayOfWeek(Time[0]);
ADR[0] = AvgDayRange(1);
*/
cur_day = 6;
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int nth_day,shift;
int counted_bars = IndicatorCounted();
if(counted_bars<0) counted_bars=0;
if(counted_bars>0) counted_bars--;
int limit = Bars-counted_bars - 21;
for( shift=0 ; shift < limit; shift++ )
{
if(cur_day != TimeDayOfWeek(Time[shift])) //New Day: compute the ADR
{
cur_day = TimeDayOfWeek(Time[shift]);
nth_day ++;
ADR[shift] = AvgDayRange(nth_day);
} //if(cur_day != TimeDayOfWeek(Time[shift]))
else ADR[shift] = ADR[shift-1]; //Not a new day
} //for(shift=limit ; shift >= 0 ; shift--)
return(0);
}
//+---------------------------------------------------------------------------+
double AvgDayRange(int nth_day)
{
double R1,R5,R10,R20;
int i;
R1 = (iHigh(NULL,PERIOD_D1,nth_day)-iLow(NULL,PERIOD_D1,nth_day));
for(i=0;i<5;i++) R5 = R5 + (iHigh(NULL,PERIOD_D1,nth_day+i)-iLow(NULL,PERIOD_D1,nth_day+i));
for(i=0;i<10;i++) R10 = R10 + (iHigh(NULL,PERIOD_D1,nth_day+i)-iLow(NULL,PERIOD_D1,nth_day+i));
for(i=0;i<20;i++) R20 = R20 + (iHigh(NULL,PERIOD_D1,nth_day+i)-iLow(NULL,PERIOD_D1,nth_day+i));
R5 = R5/5;
R10 = R10/10;
R20 = R20/20;
return((R1+R5+R10+R20)/4);
}
//+---------------------------------------------------------------------------+
/*
It computes yesterday's range (range= high - low), the previous 5, 10 and 20 days ranges. And it calculates the "Average Day Range" of these four ranges (yesterday's+ Prev 5 Day Range + Prev 10 Day Range + Prev 20 Day Range)/4.
So, if yesterday's Day Range was 80, the Previous 5 Day Range was 110, the Previous 10 Day Range was 90 and the Previous 20 Day Range was 120, then the Average Day Range would be 100.
ADR is therefore a kind of weighted Day Range.
For FXIGOR's DBO system, Divide_Factor is 2.
For more information regarding the DBO system, read the "FXiGoR-(T_S_R) very effective Trend Slope Retracement system" thread opened by iGoR at StrategyBuilderfx or Forex-tsd.
For FXIGOR's TSR method, use Divide_Factor = 1.
For more information regarding the T_S_R method, read the "FXiGoR-(T_S_R) very effective Trend Slope Retracement system" thread opened by iGoR at StrategyBuilderfx or Forex-tsd.
Ogeima.
*/
Comments