/////////////////////////////////////////////////////// // // 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 // // START Inputs ... // // // END Inputs ... // // // Include Logger Library ... #include "x-saherelm.log.lib.mq5" // // START Global Definitions: Variables, Properties and etc ... // string drawPrefix = "X-OBJ"; // // END Global Definitions: Variables, Properties and etc ... // // // START Provided Functions ... // // // DeInitial Library if required ... void OnDeinitDrawLibrary() { RemoveDraws(); } // void DrawSignalShape( XSignal &signal, // Specify Signal to Draw color longColor = clrAqua, // Long Signals Color color shortColor = clrFuchsia, // Short Signal Color color entryColor = clrGold // Signal Entry Price Color ) { // // Draw Signal Info : // - Draw Entry Price Line; // - Draw SL; // - Draw TP; // - Risk Free; // bool isLong = signal.type == X_SIGNAL_LONG; // color tpColor = longColor; color slColor = shortColor; // string name = "T(" + (string) signal.ticket + ")" + "_" + "TY(" + EnumToString(signal.type) + ")" + "_" + "KI(" + EnumToString(signal.kind) + ")"; string tpName = "TP_" + name; string slName = "SL_" + name; string riskFreeName = "RF_" + name; string entryName = "Entry_" + name; // int signalBarIndex = iBarShift( signal.symbol, _Period, signal.time ); // datetime time1 = iTime( signal.symbol, _Period, signalBarIndex + 1 ); datetime time2 = iTime( signal.symbol, _Period, signalBarIndex - 1 ); // // Entry ... bool isTrendLineDrawn = DrawTrendLine( 0, entryName, 0, time1, signal.entry, time2, signal.entry, entryColor ); // // TP ... bool isTPDrawn = false; if (signal.tp > 0) { // isTPDrawn = DrawTrendLine( 0, tpName, 0, time1, signal.tp, time2, signal.tp, tpColor, STYLE_SOLID, 1, false, true ); } // // RISKFREE ... bool isRFDrawn = false; if (signal.riskFree > 0) { // isRFDrawn = DrawTrendLine( 0, riskFreeName, 0, time1, signal.riskFree, time2, signal.riskFree, tpColor, STYLE_DOT, 1, false, true ); } // // SL ... bool isSLDrawn = false; if (signal.sl > 0) { // isSLDrawn = DrawTrendLine( 0, slName, 0, time1, signal.sl, time2, signal.sl, slColor, STYLE_SOLID, 1, false, true ); } } // // remove drawn objects ... void RemoveDraws( string tag = NULL, int 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(); } // // END Provided Functions ... // // // START Regular Draws ... // // // START 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 ... ) { // // 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 ... if (!ObjectCreate(chartID, objName, OBJ_ARROW, subWindow, time, price)) { // string message = __FUNCTION__ + ": failed to create an arrow! Error code = " + (string)GetLastError(); // LogMessage(message); // return (false); } // // 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 (true); } // // 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 ) { // // 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); } // // reset the error value ResetLastError(); // // move the anchor point ... if (!ObjectMove(chartID, name, 0, time, price)) { // string message = __FUNCTION__ + ": failed to move the anchor point! Error code = " + (string)GetLastError(); // LogMessage(message); // return (false); } // // successful execution ... return (true); } // // Delete an arrow ... bool DeleteArrow( const long chartID = 0, // chart's ID const string name = "Arrow" // arrow name ) { // // reset the error value ... ResetLastError(); // // delete an arrow ... if (!ObjectDelete(chartID, name)) { // string message = __FUNCTION__ + ": failed to delete an arrow! Error code = " + (string)GetLastError(); // LogMessage(message); // return (false); } // // successful execution ... return (true); } // // 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 ) { // // reset the error value ... ResetLastError(); // // change the arrow code ... if (!ObjectSetInteger(chartID, name, OBJPROP_ARROWCODE, code)) { // string message = __FUNCTION__ + ": failed to change the arrow code! Error code = " + (string)GetLastError(); // LogMessage(message); // return (false); } // // successful execution ... return (true); } // // 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 ) { // // reset the error value ... ResetLastError(); // // change anchor type ... if (!ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor)) { // string message = __FUNCTION__ + ": failed to change anchor type! Error code = " + (string)GetLastError(); // LogMessage(message); // return (false); } // // successful execution ... return (true); } // // 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); } } // // END Arrow Functions ... // // // START 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 ) { // // if the price is not set, set it at the current Bid price level ... if (!price) { price = SymbolInfoDouble(Symbol(), SYMBOL_BID); } // // reset the error value ... ResetLastError(); // // Normalize Name ... string objName = drawPrefix + "_" + name; // // create a horizontal line ... if (!ObjectCreate(chartID, objName, OBJ_HLINE, subWindow, 0, price)) { // string message = __FUNCTION__ + ": failed to create a horizontal line! Error code = " + (string)GetLastError(); // LogMessage(message); // return (false); } // // 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 (true); } // // Move horizontal line ... bool MoveHorizontalLine( const long chartID = 0, // chart's ID const string name = "HLine", // line name double price = 0 // line price ) { // // if the line price is not set, move it to the current Bid price level ... if (!price) { price = SymbolInfoDouble(Symbol(), SYMBOL_BID); } // // reset the error value ... ResetLastError(); // // move a horizontal line ... if (!ObjectMove(chartID, name, 0, 0, price)) { // string message = __FUNCTION__ + ": failed to move the horizontal line! Error code = " + (string)GetLastError(); // LogMessage(message); // return (false); } // // successful execution ... return (true); } // // Delete a horizontal line ... bool DeleteHorizontalLine( const long chartID = 0, // chart's ID const string name = "HLine" // line name ) { // // reset the error value ... ResetLastError(); // // delete a horizontal line ... if (!ObjectDelete(chartID, name)) { // string message = __FUNCTION__ + ": failed to delete a horizontal line! Error code = " + (string)GetLastError(); // LogMessage(message); // return (false); } // // successful execution ... return (true); } // // END Horizontal Line Functions ... // // // START Vertical Line Functions ... // // // Create the vertical line ... bool DrawVerticalLine( const long chartID = 0, // chart's ID const string name = "VLine", // line name const int sub_window = 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 ) { // // if the line time is not set, draw it via the last bar ... if (!time) { time = TimeCurrent(); } // // reset the error value ResetLastError(); // // Normalize Name ... string objName = drawPrefix + "_" + name; // // create a vertical line ... if (!ObjectCreate(chartID, objName, OBJ_VLINE, sub_window, time, 0)) { // string message = __FUNCTION__ + ": failed to create a vertical line! Error code = " + (string)GetLastError(); // LogMessage(message); // return false; } // // 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 true; } // // Move the vertical line ... bool MoveVerticalLine( const long chartID = 0, // chart's ID const string name = "VLine", // line name datetime time = 0 // line time ) { // // if line time is not set, move the line to the last bar ... if (!time) { time = TimeCurrent(); } // // reset the error value ... ResetLastError(); // // move the vertical line ... if (!ObjectMove(chartID, name, 0, time, 0)) { // string message = __FUNCTION__ + ": failed to move the vertical line! Error code = " + (string)GetLastError(); // LogMessage(message); // return (false); } // // successful execution ... return (true); } // // Delete the vertical line ... bool DeleteVerticalLine( const long chartID = 0, // chart's ID const string name = "VLine" // line name ) { // // reset the error value ... ResetLastError(); // // delete the vertical line ... if (!ObjectDelete(chartID, name)) { // string message = __FUNCTION__ + ": failed to delete the vertical line! Error code = " + (string)GetLastError(); // LogMessage(message); // return false; } // // successful execution ... return true; } // // END Vertical Line Functions ... // // // START 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 back_clr = 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 ) { // // reset the error value ... ResetLastError(); // // Normalize Name ... string objName = drawPrefix + "_" + name; // //--- create a rectangle label if (!ObjectCreate(chartID, objName, OBJ_RECTANGLE_LABEL, subWindow, 0, 0)) { // string message = __FUNCTION__ + ": failed to create a rectangle label! Error code = " + (string)GetLastError(); // LogMessage(message); // return (false); } // // 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, back_clr); // // 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 (true); } // // 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 ) { // // reset the error value ... ResetLastError(); // // move the rectangle label ... if (!ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x)) { // string message = __FUNCTION__ + ": failed to move X coordinate of the label! Error code = " + (string)GetLastError(); // LogMessage(message); // return (false); } // if (!ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y)) { // string message = __FUNCTION__ + ": failed to move Y coordinate of the label! Error code = " + (string)GetLastError(); // return (false); } // // successful execution ... return (true); } // // Delete the rectangle label ... bool DeleteRectangleLabel( const long chartID = 0, // chart's ID const string name = "RectLabel" // label name ) { // // reset the error value ... ResetLastError(); // // delete the label ... if (!ObjectDelete(chartID, name)) { // string message = __FUNCTION__ + ": failed to delete a rectangle label! Error code = " + (string)GetLastError(); // LogMessage(message); // return (false); } // // successful execution ... return (true); } // // 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 ) { // // reset the error value ... ResetLastError(); // // change label size ... if (!ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width)) { // string message = __FUNCTION__ + ": failed to change the label's width! Error code = " + (string)GetLastError(); // LogMessage(message); // return (false); } // if (!ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height)) { // string message = __FUNCTION__ + ": failed to change the label's height! Error code = " + (string)GetLastError(); // LogMessage(message); // return (false); } // // successful execution ... return (true); } // // 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 ) { // // reset the error value ... ResetLastError(); // // change border type ... if (!ObjectSetInteger(chartID, name, OBJPROP_BORDER_TYPE, border)) { // string message = __FUNCTION__ + ": failed to change the border type! Error code = " + (string)GetLastError(); // LogMessage(message); // return (false); } // // successful execution ... return (true); } // // END RectangleLabel Functions ... // // // START 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 ) { // // set anchor points' coordinates if they are not set ... ChangeTrendLineEmptyPoints( time1, price1, time2, price2); // // reset the error value ... ResetLastError(); // // Normalize Name ... string objName = drawPrefix + "_" + name; // // create a trend line by the given coordinates ... if (!ObjectCreate(chartID, objName, OBJ_TREND, subWindow, time1, price1, time2, price2)) { // string message = __FUNCTION__ + ": failed to create a trend line! Error code = " + (string)GetLastError(); // LogMessage(message); // return (false); } // // 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 (true); } // // 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 ) { // // 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); } // // reset the error value ... ResetLastError(); // // move trend line's anchor point ... if (!ObjectMove(chartID, name, pointindex, time, price)) { // string message = __FUNCTION__ + ": failed to move the anchor point! Error code = " + (string)GetLastError(); // LogMessage(message); // return (false); } // // successful execution ... return (true); } // // The function deletes the trend line from the chart ... bool DeleteTrendLine( const long chartID = 0, // chart's ID const string name = "TrendLine" // line name ) { // // reset the error value ... ResetLastError(); // // delete a trend line ... if (!ObjectDelete(chartID, name)) { // string message = __FUNCTION__ + ": failed to delete a trend line! Error code = " + (string)GetLastError(); // LogMessage(message); // return (false); } // // successful execution ... return (true); } // // 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; } } // // END TrendLine Functions ... // // // START 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 ) { // // set anchor point coordinates if they are not set ... ChangeTextEmptyPoint(time, price); // // reset the error value ... ResetLastError(); // // Normalize Name ... string objName = drawPrefix + "_" + name; // //--- create Text object if (!ObjectCreate(chartID, objName, OBJ_TEXT, subWindow, time, price)) { // string message = __FUNCTION__ + ": failed to create \"Text\" object! Error code = " + (string)GetLastError(); // LogMessage(message); // return (false); } // // 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 (true); } // // 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 ) { // //--- 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); } // // reset the error value ... ResetLastError(); // // move the anchor point .. if (!ObjectMove(chartID, name, 0, time, price)) { // string message = __FUNCTION__ + ": failed to move the anchor point! Error code = " + (string)GetLastError(); // LogMessage(message); // return (false); } // // successful execution ... return (true); } // // Change the object text ... bool ChangeText( const long chartID = 0, // chart's ID const string name = "Text", // object name const string text = "Text" // text ) { // // reset the error value ... ResetLastError(); // // change object text ... if (!ObjectSetString(chartID, name, OBJPROP_TEXT, text)) { // string message = __FUNCTION__ + ": failed to change the text! Error code = " + (string)GetLastError(); // LogMessage(message); // return (false); } // // successful execution ... return (true); } // // Delete Text object ... bool DeleteText( const long chartID = 0, // chart's ID const string name = "Text" // object name ) { // // reset the error value ... ResetLastError(); // // delete the object ... if (!ObjectDelete(chartID, name)) { // string message = __FUNCTION__ + ": failed to delete \"Text\" object! Error code = " + (string)GetLastError(); // LogMessage(message); // return (false); } // // successful execution return (true); } // // 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); } } // // END Text Functions ... // // // START 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 ) { // // set anchor points' coordinates if they are not set ... ChangeFibonacciEmptyPoints(time1, price1, time2, price2); // // reset the error value ... ResetLastError(); // // Normalize Name ... string objName = drawPrefix + "_" + name; // // Create Fibonacci Retracement by the given coordinates ... if (!ObjectCreate(chartID, objName, OBJ_FIBO, subWindow, time1, price1, time2, price2)) { // string message = __FUNCTION__ + ": failed to create \"Fibonacci Retracement\"! Error code = " + (string)GetLastError(); // LogMessage(message); // return (false); } // // 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 (true); } // // 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 ) { // // set anchor points' coordinates if they are not set ... ChangeFibonacciEmptyPoints(time1, price1, time2, price2); // // reset the error value ... ResetLastError(); // // Normalize Name ... string objName = drawPrefix + "_" + name; // // Create Fibonacci Retracement by the given coordinates ... if (!ObjectCreate(chartID, name, OBJ_FIBO, subWindow, time1, price1, time2, price2)) { // string message = __FUNCTION__ + ": failed to create \"Fibonacci Retracement\"! Error code = " + (string)GetLastError(); // LogMessage(message); // return (false); } // // 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 ... bool 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 ) { // // check array sizes ... if ( levels != ArraySize(colors) || levels != ArraySize(styles) || levels != ArraySize(widths) || levels != ArraySize(widths)) { // string message = __FUNCTION__ + ": array length does not correspond to the number of levels, error!"; // LogMessage(message); // return (false); } // // set the number of levels ... ObjectSetInteger(chartID, name, OBJPROP_LEVELS, levels); // // set the properties of levels in the loop ... for (int i = 0; i < levels; i++) { // // level value ... ObjectSetDouble(chartID, name, OBJPROP_LEVELVALUE, i, values[i]); // // level color ... ObjectSetInteger(chartID, name, OBJPROP_LEVELCOLOR, i, colors[i]); // // level style ... ObjectSetInteger(chartID, name, OBJPROP_LEVELSTYLE, i, styles[i]); // // level width ... ObjectSetInteger(chartID, name, OBJPROP_LEVELWIDTH, i, widths[i]); // // level description ... // ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, DoubleToString(100 * values[i], 1)); ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, descriptions[i]); } // // successful execution ... return (true); } // // 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 ) { // // 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); } // // reset the error value ... ResetLastError(); // // move the anchor point ... if (!ObjectMove(chartID, name, pointIndex, time, price)) { // string message = __FUNCTION__ + ": failed to move the anchor point! Error code = " + (string)GetLastError(); // LogMessage(message); // return (false); } // // successful execution ... return (true); } // // Delete Fibonacci Retracement ... bool DeleteFibonachi( const long chartID = 0, // chart's ID const string name = "Fibonacci" // object name ) { // // reset the error value ... ResetLastError(); // // delete the object ... if (!ObjectDelete(chartID, name)) { // string message = __FUNCTION__ + ": failed to delete \"Fibonacci Retracement\"! Error code = " + (string)GetLastError(); // LogMessage(message); // return (false); } // // successful execution ... return (true); } // // 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); } } // // END Fibonacci Functions ... // // // START 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 ) { // if (!time) { time = TimeCurrent(); } // ResetLastError(); // if (!ObjectCreate(chartID, name, OBJ_EVENT, subWindow, time, 0)) { // string message = __FUNCTION__ + ": failed to create \"Event\" object! Error code = " + (string)GetLastError(); // LogMessage(message); // return (false); } // // set event text ObjectSetString(chartID, name, OBJPROP_TEXT, text); // // set color ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); // // set anchor point width if the object is highlighted ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); // // display in the foreground (false) or background (true) ObjectSetInteger(chartID, name, OBJPROP_BACK, back); // // enable (true) or disable (false) the mode of moving event by mouse ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection); ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); // // hide (true) or display (false) graphical object name in the object list ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); // // set the priority for receiving the event of a mouse click in the chart ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); // // successful execution return (true); } // // Change Event object text bool EventTextChange( const long chartID = 0, // chart's ID const string name = "Event", // event name const string text = "Content" // text ) { // // reset the error value ResetLastError(); // // change object text if (!ObjectSetString(chartID, name, OBJPROP_TEXT, text)) { // string message = __FUNCTION__ + ": failed to change the text! Error code = " + (string)GetLastError(); // LogMessage(message); // return (false); } // // successful execution return (true); } // // Move Event object bool EventMove( const long chartID = 0, // chart's ID const string name = "Event", // event name datetime time = 0 // time ) { // // if time is not set, move event to the last bar if (!time) { time = TimeCurrent(); } // // reset the error value ResetLastError(); // // move the object if (!ObjectMove(chartID, name, 0, time, 0)) { // string message = __FUNCTION__ + ": failed to move \"Event\" object! Error code = " + (string)GetLastError(); // LogMessage(message); // return (false); } // // successful execution return (true); } // // Delete Event object bool EventDelete( const long chartID = 0, // chart's ID const string name = "Event" // event name ) { // // reset the error value ResetLastError(); // // delete the object if (!ObjectDelete(chartID, name)) { // string message = __FUNCTION__ + ": failed to delete \"Event\" object! Error code = " + (string)GetLastError(); // LogMessage(message); // return (false); } // // successful execution return (true); } // // END Event Functions ... // // // END Regular Draws ... // // // START Chart Style Drawers ... // // // Apply Styles On Chart ... void ApplyChartStyle( int chartId = -1, // chart's ID ENUM_CHART_MODE mode = CHART_CANDLES, // chart's mode bool showBidLine = true, // show bid line bool showAskLine = true, // show ask line bool showGrid = false, // show grids on chart bool showVolumes = false, // show volumes bool showTradeLevels = true, // Displaying trade levels in the chart (levels of open positions, Stop Loss, Take Profit and pending orders) bool autoScroll = true, // chart autoscroll bool quickNavigation = true, // chart quick navigation state color foreGroundColor = clrWhite, // chart's foreground color color backGroundColor = clrBlack, // chart's background color color upColor = clrGreen, // Up Color color downColor = clrRed, // Down Color color bullishColor = clrGreen, // Bullish color color bearishColor = clrRed, // Bearish color color gridColor = clrGray, // grid color color bidLineColor = clrGray, // bid line color color askLineColor = clrRed, // ask line color color lineColor = clrLime, // line mode and doji candlestick color color stopColor = clrGold, // Color of stop order levels (Stop Loss and Take Profit) color volumesColor = clrGreen // volumes color ) { // // Validate Args ... if (chartId == -1) { chartId = 0; } // ChartSetInteger(chartId, CHART_MODE, mode); ChartSetInteger(chartId, CHART_SHOW_BID_LINE, showBidLine); ChartSetInteger(chartId, CHART_SHOW_ASK_LINE, showAskLine); ChartSetInteger(chartId, CHART_SHOW_GRID, showGrid); ChartSetInteger(chartId, CHART_SHOW_VOLUMES, showVolumes); ChartSetInteger(chartId, CHART_SHOW_TRADE_LEVELS, showTradeLevels); ChartSetInteger(chartId, CHART_AUTOSCROLL, autoScroll); ChartSetInteger(chartId, CHART_QUICK_NAVIGATION, quickNavigation); ChartSetInteger(chartId, CHART_COLOR_FOREGROUND, foreGroundColor); ChartSetInteger(chartId, CHART_COLOR_BACKGROUND, backGroundColor); ChartSetInteger(chartId, CHART_COLOR_CHART_UP, upColor); ChartSetInteger(chartId, CHART_COLOR_CHART_DOWN, downColor); ChartSetInteger(chartId, CHART_COLOR_CANDLE_BULL, bullishColor); ChartSetInteger(chartId, CHART_COLOR_CANDLE_BEAR, bearishColor); ChartSetInteger(chartId, CHART_COLOR_GRID, gridColor); ChartSetInteger(chartId, CHART_COLOR_BID, bidLineColor); ChartSetInteger(chartId, CHART_COLOR_ASK, askLineColor); ChartSetInteger(chartId, CHART_COLOR_STOP_LEVEL, stopColor); ChartSetInteger(chartId, CHART_COLOR_CHART_LINE, lineColor); ChartSetInteger(chartId, CHART_COLOR_VOLUME, volumesColor); } // // END Chart Style Drawers ... //