Indicators Used
0
Views
0
Downloads
0
Favorites
ATR_Chart_Daily
//+------------------------------------------------------------------+
//| 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
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---