1
Views
0
Downloads
0
Favorites
Compared
ÿþ//+------------------------------------------------------------------+
//| !ompared.mq5 |
//| Copyright © 2019, Vladimir Karputov |
//| http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2019, Vladimir Karputov"
#property link "http://wmua.ru/slesar/"
#property version "1.001"
#property indicator_chart_window
#property indicator_buffers 0
#property indicator_plots 0
//--- input parameters
input bool InpVisible = true; // Visible
input int InpX = 10; // X-axis distance
input int InpY = 10; // Y-axis distance
input int InpIndentY = 15; // Indent Y-axis distance
input ENUM_BASE_CORNER InpCorner = CORNER_RIGHT_LOWER;// Chart corner for anchoring
input string InpFont = "Lucida Console"; // Font
input int InpFontSize = 12; // Font size
input color InpColor = clrLawnGreen; // Color
input double InpAngle = 0.0; // Slope angle in degrees
input ENUM_ANCHOR_POINT InpAnchor = ANCHOR_RIGHT_LOWER;// Anchor type
//---
string m_prefix = "compared_"; // prefix for object
datetime ExtPrevBars = 0; // "0" -> D'1970.01.01 00:00';
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
LabelCreate(0,m_prefix+"1 to 6",0,InpX,InpY+InpIndentY*0,InpCorner,"1 to 6:",InpFont,InpFontSize,InpColor,InpAngle,InpAnchor);
LabelCreate(0,m_prefix+"1 to 5",0,InpX,InpY+InpIndentY*1,InpCorner,"1 to 5:",InpFont,InpFontSize,InpColor,InpAngle,InpAnchor);
LabelCreate(0,m_prefix+"1 to 4",0,InpX,InpY+InpIndentY*2,InpCorner,"1 to 4:",InpFont,InpFontSize,InpColor,InpAngle,InpAnchor);
LabelCreate(0,m_prefix+"1 to 3",0,InpX,InpY+InpIndentY*3,InpCorner,"1 to 3:",InpFont,InpFontSize,InpColor,InpAngle,InpAnchor);
LabelCreate(0,m_prefix+"1 to 2",0,InpX,InpY+InpIndentY*4,InpCorner,"1 to 2:",InpFont,InpFontSize,InpColor,InpAngle,InpAnchor);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Indicator deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
ObjectsDeleteAll(0,m_prefix,0,OBJ_LABEL);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//--- we work only at the time of the birth of new bar
if(time[rates_total-1]==ExtPrevBars)
return(rates_total);
ExtPrevBars=time[rates_total-1];
int i=rates_total-1;
//---
double body_1=(open[i-1]>close[i-1])?open[i-1]-close[i-1]:close[i-1]-open[i-1];
double body_2=(open[i-2]>close[i-2])?open[i-2]-close[i-2]:close[i-2]-open[i-2];
double body_3=(open[i-3]>close[i-3])?open[i-3]-close[i-3]:close[i-3]-open[i-3];
double body_4=(open[i-4]>close[i-4])?open[i-4]-close[i-4]:close[i-4]-open[i-4];
double body_5=(open[i-5]>close[i-5])?open[i-5]-close[i-5]:close[i-5]-open[i-5];
double body_6=(open[i-6]>close[i-6])?open[i-6]-close[i-6]:close[i-6]-open[i-6];
LabelTextChange(0,m_prefix+"1 to 6","1 to 6: "+DoubleToString((body_1==0.0)?0.0:body_6*100.0/body_1,0)+"%");
LabelTextChange(0,m_prefix+"1 to 5","1 to 5: "+DoubleToString((body_1==0.0)?0.0:body_5*100.0/body_1,0)+"%");
LabelTextChange(0,m_prefix+"1 to 4","1 to 4: "+DoubleToString((body_1==0.0)?0.0:body_4*100.0/body_1,0)+"%");
LabelTextChange(0,m_prefix+"1 to 3","1 to 3: "+DoubleToString((body_1==0.0)?0.0:body_3*100.0/body_1,0)+"%");
LabelTextChange(0,m_prefix+"1 to 2","1 to 2: "+DoubleToString((body_1==0.0)?0.0:body_2*100.0/body_1,0)+"%");
ChartRedraw(0);
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
//| Create a text label |
//+------------------------------------------------------------------+
bool LabelCreate(const long chart_ID=0, // chart's ID
const string name="Label", // label name
const int sub_window=0, // subwindow index
const int x=0, // X coordinate
const int y=0, // Y coordinate
const ENUM_BASE_CORNER corner=CORNER_LEFT_UPPER, // chart corner for anchoring
const string text="Label", // text
const string font="Arial", // font
const int font_size=10, // font size
const color clr=clrRed, // color
const double angle=0.0, // text slope
const ENUM_ANCHOR_POINT anchor=ANCHOR_LEFT_UPPER, // anchor type
const bool back=false, // in the background
const bool selection=false, // highlight to move
const bool hidden=true, // hidden in the object list
const long z_order=0) // priority for mouse click
{
//--- reset the error value
ResetLastError();
//--- create a text label
if(!ObjectCreate(chart_ID,name,OBJ_LABEL,sub_window,0,0))
{
Print(__FUNCTION__,
": failed to create text label! Error code = ",GetLastError());
return(false);
}
//--- set label coordinates
ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);
ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);
//--- set the chart's corner, relative to which point coordinates are defined
ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);
//--- set the text
ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);
//--- set text font
ObjectSetString(chart_ID,name,OBJPROP_FONT,font);
//--- set font size
ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);
//--- set the slope angle of the text
ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle);
//--- set anchor type
ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor);
//--- set color
ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- display in the foreground (false) or background (true)
ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
//--- enable (true) or disable (false) the mode of moving the label by mouse
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
//--- hide (true) or display (false) graphical object name in the object list
ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
//--- set the priority for receiving the event of a mouse click in the chart
ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
//--- successful execution
return(true);
}
//+------------------------------------------------------------------+
//| Change the label text |
//+------------------------------------------------------------------+
bool LabelTextChange(const long chart_ID=0, // chart's ID
const string name="Label", // object name
const string text="Text") // text
{
//--- reset the error value
ResetLastError();
//--- change object text
if(!ObjectSetString(chart_ID,name,OBJPROP_TEXT,text))
{
Print(__FUNCTION__,
": failed to change the text! Error code = ",GetLastError());
return(false);
}
//--- successful execution
return(true);
}
//+------------------------------------------------------------------+
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
---