ATR_Chart_Daily
Download scriptThis tool is designed to provide traders with a clear, real-time view of market volatility by calculating and displaying the Average True Range (ATR) directly on the trading chart. Instead of requiring the user to navigate through complex technical sub-windows, this script simplifies the data into two easily readable text labels.
Core Functionality
The primary purpose of this script is to monitor how much a currency pair or asset typically moves over a specific period. It focuses on two distinct timeframes:
- Current ATR: The average range for the current ongoing day.
- Previous ATR: The average range recorded for the preceding day.
By displaying these two figures side-by-side, traders can quickly gauge whether the current market movement is "normal" compared to yesterday's behavior. If today’s volatility is significantly higher or lower than the previous day's average, it serves as a vital signal for adjusting risk management or entry strategies.
How the Logic Works
- Data Processing: The script looks back at the last 14 days (a standard timeframe for measuring momentum and volatility) to calculate the average price movement. It automatically converts these raw values into a format that aligns with the specific currency's pricing structure.
- Dynamic Visual Updates: The script constantly monitors the live market feed. As new price data arrives, it refreshes the text on the screen so the "Current ATR" value remains up-to-date without any manual intervention from the user.
- Smart Label Management: To keep the trading workspace clean, the script includes automated "housekeeping" logic. It identifies its own unique labels and ensures that they are correctly placed on the chart for the specific asset you are viewing. It effectively prevents overlapping text or leftover data from other charts from cluttering your screen.
- Customizable Display: The script allows for adjustments regarding the visual appearance of the information, such as the size of the font, the color of the text, and its position on the screen. This ensures that the data is always visible and integrated seamlessly into the trader's unique layout.
Summary for the Trader
Essentially, this script acts as a volatility speedometer. It removes the manual math of calculating daily ranges and presents you with two simple numbers: what the market moved on average yesterday, and how much it is moving right now. This helps in making informed decisions about profit targets and stop-loss placement based on real-time market behavior.
//+------------------------------------------------------------------+
//| ATR_Chart_Daily.mq4 |
//| Copyright © 2008, Robert Hill |
//| |
//| Display the Average Daily Range on the chart for past 2 days |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Robert Hill"
#property indicator_chart_window
//---- input parameters
extern int AtrPeriod=14;
extern string to="---Text Object Settings---";
extern int Text_X_Offset = 20;
extern int CommentTxtSize = 10;
extern color CommentColor = White;
int Comment1Y, Comment2Y;
string Comment1Label, Comment2Label;
string Object_ID = "ATRCA_";
string short_name;
double myPoint;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
DeleteBadLabels();
DeleteExistingLabels();
SetupLabels();
myPoint = SetPoint(Symbol());
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
ClearLabels();
DeleteExistingLabels();
//----
return(0);
}
//+------------------------------------------------------------------+
//| Average True Range |
//+------------------------------------------------------------------+
int start()
{
double ATRcurr, ATRprev;
//----
if(Bars<=AtrPeriod) return(0);
if (Comment1Y < 10)
{
SetupLabels();
ClearLabels();
DeleteExistingLabels();
SetupLabels();// Make sure label settings are OK
}
else
{
ClearLabels();
}
//----
ATRcurr = iATR(NULL, PERIOD_D1, AtrPeriod, 0) / myPoint;
ATRprev = iATR(NULL, PERIOD_D1, AtrPeriod, 1) / myPoint;
//----
OutputComment1ToChart("Curr ATR : " + DoubleToStr(ATRcurr, 0));
OutputComment2ToChart("Prev ATR : " + DoubleToStr(ATRprev, 0));
return(0);
}
double SetPoint(string mySymbol)
{
double mPoint, myDigits;
myDigits = MarketInfo (mySymbol, MODE_DIGITS);
if (myDigits < 4)
mPoint = 0.01;
else
mPoint = 0.0001;
return(mPoint);
}
void ClearLabels()
{
string mComment = " ";
OutputLabelToChart(Comment1Label, Comment1Y, CommentTxtSize, CommentColor, mComment);
OutputLabelToChart(Comment2Label, Comment2Y, CommentTxtSize, CommentColor, mComment);
}
void DeleteBadLabels()
{
int objLabels = ObjectsTotal(OBJ_LABEL);
string objName;
if (objLabels > 0)
{
for (int i = objLabels; i >= 0;i--)
{
objName = ObjectName(i);
if (StringFind(objName,Object_ID, 0) >= 0)
{
// Found 2 Play object, now check for wrong Symbol
if (StringFind(objName,Symbol(), 0) < 0)
{
ObjectDelete(objName);
}
}
}
}
}
void DeleteExistingLabels()
{
int objLabels = ObjectsTotal(OBJ_LABEL);
string objName;
if (objLabels > 0)
{
for (int i = objLabels; i >= 0;i--)
{
objName = ObjectName(i);
if (StringFind(objName,Object_ID, 0) >= 0)
{
// Found 2 Play object, now check for Symbol
if (StringFind(objName,Symbol(), 0) >= 0)
{
ObjectDelete(objName);
}
}
}
}
}
void SetupLabels()
{
Comment1Y = 12;
Comment2Y = Comment1Y + CommentTxtSize + 4;
Comment1Label = Object_ID + Symbol() + "_Comment1";
Comment2Label = Object_ID + Symbol() + "_Comment2";
}
void OutputLabelToChart(string LabelName, int LabelY, int LabelTxtSize, color LabelColor, string LabelStr)
{
if(ObjectFind(LabelName) != 0)
{
ObjectCreate(LabelName, OBJ_LABEL, 0, 0, 0);
ObjectSet(LabelName, OBJPROP_CORNER, 0);
ObjectSet(LabelName, OBJPROP_XDISTANCE, Text_X_Offset);
ObjectSet(LabelName, OBJPROP_YDISTANCE, LabelY);
}
ObjectSetText(LabelName, LabelStr, LabelTxtSize, "Arial Bold", LabelColor);
}
void OutputComment1ToChart(string mComment)
{
OutputLabelToChart(Comment1Label, Comment1Y, CommentTxtSize, CommentColor, mComment);
}
void OutputComment2ToChart(string mComment)
{
OutputLabelToChart(Comment2Label, Comment2Y, CommentTxtSize, CommentColor, mComment);
}
//+------------------------------------------------------------------+
Comments