2621 lines
67 KiB
Plaintext
2621 lines
67 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 Draw Library
|
|
// --------------------------------------
|
|
// Name: XDraw
|
|
// Description: provides Draw abilities ...
|
|
//
|
|
//
|
|
// Maintainer:
|
|
// ------------
|
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
//
|
|
//////////////////////////////////////////////////////
|
|
//
|
|
// Global Properties ...
|
|
#property library
|
|
#property copyright "Copyright 2023, SaherElm IT Center"
|
|
#property link "https://www.saherelm.ir"
|
|
#property version "1.00"
|
|
#property strict
|
|
|
|
//
|
|
// Global Definitions: Variables, Properties and etc ...
|
|
|
|
//
|
|
// Retrieve Chart Size in Pixel ...
|
|
struct XSize
|
|
{
|
|
long width;
|
|
long height;
|
|
|
|
//
|
|
int x;
|
|
int y;
|
|
int w;
|
|
int h;
|
|
|
|
//
|
|
int wStep;
|
|
int hStep;
|
|
};
|
|
|
|
//
|
|
// Define a Draw Specifications ...
|
|
struct XDrawSpecifications
|
|
{
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
bool draw; // Draw or Not ...
|
|
|
|
//
|
|
int width; // Draw Witdth ...
|
|
color clr; // Draw Color ...
|
|
ENUM_LINE_STYLE style; // Draw Style ...
|
|
|
|
//
|
|
bool back; // in the background
|
|
bool fill; // fill object if supported
|
|
bool selection; // highlight to move
|
|
bool rayRight; // line's continuation to the right
|
|
bool hidden; // hidden in the object list
|
|
long zOrder; // priority for mouse click
|
|
|
|
//
|
|
string label; // Label ...
|
|
color labelColor; // Label Color ...
|
|
double labelAngel; // Label Angle ...
|
|
string labelFont; // Label Font ...
|
|
int labelFontSize; // Label Font Size ...
|
|
ENUM_ANCHOR_POINT labelAnchor; // Label Anchor Point ...
|
|
|
|
//
|
|
// Constructor ...
|
|
XDrawSpecifications()
|
|
{
|
|
Clean();
|
|
}
|
|
|
|
//
|
|
// Operator ...
|
|
void operator=(const XDrawSpecifications &value)
|
|
{
|
|
//
|
|
clr = value.clr;
|
|
draw = value.draw;
|
|
width = value.width;
|
|
style = value.style;
|
|
|
|
//
|
|
back = value.back;
|
|
hidden = value.hidden;
|
|
zOrder = value.zOrder;
|
|
rayRight = value.rayRight;
|
|
selection = value.selection;
|
|
|
|
//
|
|
fill = value.fill;
|
|
|
|
//
|
|
label = value.label;
|
|
labelColor = value.labelColor;
|
|
labelAngel = value.labelAngel;
|
|
labelFont = value.labelFont;
|
|
labelFontSize = value.labelFontSize;
|
|
labelAnchor = value.labelAnchor;
|
|
}
|
|
|
|
//
|
|
// Functions ...
|
|
|
|
//
|
|
void Clean()
|
|
{
|
|
//
|
|
draw = false;
|
|
width = 1;
|
|
clr = CLR_NONE;
|
|
style = STYLE_SOLID;
|
|
|
|
//
|
|
back = false;
|
|
hidden = false;
|
|
rayRight = false;
|
|
selection = false;
|
|
fill = false;
|
|
|
|
//
|
|
zOrder = 0;
|
|
|
|
//
|
|
label = "";
|
|
labelColor = CLR_NONE;
|
|
labelAngel = 0;
|
|
labelFont = "Arial";
|
|
labelFontSize = 20;
|
|
labelAnchor = ANCHOR_LEFT_UPPER;
|
|
}
|
|
|
|
//
|
|
void Label(
|
|
string mLabel = "", // Label ...
|
|
color mLabelColor = CLR_NONE, // Label Color ...
|
|
string mLabelFont = "Arial", // Label Font ...
|
|
int mLabelFontSize = 20, // Label Font Size ...
|
|
ENUM_ANCHOR_POINT mLabelAnchor = ANCHOR_LEFT_UPPER, // Label Anchor Point ...
|
|
double mLabelAngel = 0 // Label Angle ...
|
|
)
|
|
{
|
|
//
|
|
label = mLabel;
|
|
labelFont = mLabelFont;
|
|
labelColor = mLabelColor;
|
|
labelAngel = mLabelAngel;
|
|
labelAnchor = mLabelAnchor;
|
|
labelFontSize = mLabelFontSize;
|
|
}
|
|
};
|
|
|
|
//
|
|
// Candle Draw Specifications ...
|
|
struct XOHCLDrawSpecification
|
|
{
|
|
//
|
|
// Props ...
|
|
XDrawSpecifications openStyle;
|
|
XDrawSpecifications highStyle;
|
|
XDrawSpecifications closeStyle;
|
|
XDrawSpecifications lowStyle;
|
|
|
|
//
|
|
// Constructors ...
|
|
XOHCLDrawSpecification()
|
|
{
|
|
Clean();
|
|
}
|
|
|
|
//
|
|
// Operators ...
|
|
void operator=(const XOHCLDrawSpecification &value)
|
|
{
|
|
//
|
|
lowStyle = value.lowStyle;
|
|
openStyle = value.openStyle;
|
|
highStyle = value.highStyle;
|
|
closeStyle = value.closeStyle;
|
|
}
|
|
|
|
//
|
|
// Functions ...
|
|
|
|
//
|
|
void Clean()
|
|
{
|
|
//
|
|
lowStyle.Clean();
|
|
openStyle.Clean();
|
|
highStyle.Clean();
|
|
closeStyle.Clean();
|
|
}
|
|
|
|
//
|
|
void Default()
|
|
{
|
|
//
|
|
// Open ...
|
|
openStyle.width = 1;
|
|
openStyle.draw = true;
|
|
openStyle.clr = clrLime;
|
|
openStyle.style = STYLE_SOLID;
|
|
openStyle.Label(
|
|
"O",
|
|
openStyle.clr);
|
|
|
|
//
|
|
// High ...
|
|
highStyle.width = 1;
|
|
highStyle.draw = true;
|
|
highStyle.clr = clrAqua;
|
|
highStyle.style = STYLE_SOLID;
|
|
highStyle.Label(
|
|
"H",
|
|
highStyle.clr);
|
|
|
|
//
|
|
// Close ...
|
|
closeStyle.width = 1;
|
|
closeStyle.draw = true;
|
|
closeStyle.clr = clrRed;
|
|
closeStyle.style = STYLE_SOLID;
|
|
closeStyle.Label(
|
|
"C",
|
|
closeStyle.clr);
|
|
|
|
//
|
|
// Low ...
|
|
lowStyle.width = 1;
|
|
lowStyle.draw = true;
|
|
lowStyle.clr = clrMagenta;
|
|
lowStyle.style = STYLE_SOLID;
|
|
lowStyle.Label(
|
|
"L",
|
|
lowStyle.clr);
|
|
}
|
|
|
|
//
|
|
void Width(int value)
|
|
{
|
|
//
|
|
lowStyle.width = value;
|
|
openStyle.width = value;
|
|
highStyle.width = value;
|
|
closeStyle.width = value;
|
|
}
|
|
|
|
//
|
|
void Style(ENUM_LINE_STYLE value)
|
|
{
|
|
//
|
|
lowStyle.style = value;
|
|
openStyle.style = value;
|
|
highStyle.style = value;
|
|
closeStyle.style = value;
|
|
}
|
|
|
|
//
|
|
void Color(color value)
|
|
{
|
|
//
|
|
lowStyle.clr = value;
|
|
openStyle.clr = value;
|
|
highStyle.clr = value;
|
|
closeStyle.clr = value;
|
|
}
|
|
|
|
//
|
|
void RayRight(bool value)
|
|
{
|
|
//
|
|
lowStyle.rayRight = value;
|
|
openStyle.rayRight = value;
|
|
highStyle.rayRight = value;
|
|
closeStyle.rayRight = value;
|
|
}
|
|
|
|
//
|
|
void Draw(bool value)
|
|
{
|
|
//
|
|
lowStyle.draw = value;
|
|
openStyle.draw = value;
|
|
highStyle.draw = value;
|
|
closeStyle.draw = value;
|
|
}
|
|
|
|
//
|
|
void Back(bool value)
|
|
{
|
|
//
|
|
lowStyle.back = value;
|
|
openStyle.back = value;
|
|
highStyle.back = value;
|
|
closeStyle.back = value;
|
|
}
|
|
|
|
//
|
|
void Fill(bool value)
|
|
{
|
|
//
|
|
lowStyle.fill = value;
|
|
openStyle.fill = value;
|
|
highStyle.fill = value;
|
|
closeStyle.fill = value;
|
|
}
|
|
|
|
//
|
|
void Label(string value)
|
|
{
|
|
//
|
|
lowStyle.Label(value);
|
|
openStyle.Label(value);
|
|
highStyle.Label(value);
|
|
closeStyle.Label(value);
|
|
}
|
|
|
|
//
|
|
void SetLabelPrefix(string value)
|
|
{
|
|
//
|
|
lowStyle.label = value + " " + lowStyle.label;
|
|
openStyle.label = value + " " + openStyle.label;
|
|
highStyle.label = value + " " + highStyle.label;
|
|
closeStyle.label = value + " " + closeStyle.label;
|
|
}
|
|
};
|
|
|
|
//
|
|
string drawPrefix = "X-OBJ";
|
|
|
|
//
|
|
// Common Draw Functions ...
|
|
|
|
//
|
|
// remove drawn objects ...
|
|
void RemoveDraws(
|
|
string tag = NULL,
|
|
long chartId = -1,
|
|
int subWindow = -1 //
|
|
)
|
|
{
|
|
//
|
|
// Normalize Args ...
|
|
//
|
|
if (tag == NULL)
|
|
{
|
|
tag = drawPrefix;
|
|
}
|
|
|
|
//
|
|
if (chartId == -1)
|
|
{
|
|
chartId = 0;
|
|
}
|
|
|
|
//
|
|
if (subWindow == -1)
|
|
{
|
|
subWindow = 0;
|
|
}
|
|
|
|
//
|
|
for (int iObj = ObjectsTotal(chartId, subWindow) - 1; iObj >= 0; iObj--)
|
|
{
|
|
//
|
|
string on = ObjectName(chartId, iObj, subWindow);
|
|
if (StringFind(on, tag) >= 0)
|
|
{
|
|
ObjectDelete(chartId, on);
|
|
}
|
|
}
|
|
|
|
//
|
|
// Redraw Chart ...
|
|
ChartRedraw();
|
|
}
|
|
|
|
//
|
|
bool RemoveDraw(
|
|
string name,
|
|
long chartId = -1,
|
|
int subWindow = -1 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (chartId == -1)
|
|
{
|
|
chartId = 0;
|
|
}
|
|
|
|
//
|
|
if (subWindow == -1)
|
|
{
|
|
subWindow = 0;
|
|
}
|
|
|
|
//
|
|
string objName = "";
|
|
for (int iObj = ObjectsTotal(chartId, subWindow) - 1; iObj >= 0; iObj--)
|
|
{
|
|
//
|
|
string on = ObjectName(chartId, iObj, subWindow);
|
|
if (StringFind(on, name) >= 0)
|
|
{
|
|
//
|
|
objName = on;
|
|
break;
|
|
}
|
|
}
|
|
|
|
//
|
|
if (StringLen(objName) > 0)
|
|
{
|
|
result = ObjectDelete(chartId, objName);
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Deselect All Draws ...
|
|
void DeselectAllDraws()
|
|
{
|
|
//
|
|
int objs = ObjectsTotal(ChartID(), 0);
|
|
for (int o = 0; o < objs; o++)
|
|
{
|
|
ObjectSetInteger(ChartID(), ObjectName(ChartID(), o, 0), OBJPROP_SELECTED, false);
|
|
}
|
|
|
|
//
|
|
ChartRedraw();
|
|
}
|
|
|
|
//
|
|
// Check Object Exists ...
|
|
bool IsDrawExists(
|
|
string name,
|
|
long chartId = -1,
|
|
int subWindow = -1 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (chartId == -1)
|
|
{
|
|
chartId = 0;
|
|
}
|
|
|
|
//
|
|
if (subWindow == -1)
|
|
{
|
|
subWindow = 0;
|
|
}
|
|
|
|
//
|
|
for (int iObj = ObjectsTotal(chartId, subWindow) - 1; iObj >= 0; iObj--)
|
|
{
|
|
//
|
|
string on = ObjectName(chartId, iObj, subWindow);
|
|
result = StringFind(on, name) >= 0;
|
|
if (result)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Find Specific Object Name ...
|
|
string FindObjectName(
|
|
string suggest,
|
|
long chartId = 0,
|
|
int subWindow = 0 //
|
|
)
|
|
{
|
|
//
|
|
string result = NULL;
|
|
|
|
//
|
|
int objectsCount = ObjectsTotal(chartId, subWindow);
|
|
if (objectsCount <= 0)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
for (int i = objectsCount - 1; i >= 0; i--)
|
|
{
|
|
//
|
|
string iObjectName = ObjectName(chartId, i, subWindow);
|
|
bool isExists = StringFind(iObjectName, suggest) >= 0;
|
|
if (isExists)
|
|
{
|
|
//
|
|
result = iObjectName;
|
|
break;
|
|
}
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Regular Draws ...
|
|
|
|
//
|
|
// Arrow Functions ...
|
|
|
|
//
|
|
// Draw an Arrow Object on Chart ...
|
|
bool DrawArrow(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "Arrow", // arrow name
|
|
const int subWindow = 0, // subwindow index
|
|
datetime time = 0, // anchor point time
|
|
double price = 0, // anchor point price
|
|
const uchar arrowCode = 252, // arrow code
|
|
const ENUM_ARROW_ANCHOR anchor = ANCHOR_BOTTOM, // anchor point position
|
|
const color clr = clrAqua, // arrow color
|
|
const ENUM_LINE_STYLE style = STYLE_SOLID, // border line style
|
|
const int width = 3, // arrow size
|
|
const bool back = false, // in the background
|
|
const bool selection = false, // highlight to move
|
|
const bool hidden = false, // hidden in the object list
|
|
const long zOrder = 0 // Order Object ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// set anchor point coordinates if they are not set ...
|
|
ChangeArrowEmptyPoint(time, price);
|
|
|
|
//
|
|
// reset the error value ...
|
|
ResetLastError();
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
// create an arrow ...
|
|
result = ObjectCreate(chartID, objName, OBJ_ARROW, subWindow, time, price);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// set the arrow code ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_ARROWCODE, arrowCode);
|
|
|
|
//
|
|
// set anchor type ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_ANCHOR, anchor);
|
|
|
|
//
|
|
// set the arrow color ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr);
|
|
|
|
//
|
|
// set the border line style ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style);
|
|
|
|
//
|
|
// set the arrow's size ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width);
|
|
|
|
//
|
|
// display in the foreground false or background true ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_BACK, back);
|
|
|
|
//
|
|
// enable true or disable false the mode of moving the arrow by mouse
|
|
// when creating a graphical object using ObjectCreate function, the object cannot be
|
|
// highlighted and moved by default. Inside this method, selection parameter
|
|
// is false by default, if you want making it possible to highlight and move the object
|
|
// change it to true ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, true);
|
|
ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection);
|
|
|
|
//
|
|
// hide true or display false graphical object name in the object list ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden);
|
|
|
|
//
|
|
// set the priority for receiving the event of a mouse click in the chart ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder);
|
|
|
|
//
|
|
// successful execution ...
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Move the anchor point of Arrow ...
|
|
bool MoveArrow(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "Arrow", // object name
|
|
datetime time = 0, // anchor point time coordinate
|
|
double price = 0 // anchor point price coordinate
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
// if point position is not set, move it to the current bar having Bid price ...
|
|
if (!time)
|
|
{
|
|
time = TimeCurrent();
|
|
}
|
|
|
|
//
|
|
if (!price)
|
|
{
|
|
price = SymbolInfoDouble(_Symbol, SYMBOL_BID);
|
|
}
|
|
|
|
//
|
|
// move the anchor point ...
|
|
result = ObjectMove(chartID, objName, 0, time, price);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Delete an arrow ...
|
|
bool DeleteArrow(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "Arrow" // arrow name
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
// delete an arrow ...
|
|
result = !ObjectDelete(chartID, objName);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Change the arrow code ...
|
|
bool ArrowCodeChange(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "Arrow", // object name
|
|
const uchar code = 252 // arrow code
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
// change the arrow code ...
|
|
result = ObjectSetInteger(chartID, objName, OBJPROP_ARROWCODE, code);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Change anchor type ...
|
|
bool ArrowAnchorChange(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "Arrow", // object name
|
|
const ENUM_ARROW_ANCHOR anchor = ANCHOR_TOP // anchor type
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
// change anchor type ...
|
|
result = !ObjectSetInteger(chartID, objName, OBJPROP_ANCHOR, anchor);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check anchor point values and set default values
|
|
// for empty ones ...
|
|
void ChangeArrowEmptyPoint(
|
|
datetime &time,
|
|
double &price //
|
|
)
|
|
{
|
|
//
|
|
// if the point's time is not set, it will be on the current bar ...
|
|
if (!time)
|
|
{
|
|
time = TimeCurrent();
|
|
}
|
|
|
|
//
|
|
// if the point's price is not set, it will have Bid value ...
|
|
if (!price)
|
|
{
|
|
price = SymbolInfoDouble(_Symbol, SYMBOL_BID);
|
|
}
|
|
}
|
|
|
|
//
|
|
// Horizontal Line Functions ...
|
|
|
|
//
|
|
// Create, Draw the horizontal line ...
|
|
bool DrawHorizontalLine(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "HLine", // line name
|
|
const int subWindow = 0, // subwindow index
|
|
double price = 0, // line price
|
|
const color clr = clrRed, // line color
|
|
const ENUM_LINE_STYLE style = STYLE_SOLID, // line style
|
|
const int width = 1, // line width
|
|
const bool back = false, // in the background
|
|
const bool selection = false, // highlight to move
|
|
const bool hidden = false, // hidden in the object list
|
|
const long zOrder = 0 // priority for mouse click
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// if the price is not set, set it at the current Bid price level ...
|
|
if (!price)
|
|
{
|
|
price = SymbolInfoDouble(Symbol(), SYMBOL_BID);
|
|
}
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
// create a horizontal line ...
|
|
result = ObjectCreate(chartID, objName, OBJ_HLINE, subWindow, 0, price);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// set line color ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr);
|
|
|
|
//
|
|
// set line display style ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style);
|
|
|
|
//
|
|
// set line width ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width);
|
|
|
|
//
|
|
// display in the foreground false or background true ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_BACK, back);
|
|
|
|
//
|
|
// enable true or disable false the mode of moving the line by mouse
|
|
// when creating a graphical object using ObjectCreate function, the object cannot be
|
|
// highlighted and moved by default. Inside this method, selection parameter
|
|
// is true by default making it possible to highlight and move the object
|
|
ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, selection);
|
|
ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection);
|
|
|
|
//
|
|
// hide true or display false graphical object name in the object list ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden);
|
|
|
|
//
|
|
// set the priority for receiving the event of a mouse click in the chart ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder);
|
|
|
|
//
|
|
// successful execution ...
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Move horizontal line ...
|
|
bool MoveHorizontalLine(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "HLine", // line name
|
|
double price = 0 // line price
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
// if the line price is not set, move it to the current Bid price level ...
|
|
if (!price)
|
|
{
|
|
price = SymbolInfoDouble(Symbol(), SYMBOL_BID);
|
|
}
|
|
|
|
//
|
|
// move a horizontal line ...
|
|
result = ObjectMove(chartID, objName, 0, 0, price);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Delete a horizontal line ...
|
|
bool DeleteHorizontalLine(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "HLine" // line name
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
// delete a horizontal line ...
|
|
result = ObjectDelete(chartID, objName);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Vertical Line Functions ...
|
|
|
|
//
|
|
// Create the vertical line ...
|
|
bool DrawVerticalLine(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "VLine", // line name
|
|
const int subWindow = 0, // subwindow index
|
|
datetime time = 0, // line time
|
|
const color clr = clrRed, // line color
|
|
const ENUM_LINE_STYLE style = STYLE_SOLID, // line style
|
|
const int width = 1, // line width
|
|
const bool back = false, // in the background
|
|
const bool selection = false, // highlight to move
|
|
const bool hidden = false, // hidden in the object list
|
|
const long zOrder = 0 // priority for mouse click
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// if the line time is not set, draw it via the last bar ...
|
|
if (!time)
|
|
{
|
|
time = TimeCurrent();
|
|
}
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
// create a vertical line ...
|
|
result = ObjectCreate(chartID, objName, OBJ_VLINE, subWindow, time, 0);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// set line color ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr);
|
|
|
|
//
|
|
// set line display style ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style);
|
|
|
|
//
|
|
// set line width ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width);
|
|
|
|
//
|
|
// display in the foreground false or background true ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_BACK, back);
|
|
|
|
//
|
|
// enable true or disable false the mode of moving the line by mouse
|
|
// when creating a graphical object using ObjectCreate function, the object cannot be
|
|
// highlighted and moved by default. Inside this method, selection parameter
|
|
// is true by default making it possible to highlight and move the object ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, true);
|
|
ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection);
|
|
|
|
//
|
|
// hide true or display false graphical object name in the object list ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden);
|
|
|
|
//
|
|
// set the priority for receiving the event of a mouse click in the chart
|
|
ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder);
|
|
|
|
//
|
|
// successful execution ...
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Move the vertical line ...
|
|
bool MoveVerticalLine(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "VLine", // line name
|
|
datetime time = 0 // line time
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
// if line time is not set, move the line to the last bar ...
|
|
if (!time)
|
|
{
|
|
time = TimeCurrent();
|
|
}
|
|
|
|
//
|
|
// move the vertical line ...
|
|
result = ObjectMove(chartID, objName, 0, time, 0);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Delete the vertical line ...
|
|
bool DeleteVerticalLine(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "VLine" // line name
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
// delete the vertical line ...
|
|
result = ObjectDelete(chartID, objName);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Rectangle Functions ...
|
|
|
|
//
|
|
// Create rectangle by the given coordinates ...
|
|
bool DrawRectangle(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "Rectangle", // rectangle name
|
|
const int subWindow = 0, // subwindow index
|
|
datetime time1 = 0, // down first point time
|
|
double price1 = 0, // down first point price
|
|
datetime time2 = 0, // up second point time
|
|
double price2 = 0, // up second point price
|
|
const color clr = clrRed, // rectangle color
|
|
const ENUM_LINE_STYLE style = STYLE_SOLID, // style of rectangle lines
|
|
const int width = 1, // width of rectangle lines
|
|
const bool fill = false, // filling rectangle with color
|
|
const bool back = false, // in the background
|
|
const bool selection = true, // highlight to move
|
|
const bool hidden = true, // hidden in the object list
|
|
const long zOrder = 0 // priority for mouse click
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Set anchor points' coordinates if they are not set ...
|
|
ChangeRectangleEmptyPoints(time1, price1, time2, price2);
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
// Create a rectangle by the given coordinates ...
|
|
result = ObjectCreate(
|
|
chartID,
|
|
objName,
|
|
OBJ_RECTANGLE,
|
|
subWindow,
|
|
time1,
|
|
price1,
|
|
time2,
|
|
price2 //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Set rectangle color ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr);
|
|
|
|
//
|
|
// Set the style of rectangle lines
|
|
ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style);
|
|
|
|
//
|
|
// Set width of the rectangle lines ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width);
|
|
|
|
//
|
|
// Enable (true) or disable (false) the mode of filling the rectangle ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_FILL, fill);
|
|
|
|
//
|
|
// Display in the foreground (false) or background (true) ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_BACK, back);
|
|
|
|
//
|
|
// Enable (true) or disable (false) the mode of highlighting the rectangle for moving
|
|
// when creating a graphical object using ObjectCreate function, the object cannot be
|
|
// highlighted and moved by default. Inside this method, selection parameter
|
|
// is true by default making it possible to highlight and move the object
|
|
ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, selection);
|
|
|
|
//
|
|
ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection);
|
|
|
|
//
|
|
// Hide (true) or display (false) graphical object name in the object list ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden);
|
|
|
|
//
|
|
// Set the priority for receiving the event of a mouse click in the chart ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder);
|
|
|
|
//
|
|
// Successful execution
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Move the rectangle anchor point ...s
|
|
bool RectanglePointChange(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "Rectangle", // rectangle name
|
|
const int pointIndex = 0, // anchor point index
|
|
datetime time = 0, // anchor point time coordinate
|
|
double price = 0 // anchor point price coordinate
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
// if point position is not set, move it to the current bar having Bid price ...
|
|
if (!time)
|
|
{
|
|
time = TimeCurrent();
|
|
}
|
|
|
|
//
|
|
if (!price)
|
|
{
|
|
price = SymbolInfoDouble(Symbol(), SYMBOL_BID);
|
|
}
|
|
|
|
//
|
|
// Move the anchor point ...
|
|
result = ObjectMove(chartID, objName, pointIndex, time, price);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Delete the rectangle ...
|
|
bool DeleteRectangle(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "Rectangle" // rectangle name
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
result = ObjectDelete(chartID, objName);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check the values of rectangle's anchor points and set default
|
|
// values for empty ones
|
|
void ChangeRectangleEmptyPoints(
|
|
datetime &time1, double &price1,
|
|
datetime &time2, double &price2 //
|
|
)
|
|
{
|
|
//
|
|
// if the first point's time is not set, it will be on the current bar ...
|
|
if (!time1)
|
|
{
|
|
time1 = TimeCurrent();
|
|
}
|
|
|
|
//
|
|
// if the first point's price is not set, it will have Bid value ...
|
|
if (!price1)
|
|
{
|
|
price1 = SymbolInfoDouble(Symbol(), SYMBOL_BID);
|
|
}
|
|
|
|
//
|
|
// if the second point's time is not set, it is located 9 bars left from the second one ...
|
|
if (!time2)
|
|
{
|
|
//
|
|
// array for receiving the open time of the last 10 bars ...
|
|
datetime temp[10];
|
|
CopyTime(Symbol(), Period(), time1, 10, temp);
|
|
|
|
//
|
|
// set the second point 9 bars left from the first one ...
|
|
time2 = temp[0];
|
|
}
|
|
|
|
//
|
|
// if the second point's price is not set, move it 300 points lower than the first one ...
|
|
if (!price2)
|
|
{
|
|
price2 = price1 - 300 * SymbolInfoDouble(Symbol(), SYMBOL_POINT);
|
|
}
|
|
}
|
|
|
|
//
|
|
// RectangleLabel Functions ...
|
|
|
|
//
|
|
// Create Rectangle Label Object ...
|
|
bool DrawRectangleLabel(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "RectLabel", // label name
|
|
const int subWindow = 0, // subwindow index
|
|
const int x = 0, // X coordinate
|
|
const int y = 0, // Y coordinate
|
|
const int width = 50, // width
|
|
const int height = 18, // height
|
|
const color bgColor = clrWhiteSmoke, // background color
|
|
const ENUM_BORDER_TYPE border = BORDER_SUNKEN, // border type
|
|
const ENUM_BASE_CORNER corner = CORNER_LEFT_UPPER, // chart corner for anchoring
|
|
const color clr = clrRed, // flat border color (Flat)
|
|
const ENUM_LINE_STYLE style = STYLE_SOLID, // flat border style
|
|
const int lineWidth = 1, // flat border width
|
|
const bool back = false, // in the background
|
|
const bool selection = false, // highlight to move
|
|
const bool hidden = false, // hidden in the object list
|
|
const long zOrder = 0 // priority for mouse click
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
// create a rectangle label
|
|
result = ObjectCreate(chartID, objName, OBJ_RECTANGLE_LABEL, subWindow, 0, 0);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// set label coordinates ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_XDISTANCE, x);
|
|
ObjectSetInteger(chartID, objName, OBJPROP_YDISTANCE, y);
|
|
|
|
//
|
|
// set label size ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_XSIZE, width);
|
|
ObjectSetInteger(chartID, objName, OBJPROP_YSIZE, height);
|
|
|
|
//
|
|
// set background color ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_BGCOLOR, bgColor);
|
|
|
|
//
|
|
// set border type ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_BORDER_TYPE, border);
|
|
|
|
//
|
|
// set the chart's corner, relative to which point coordinates are defined ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_CORNER, corner);
|
|
|
|
//
|
|
// set flat border color (in Flat mode) ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr);
|
|
|
|
//
|
|
// set flat border line style ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style);
|
|
|
|
//
|
|
// set flat border width ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, lineWidth);
|
|
|
|
//
|
|
// display in the foreground false or background true ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_BACK, back);
|
|
|
|
//
|
|
// enable true or disable false the mode of moving the label by mouse ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, selection);
|
|
ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection);
|
|
|
|
//
|
|
// hide true or display false graphical object name in the object list ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden);
|
|
|
|
//
|
|
// set the priority for receiving the event of a mouse click in the chart ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder);
|
|
|
|
//
|
|
// successful execution ...
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Move Rectangle Label ..
|
|
bool MoveRectangleLabel(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "RectLabel", // label name
|
|
const int x = 0, // X coordinate
|
|
const int y = 0 // Y coordinate
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
// move the rectangle label ...
|
|
result = ObjectSetInteger(chartID, objName, OBJPROP_XDISTANCE, x);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = ObjectSetInteger(chartID, objName, OBJPROP_YDISTANCE, y);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Delete the rectangle label ...
|
|
bool DeleteRectangleLabel(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "RectLabel" // label name
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
// delete the label ...
|
|
result = ObjectDelete(chartID, objName);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Change Rectangle Label Size ...
|
|
bool ChangeSizeRectangleLabel(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "RectLabel", // label name
|
|
const int width = 50, // label width
|
|
const int height = 18 // label height
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
// change label size ...
|
|
result = ObjectSetInteger(chartID, objName, OBJPROP_XSIZE, width);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = ObjectSetInteger(chartID, objName, OBJPROP_YSIZE, height);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Change rectangle label border type ...
|
|
bool RectLabelChangeBorderType(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "RectLabel", // label name
|
|
const ENUM_BORDER_TYPE border = BORDER_SUNKEN // border type
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
// change border type ...
|
|
result = ObjectSetInteger(chartID, objName, OBJPROP_BORDER_TYPE, border);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// TrendLine Funcions ...
|
|
|
|
//
|
|
// Create a trend line by the given coordinates ...
|
|
bool DrawTrendLine(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "TrendLine", // line name
|
|
const int subWindow = 0, // subwindow index
|
|
datetime time1 = 0, // first point time
|
|
double price1 = 0, // first point price
|
|
datetime time2 = 0, // second point time
|
|
double price2 = 0, // second point price
|
|
const color clr = clrYellow, // line color
|
|
const ENUM_LINE_STYLE style = STYLE_SOLID, // line style
|
|
const int width = 1, // line width
|
|
const bool back = false, // in the background
|
|
const bool selection = false, // highlight to move
|
|
const bool rayRight = false, // line's continuation to the right
|
|
const bool hidden = false, // hidden in the object list
|
|
const long zOrder = 0 // priority for mouse click
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// set anchor points' coordinates if they are not set ...
|
|
ChangeTrendLineEmptyPoints(
|
|
time1,
|
|
price1,
|
|
time2,
|
|
price2);
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
// create a trend line by the given coordinates ...
|
|
result = ObjectCreate(chartID, objName, OBJ_TREND, subWindow, time1, price1, time2, price2);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// set line color ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr);
|
|
|
|
//
|
|
// set line display style ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style);
|
|
|
|
//
|
|
// set line width ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width);
|
|
|
|
//
|
|
// display in the foreground false or background true ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_BACK, back);
|
|
|
|
//
|
|
// enable true or disable false the mode of moving the line by mouse
|
|
// when creating a graphical object using ObjectCreate function, the object cannot be
|
|
// highlighted and moved by default. Inside this method, selection parameter
|
|
// is true by default making it possible to highlight and move the object ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, true);
|
|
ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection);
|
|
|
|
//
|
|
// enable true or disable false the mode of continuation of the line's display to the right ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_RAY_RIGHT, rayRight);
|
|
|
|
//
|
|
// hide true or display false graphical object name in the object list ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden);
|
|
|
|
//
|
|
// set the priority for receiving the event of a mouse click in the chart ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder);
|
|
|
|
//
|
|
// successful execution ...
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Move trend line anchor point ... |
|
|
bool ChangeTrendLinePoint(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "TrendLine", // line name
|
|
const int pointindex = 0, // anchor point index
|
|
datetime time = 0, // anchor point time coordinate
|
|
double price = 0 // anchor point price coordinate
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
// if point position is not set, move it to the current bar having Bid price ...
|
|
if (!time)
|
|
{
|
|
time = TimeCurrent();
|
|
}
|
|
|
|
//
|
|
if (!price)
|
|
{
|
|
price = SymbolInfoDouble(Symbol(), SYMBOL_BID);
|
|
}
|
|
|
|
//
|
|
// move trend line's anchor point ...
|
|
result = ObjectMove(chartID, objName, pointindex, time, price);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// The function deletes the trend line from the chart ...
|
|
bool DeleteTrendLine(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "TrendLine" // line name
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
// delete a trend line ...
|
|
result = ObjectDelete(chartID, objName);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check the values of trend line's anchor points and set default ...
|
|
// values for empty ones ...
|
|
void ChangeTrendLineEmptyPoints(
|
|
datetime &time1,
|
|
double &price1,
|
|
datetime &time2,
|
|
double &price2 //
|
|
)
|
|
{
|
|
//
|
|
// if the first point's time is not set, it will be on the current bar ...
|
|
if (!time1)
|
|
{
|
|
time1 = TimeCurrent();
|
|
}
|
|
|
|
//
|
|
// if the first point's price is not set, it will have Bid value ...
|
|
if (!price1)
|
|
{
|
|
price1 = SymbolInfoDouble(Symbol(), SYMBOL_BID);
|
|
}
|
|
|
|
//
|
|
// if the second point's time is not set, it is located 9 bars left from the second one ...
|
|
if (!time2)
|
|
{
|
|
//
|
|
// array for receiving the open time of the last 10 bars ...
|
|
datetime temp[10];
|
|
CopyTime(Symbol(), Period(), time1, 10, temp);
|
|
|
|
//
|
|
// set the second point 9 bars left from the first one ...
|
|
time2 = temp[0];
|
|
}
|
|
|
|
//
|
|
// if the second point's price is not set, it is equal to the first point's one ...
|
|
if (!price2)
|
|
{
|
|
price2 = price1;
|
|
}
|
|
}
|
|
|
|
//
|
|
// Text Functions ...
|
|
|
|
//
|
|
// Create and Draw a Text Object ...
|
|
bool DrawText(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "Text", // object name
|
|
const int subWindow = 0, // subwindow index
|
|
datetime time = 0, // anchor point time
|
|
double price = 0, // anchor point price
|
|
const string text = "Text", // the text itself
|
|
const string font = "Arial", // font
|
|
const int fontSize = 10, // font size
|
|
const color clr = clrRed, // color
|
|
const double angle = 0.0, // text slope
|
|
const ENUM_ANCHOR_POINT anchor = ANCHOR_CENTER, // 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 zOrder = 0 // priority for mouse click
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// set anchor point coordinates if they are not set ...
|
|
ChangeTextEmptyPoint(time, price);
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
//
|
|
// create Text object
|
|
result = ObjectCreate(chartID, objName, OBJ_TEXT, subWindow, time, price);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// set the text ...
|
|
ObjectSetString(chartID, objName, OBJPROP_TEXT, text);
|
|
|
|
//
|
|
// set text font ...
|
|
ObjectSetString(chartID, objName, OBJPROP_FONT, font);
|
|
|
|
//
|
|
// set font size ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_FONTSIZE, fontSize);
|
|
|
|
//
|
|
// set the slope angle of the text ...
|
|
ObjectSetDouble(chartID, objName, OBJPROP_ANGLE, angle);
|
|
|
|
//
|
|
// set anchor type ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_ANCHOR, anchor);
|
|
|
|
//
|
|
// set color ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr);
|
|
|
|
//
|
|
// display in the foreground false or background true ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_BACK, back);
|
|
|
|
//
|
|
// enable true or disable false the mode of moving the object by mouse ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, true);
|
|
ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection);
|
|
|
|
//
|
|
// hide true or display false graphical object name in the object list ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden);
|
|
|
|
//
|
|
// set the priority for receiving the event of a mouse click in the chart ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder);
|
|
|
|
//
|
|
// successful execution ...
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Move the anchor point ...
|
|
bool MoveText(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "Text", // object name
|
|
datetime time = 0, // anchor point time coordinate
|
|
double price = 0 // anchor point price coordinate
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
//
|
|
// if point position is not set, move it to the current bar having Bid price
|
|
if (!time)
|
|
{
|
|
time = TimeCurrent();
|
|
}
|
|
|
|
//
|
|
if (!price)
|
|
{
|
|
price = SymbolInfoDouble(_Symbol, SYMBOL_BID);
|
|
}
|
|
|
|
//
|
|
// move the anchor point ...
|
|
result = ObjectMove(chartID, objName, 0, time, price);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Change the object text ...
|
|
bool ChangeText(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "Text", // object name
|
|
const string text = "Text" // text
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
// change object text ...
|
|
result = ObjectSetString(chartID, objName, OBJPROP_TEXT, text);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Delete Text object ...
|
|
bool DeleteText(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "Text" // object name
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
// delete the object ...
|
|
result = ObjectDelete(chartID, objName);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check anchor point values and set default values
|
|
// for empty ones ...
|
|
void ChangeTextEmptyPoint(
|
|
datetime &time,
|
|
double &price //
|
|
)
|
|
{
|
|
//
|
|
// if the point's time is not set, it will be on the current bar ...
|
|
if (!time)
|
|
{
|
|
time = TimeCurrent();
|
|
}
|
|
|
|
//
|
|
// if the point's price is not set, it will have Bid value ...
|
|
if (!price)
|
|
{
|
|
price = SymbolInfoDouble(_Symbol, SYMBOL_BID);
|
|
}
|
|
}
|
|
|
|
//
|
|
// Fibonacchi Functions ...
|
|
|
|
//
|
|
// Create Fibonacci Retracement by the given coordinates ...
|
|
bool DrawFibonacci(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "Fibonacci", // object name
|
|
const int subWindow = 0, // subwindow index
|
|
datetime time1 = 0, // first point time
|
|
double price1 = 0, // first point price
|
|
datetime time2 = 0, // second point time
|
|
double price2 = 0, // second point price
|
|
const color clr = clrRed, // object color
|
|
const ENUM_LINE_STYLE style = STYLE_SOLID, // object line style
|
|
const int width = 1, // object line width
|
|
const bool back = false, // in the background
|
|
const bool selection = true, // highlight to move
|
|
const bool rayRight = false, // object's continuation to the right
|
|
const bool hidden = true, // hidden in the object list
|
|
const long zOrder = 0 // priority for mouse click
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// set anchor points' coordinates if they are not set ...
|
|
ChangeFibonacciEmptyPoints(time1, price1, time2, price2);
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
// Create Fibonacci Retracement by the given coordinates ...
|
|
result = ObjectCreate(chartID, objName, OBJ_FIBO, subWindow, time1, price1, time2, price2);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// set color ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr);
|
|
|
|
//
|
|
// set line style ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style);
|
|
|
|
//
|
|
// set line width ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width);
|
|
|
|
//
|
|
// display in the foreground false or background true ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_BACK, back);
|
|
|
|
//
|
|
// enable true or disable false the mode of highlighting the channel for moving
|
|
// when creating a graphical object using ObjectCreate function, the object cannot be
|
|
// highlighted and moved by default. Inside this method, selection parameter
|
|
// is true by default making it possible to highlight and move the object ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, true);
|
|
ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection);
|
|
|
|
//
|
|
// enable true or disable false the mode of continuation of the object's display to the right ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_RAY_RIGHT, rayRight);
|
|
|
|
//
|
|
// hide true or display false graphical object name in the object list ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden);
|
|
|
|
//
|
|
// set the priority for receiving the event of a mouse click in the chart ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder);
|
|
|
|
//
|
|
// successful execution ...
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Create Fibonacci Retracement by the given coordinates ...
|
|
bool DrawCustomFibonacci(
|
|
//
|
|
int levels, // number of level lines
|
|
double &values[], // values of level lines
|
|
color &colors[], // color of level lines
|
|
ENUM_LINE_STYLE &styles[], // style of level lines
|
|
int &widths[], // width of level lines
|
|
string &descriptions[], // level Descriptions
|
|
//
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "Fibonacci", // object name
|
|
const int subWindow = 0, // subwindow index
|
|
datetime time1 = 0, // first point time
|
|
double price1 = 0, // first point price
|
|
datetime time2 = 0, // second point time
|
|
double price2 = 0, // second point price
|
|
const color clr = clrAqua, // object color
|
|
const ENUM_LINE_STYLE style = STYLE_DOT, // object line style
|
|
const int width = 1, // object line width
|
|
const bool back = false, // in the background
|
|
const bool selection = true, // highlight to move
|
|
const bool rayRight = false, // object's continuation to the right
|
|
const bool hidden = true, // hidden in the object list
|
|
const long zOrder = 0 // priority for mouse click
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// set anchor points' coordinates if they are not set ...
|
|
ChangeFibonacciEmptyPoints(time1, price1, time2, price2);
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
// Create Fibonacci Retracement by the given coordinates ...
|
|
result = ObjectCreate(chartID, name, OBJ_FIBO, subWindow, time1, price1, time2, price2);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// set color ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr);
|
|
|
|
//
|
|
// set line style ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style);
|
|
|
|
//
|
|
// set line width ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width);
|
|
|
|
//
|
|
// display in the foreground false or background true ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_BACK, back);
|
|
|
|
//
|
|
// enable true or disable false the mode of highlighting the channel for moving
|
|
// when creating a graphical object using ObjectCreate function, the object cannot be
|
|
// highlighted and moved by default. Inside this method, selection parameter
|
|
// is true by default making it possible to highlight and move the object ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, true);
|
|
ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection);
|
|
|
|
//
|
|
// enable true or disable false the mode of continuation of the object's display to the right ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_RAY_RIGHT, rayRight);
|
|
|
|
//
|
|
// hide true or display false graphical object name in the object list ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden);
|
|
|
|
//
|
|
// set the priority for receiving the event of a mouse click in the chart ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder);
|
|
|
|
//
|
|
// Change Levels Of Fibonacci ...
|
|
result = FibonacciLevelsSet(
|
|
levels,
|
|
values,
|
|
colors,
|
|
styles,
|
|
widths,
|
|
descriptions,
|
|
chartID,
|
|
objName);
|
|
|
|
//
|
|
// successful execution ...
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Set number of levels and their parameters ...
|
|
bool FibonacciLevelsSet(
|
|
int levels, // number of level lines
|
|
double &values[], // values of level lines
|
|
color &colors[], // color of level lines
|
|
ENUM_LINE_STYLE &styles[], // style of level lines
|
|
int &widths[], // width of level lines
|
|
string &descriptions[], // level Descriptions
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "Fibonacci" // object name
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// check array sizes ...
|
|
result = levels == ArraySize(colors) &&
|
|
levels == ArraySize(styles) &&
|
|
levels == ArraySize(widths) &&
|
|
levels == ArraySize(widths);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
// set the number of levels ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_LEVELS, levels);
|
|
|
|
//
|
|
// set the properties of levels in the loop ...
|
|
for (int i = 0; i < levels; i++)
|
|
{
|
|
//
|
|
// level value ...
|
|
ObjectSetDouble(chartID, objName, OBJPROP_LEVELVALUE, i, values[i]);
|
|
|
|
//
|
|
// level color ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_LEVELCOLOR, i, colors[i]);
|
|
|
|
//
|
|
// level style ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_LEVELSTYLE, i, styles[i]);
|
|
|
|
//
|
|
// level width ...
|
|
ObjectSetInteger(chartID, objName, OBJPROP_LEVELWIDTH, i, widths[i]);
|
|
|
|
//
|
|
// level description ...
|
|
// ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, DoubleToString(100 * values[i], 1));
|
|
ObjectSetString(chartID, objName, OBJPROP_LEVELTEXT, i, descriptions[i]);
|
|
}
|
|
|
|
//
|
|
// successful execution ...
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Move Fibonacci Retracement anchor point ...
|
|
bool FibonacciPointChange(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "Fibonacci", // object name
|
|
const int pointIndex = 0, // anchor point index
|
|
datetime time = 0, // anchor point time coordinate
|
|
double price = 0 // anchor point price coordinate
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
// if point position is not set, move it to the current bar having Bid price ...
|
|
if (!time)
|
|
{
|
|
time = TimeCurrent();
|
|
}
|
|
|
|
//
|
|
if (!price)
|
|
{
|
|
price = SymbolInfoDouble(_Symbol, SYMBOL_BID);
|
|
}
|
|
|
|
//
|
|
// move the anchor point ...
|
|
result = ObjectMove(chartID, objName, pointIndex, time, price);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Delete Fibonacci Retracement ...
|
|
bool DeleteFibonachi(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "Fibonacci" // object name
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
// delete the object ...
|
|
result = ObjectDelete(chartID, objName);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check the values of Fibonacci Retracement anchor points and set
|
|
// default values for empty ones ...
|
|
void ChangeFibonacciEmptyPoints(
|
|
datetime &time1,
|
|
double &price1,
|
|
datetime &time2,
|
|
double &price2 //
|
|
)
|
|
{
|
|
//
|
|
// if the second point's time is not set, it will be on the current bar ...
|
|
if (!time2)
|
|
{
|
|
time2 = TimeCurrent();
|
|
}
|
|
|
|
//
|
|
// if the second point's price is not set, it will have Bid value ...
|
|
if (!price2)
|
|
{
|
|
price2 = SymbolInfoDouble(_Symbol, SYMBOL_BID);
|
|
}
|
|
|
|
//
|
|
// if the first point's time is not set, it is located 9 bars left from the second one ...
|
|
if (!time1)
|
|
{
|
|
//
|
|
// array for receiving the open time of the last 10 bars ...
|
|
datetime temp[10];
|
|
CopyTime(Symbol(), Period(), time2, 10, temp);
|
|
|
|
//
|
|
// set the first point 9 bars left from the second one ...
|
|
time1 = temp[0];
|
|
}
|
|
|
|
//
|
|
// if the first point's price is not set, move it 200 points below the second one ...
|
|
if (!price1)
|
|
{
|
|
price1 = price2 - 200 * SymbolInfoDouble(_Symbol, SYMBOL_POINT);
|
|
}
|
|
}
|
|
|
|
//
|
|
// Event Functions ...
|
|
|
|
//
|
|
// Create an Event ...
|
|
bool EventCreate(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "Event", // object name
|
|
const int subWindow = 0, // subwindow index
|
|
const string text = "Content", // event text
|
|
datetime time = 0, // anchor point time
|
|
const color clr = clrRed, // color
|
|
const int width = 1, // point width when highlighted
|
|
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 zOrder = 0 // priority for mouse click
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (!time)
|
|
{
|
|
time = TimeCurrent();
|
|
}
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
result = ObjectCreate(chartID, objName, OBJ_EVENT, subWindow, time, 0);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// set event text
|
|
ObjectSetString(chartID, objName, OBJPROP_TEXT, text);
|
|
|
|
//
|
|
// set color
|
|
ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr);
|
|
|
|
//
|
|
// set anchor point width if the object is highlighted
|
|
ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width);
|
|
|
|
//
|
|
// display in the foreground false or background true
|
|
ObjectSetInteger(chartID, objName, OBJPROP_BACK, back);
|
|
|
|
//
|
|
// enable true or disable false the mode of moving event by mouse
|
|
ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, selection);
|
|
ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection);
|
|
|
|
//
|
|
// hide true or display false graphical object name in the object list
|
|
ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden);
|
|
|
|
//
|
|
// set the priority for receiving the event of a mouse click in the chart
|
|
ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder);
|
|
|
|
//
|
|
// successful execution
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Change Event object text
|
|
bool EventTextChange(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "Event", // event name
|
|
const string text = "Content" // text
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
// change object text
|
|
result = ObjectSetString(chartID, objName, OBJPROP_TEXT, text);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Move Event object
|
|
bool EventMove(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "Event", // event name
|
|
datetime time = 0 // time
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
// if time is not set, move event to the last bar
|
|
if (!time)
|
|
{
|
|
time = TimeCurrent();
|
|
}
|
|
|
|
//
|
|
// move the object
|
|
result = ObjectMove(chartID, objName, 0, time, 0);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Delete Event object
|
|
bool EventDelete(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "Event" // event name
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
// delete the object
|
|
result = ObjectDelete(chartID, objName);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Button Functions ...
|
|
|
|
//
|
|
// Create the button ...
|
|
bool ButtonCreate(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "Button", // button name
|
|
const int subWindow = 0, // subwindow index
|
|
const int x = 0, // X coordinate
|
|
const int y = 0, // Y coordinate
|
|
const int width = 50, // button width
|
|
const int height = 15, // button height
|
|
const ENUM_BASE_CORNER corner = CORNER_LEFT_UPPER, // chart corner for anchoring
|
|
const string text = "Button", // text
|
|
const string font = "Arial", // font
|
|
const int fontSize = 8, // font size
|
|
const color clr = clrBlack, // text color
|
|
const color bgColor = clrLightGray, // background color
|
|
const color borderColor = clrNONE, // border color
|
|
const bool state = false, // pressed/released
|
|
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 zOrder = 0 // priority for mouse click
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
// create the button
|
|
result = ObjectCreate(chartID, objName, OBJ_BUTTON, subWindow, 0, 0);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// set button coordinates
|
|
ObjectSetInteger(chartID, objName, OBJPROP_XDISTANCE, x);
|
|
ObjectSetInteger(chartID, objName, OBJPROP_YDISTANCE, y);
|
|
|
|
//
|
|
// set button size
|
|
ObjectSetInteger(chartID, objName, OBJPROP_XSIZE, width);
|
|
ObjectSetInteger(chartID, objName, OBJPROP_YSIZE, height);
|
|
|
|
//
|
|
// set the chart's corner, relative to which point coordinates are defined
|
|
ObjectSetInteger(chartID, objName, OBJPROP_CORNER, corner);
|
|
|
|
//
|
|
// set the text
|
|
ObjectSetString(chartID, objName, OBJPROP_TEXT, text);
|
|
|
|
//
|
|
// set text font
|
|
ObjectSetString(chartID, objName, OBJPROP_FONT, font);
|
|
|
|
//
|
|
// set font size
|
|
ObjectSetInteger(chartID, objName, OBJPROP_FONTSIZE, fontSize);
|
|
|
|
//
|
|
// set text color
|
|
ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr);
|
|
|
|
//
|
|
// set background color
|
|
ObjectSetInteger(chartID, objName, OBJPROP_BGCOLOR, bgColor);
|
|
|
|
//
|
|
// set border color
|
|
ObjectSetInteger(chartID, objName, OBJPROP_BORDER_COLOR, borderColor);
|
|
|
|
//
|
|
// display in the foreground false or background true
|
|
ObjectSetInteger(chartID, objName, OBJPROP_BACK, back);
|
|
|
|
//
|
|
// set button state
|
|
ObjectSetInteger(chartID, objName, OBJPROP_STATE, state);
|
|
|
|
//
|
|
// enable true or disable false the mode of moving the button by mouse
|
|
ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, selection);
|
|
ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection);
|
|
|
|
//
|
|
// hide true or display false graphical object name in the object list
|
|
ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden);
|
|
|
|
//
|
|
// set the priority for receiving the event of a mouse click in the chart
|
|
ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Move the button ...
|
|
bool ButtonMove(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "Button", // button name
|
|
const int x = 0, // X coordinate
|
|
const int y = 0 // Y coordinate
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// move the button
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
result = ObjectSetInteger(chartID, objName, OBJPROP_XDISTANCE, x);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = ObjectSetInteger(chartID, objName, OBJPROP_YDISTANCE, y);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Change button size ...
|
|
bool ButtonChangeSize(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "Button", // button name
|
|
const int width = 50, // button width
|
|
const int height = 18 // button height
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// change the button size
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
result = ObjectSetInteger(chartID, objName, OBJPROP_XSIZE, width);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = ObjectSetInteger(chartID, objName, OBJPROP_YSIZE, height);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Change corner of the chart for binding the button ...
|
|
bool ButtonChangeCorner(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "Button", // button name
|
|
const ENUM_BASE_CORNER corner = CORNER_LEFT_UPPER // chart corner for anchoring
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
// change anchor corner
|
|
result = ObjectSetInteger(chartID, objName, OBJPROP_CORNER, corner);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Change button text ...
|
|
bool ButtonTextChange(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "Button", // button name
|
|
const string text = "Text" // text
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
// change object text
|
|
result = ObjectSetString(chartID, objName, OBJPROP_TEXT, text);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Delete the button ...
|
|
bool ButtonDelete(
|
|
const long chartID = 0, // chart's ID
|
|
const string name = "Button" // button name
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize Name ...
|
|
string objName = drawPrefix + "_" + name;
|
|
|
|
//
|
|
// delete the button
|
|
result = ObjectDelete(chartID, objName);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Chart Style Drawers ...
|
|
|
|
//
|
|
// Apply Styles On Chart ...
|
|
void ApplyChartStyle(
|
|
long mChartId = -1, // chart's ID
|
|
ENUM_CHART_MODE mMode = CHART_CANDLES, // chart's mMode
|
|
bool mShowBidLine = true, // show bid line
|
|
bool mShowAskLine = true, // show ask line
|
|
bool mShowGrid = false, // show grids on chart
|
|
bool mShowVolumes = false, // show volumes
|
|
bool mShowTradeLevels = true, // Displaying trade levels in the chart (levels of open positions, Stop Loss, Take Profit and pending orders)
|
|
bool mAutoScroll = true, // chart autoscroll
|
|
bool mQuickNavigation = true, // chart quick navigation state
|
|
color mForeGroundColor = clrWhite, // chart's foreground color
|
|
color mBackGroundColor = clrBlack, // chart's background color
|
|
color mUpColor = clrGreen, // Up Color
|
|
color mDownColor = clrRed, // Down Color
|
|
color mBullishColor = clrGreen, // Bullish color
|
|
color mBearishColor = clrRed, // Bearish color
|
|
color mGridColor = clrGray, // grid color
|
|
color mBidLineColor = clrGray, // bid line color
|
|
color mAskLineColor = clrRed, // ask line color
|
|
color mLineColor = clrLime, // line mMode and doji candlestick color
|
|
color mStopColor = clrGold, // Color of stop order levels (Stop Loss and Take Profit)
|
|
color mVolumesColor = clrGreen // volumes color
|
|
)
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
if (mChartId == -1)
|
|
{
|
|
mChartId = 0;
|
|
}
|
|
|
|
//
|
|
ChartSetInteger(mChartId, CHART_MODE, mMode);
|
|
ChartSetInteger(mChartId, CHART_SHOW_BID_LINE, mShowBidLine);
|
|
ChartSetInteger(mChartId, CHART_SHOW_ASK_LINE, mShowAskLine);
|
|
ChartSetInteger(mChartId, CHART_SHOW_GRID, mShowGrid);
|
|
ChartSetInteger(mChartId, CHART_SHOW_VOLUMES, mShowVolumes);
|
|
ChartSetInteger(mChartId, CHART_SHOW_TRADE_LEVELS, mShowTradeLevels);
|
|
ChartSetInteger(mChartId, CHART_AUTOSCROLL, mAutoScroll);
|
|
ChartSetInteger(mChartId, CHART_QUICK_NAVIGATION, mQuickNavigation);
|
|
ChartSetInteger(mChartId, CHART_COLOR_FOREGROUND, mForeGroundColor);
|
|
ChartSetInteger(mChartId, CHART_COLOR_BACKGROUND, mBackGroundColor);
|
|
ChartSetInteger(mChartId, CHART_COLOR_CHART_UP, mUpColor);
|
|
ChartSetInteger(mChartId, CHART_COLOR_CHART_DOWN, mDownColor);
|
|
ChartSetInteger(mChartId, CHART_COLOR_CANDLE_BULL, mBullishColor);
|
|
ChartSetInteger(mChartId, CHART_COLOR_CANDLE_BEAR, mBearishColor);
|
|
ChartSetInteger(mChartId, CHART_COLOR_GRID, mGridColor);
|
|
ChartSetInteger(mChartId, CHART_COLOR_BID, mBidLineColor);
|
|
ChartSetInteger(mChartId, CHART_COLOR_ASK, mAskLineColor);
|
|
ChartSetInteger(mChartId, CHART_COLOR_STOP_LEVEL, mStopColor);
|
|
ChartSetInteger(mChartId, CHART_COLOR_CHART_LINE, mLineColor);
|
|
ChartSetInteger(mChartId, CHART_COLOR_VOLUME, mVolumesColor);
|
|
}
|
|
|
|
//
|
|
// Tools ...
|
|
|
|
//
|
|
// Retrieve Chart Size ...
|
|
bool GetChartSize(
|
|
XSize &result, // Holds Result ...
|
|
long chartID = 0 // Specified Chart ID ...
|
|
)
|
|
{
|
|
//
|
|
bool mResult = false;
|
|
|
|
//
|
|
mResult = ChartGetInteger(0, CHART_WIDTH_IN_PIXELS, 0, result.width);
|
|
if (!mResult)
|
|
{
|
|
return mResult;
|
|
}
|
|
|
|
//
|
|
mResult = ChartGetInteger(0, CHART_HEIGHT_IN_PIXELS, 0, result.height);
|
|
|
|
//
|
|
return mResult;
|
|
}
|