/////////////////////////////////////////////////////// // // SaherElm IT Center MQL4 Draw Global Library // --------------------------------------------- // saherelm useful tools and definitions ... // // // Maintainer: // ------------ // Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) // ////////////////////////////////////////////////////// #property library #property copyright "Copyright 2023, SaherElm IT Center" #property link "https://www.saherelm.ir" #property version "1.00" #property strict // // Includes our shared library ... #include "../Libraries/x-saherelm.log.lib.mq4" // // Draw Highest High ... bool DrawHighestHigh( const int bar_index, const int marketLen, const string tag, const int drawUntilBarIndex = 0, const long chartID = 0, const int subWindow = 0, const color clr = clrAqua, const ENUM_LINE_STYLE style = STYLE_DOT, const int width = 1, const bool back = false, const bool selection = false, const bool hidden = false, const long zOrder = 0 ) { // bool result = false; // // Calculate Highest High ... int hhIdx = iHighest( _Symbol, _Period, MODE_HIGH, marketLen, bar_index ); // datetime hhTime = iTime( _Symbol, _Period, hhIdx ); // datetime barTime = iTime( _Symbol, _Period, bar_index ); // datetime drawUntilTime = drawUntilBarIndex != bar_index ? iTime( _Symbol, _Period, drawUntilBarIndex ) : barTime ; // double hh = iHigh( _Symbol, _Period, hhIdx ); // int rnd = rand(); // // Define Label ... string lbl = StringConcatenate( tag, "_HH(", marketLen ,")_", hh, "_", rnd ); // result = ObjectDelete( chartID, lbl ); // // Draw a Trend Line ... result = DrawTrendLine( chartID, lbl, subWindow, hhTime, hh, drawUntilTime, hh, clr, style, width, back, selection, hidden, zOrder ); // return result; } // // Draw Lowest Low ... bool DrawLowestLow( const int bar_index, const int marketLen, const string tag, const int drawUntilBarIndex = 0, const long chartID = 0, const int subWindow = 0, const color clr = clrFuchsia, const ENUM_LINE_STYLE style = STYLE_DOT, const int width = 1, const bool back = false, const bool selection = false, const bool hidden = false, const long zOrder = 0 ) { // bool result = false; // // Calculate Highest High ... int llIdx = iLowest( _Symbol, _Period, MODE_LOW, marketLen, bar_index ); // datetime llTime = iTime( _Symbol, _Period, llIdx ); // datetime barTime = iTime( _Symbol, _Period, bar_index ); // datetime drawUntilTime = drawUntilBarIndex != bar_index ? iTime( _Symbol, _Period, drawUntilBarIndex ) : barTime ; // double ll = iLow( _Symbol, _Period, llIdx ); // int rnd = rand(); // // Define Label ... string lbl = StringConcatenate( tag, "_LL(", marketLen ,")_", ll, "_", rnd ); // result = ObjectDelete( chartID, lbl ); // // Draw a Trend Line ... result = DrawTrendLine( chartID, lbl, subWindow, llTime, ll, drawUntilTime, ll, clr, style, width, back, selection, hidden, zOrder ); // return result; } // // Draw Market Middle ... bool DrawMarketMiddle( const int bar_index, const int marketLen, const string tag, const int drawUntilBarIndex = 0, const long chartID = 0, const int subWindow = 0, const color clr = clrYellow, const ENUM_LINE_STYLE style = STYLE_DOT, const int width = 1, const bool back = false, const bool selection = false, const bool hidden = false, const long zOrder = 0 ) { // bool result = false; // // Calculate Highest High ... int llIdx = iLowest( _Symbol, _Period, MODE_LOW, marketLen, bar_index ); // datetime llTime = iTime( _Symbol, _Period, llIdx ); // double ll = iLow( _Symbol, _Period, llIdx ); // // Calculate Highest High ... int hhIdx = iHighest( _Symbol, _Period, MODE_HIGH, marketLen, bar_index ); // datetime hhTime = iTime( _Symbol, _Period, hhIdx ); // double hh = iHigh( _Symbol, _Period, hhIdx ); // double middle = ll + ((hh - ll) / 2); datetime middleTime = hhIdx < llIdx ? hhTime : llTime ; // datetime barTime = iTime( _Symbol, _Period, bar_index ); // datetime drawUntilTime = drawUntilBarIndex != bar_index ? iTime( _Symbol, _Period, drawUntilBarIndex ) : barTime ; // int rnd = rand(); // // Define Label ... string lbl = StringConcatenate( tag, "_MID(", marketLen ,")_", middle, "_", rnd ); // result = ObjectDelete( chartID, lbl ); // // Draw a Trend Line ... result = DrawTrendLine( chartID, lbl, subWindow, middleTime, middle, drawUntilTime, middle, clr, style, width, back, selection, hidden, zOrder ); // return result; } // // 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 = OBJ_ARROW_UP, // 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(); // // create an arrow ... if(!ObjectCreate(chartID, name, OBJ_ARROW, subWindow, time, price)) { // string message = StringConcatenate(__FUNCTION__, ": failed to create an arrow! Error code = ", GetLastError() ); // LogMessage(message); // return(false); } // // set the arrow code ... ObjectSetInteger(chartID, name, OBJPROP_ARROWCODE, arrowCode); // // set anchor type ... ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor); // // set the arrow color ... ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); // // set the border line style ... ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); // // set the arrow's size ... 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 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,name, OBJPROP_SELECTABLE, true); 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); } // // 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 = StringConcatenate( __FUNCTION__, ": failed to move the anchor point! Error code = ",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 = StringConcatenate( __FUNCTION__, ": failed to delete an arrow! Error code = ",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 = StringConcatenate( __FUNCTION__, ": failed to change the arrow code! Error code = ",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 = StringConcatenate( __FUNCTION__, ": failed to change anchor type! Error code = ",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(); // // create a horizontal line ... if(!ObjectCreate(chartID, name, OBJ_HLINE, subWindow, 0, price)) { // string message = StringConcatenate( __FUNCTION__, ": failed to create a horizontal line! Error code = ",GetLastError() ); // LogMessage(message); // return(false); } // // set line color ... ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); // // set line display style ... ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); // // set line width ... 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 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, 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); } // // 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 = StringConcatenate( __FUNCTION__, ": failed to move the horizontal line! Error code = ",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 = StringConcatenate( __FUNCTION__, ": failed to delete a horizontal line! Error code = ",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(); // // create a vertical line ... if (!ObjectCreate(chartID, name, OBJ_VLINE, sub_window, time, 0)) { // string message = StringConcatenate( __FUNCTION__, ": failed to create a vertical line! Error code = ", GetLastError() ); // LogMessage(message); // return false; } // // set line color ... ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); // // set line display style ... ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); // // set line width ... 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 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, name, OBJPROP_SELECTABLE, true); 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; } // // 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 = StringConcatenate( __FUNCTION__, ": failed to move the vertical line! Error code = ", 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 = StringConcatenate( __FUNCTION__, ": failed to delete the vertical line! Error code = ", 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 = C'236,233,216', // 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(); // //--- create a rectangle label if(!ObjectCreate(chartID, name, OBJ_RECTANGLE_LABEL, subWindow, 0, 0)) { // string message = StringConcatenate( __FUNCTION__, ": failed to create a rectangle label! Error code = ",GetLastError() ); // LogMessage(message); // return(false); } // // set label coordinates ... ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x); ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y); // // set label size ... ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width); ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height); // // set background color ... ObjectSetInteger(chartID, name, OBJPROP_BGCOLOR, back_clr); // // set border type ... ObjectSetInteger(chartID, name, OBJPROP_BORDER_TYPE, border); // // set the chart's corner, relative to which point coordinates are defined ... ObjectSetInteger(chartID, name, OBJPROP_CORNER, corner); // // set flat border color (in Flat mode) ... ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); // // set flat border line style ... ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); // // set flat border width ... ObjectSetInteger(chartID, name, OBJPROP_WIDTH, lineWidth); // // display in the foreground (false) or background (true) ... ObjectSetInteger(chartID, name, OBJPROP_BACK, back); // // enable (true) or disable (false) the mode of moving the label 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); } // // 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 = StringConcatenate( __FUNCTION__, ": failed to move X coordinate of the label! Error code = ",GetLastError() ); // LogMessage(message); // return(false); } // if(!ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y)) { // string message = StringConcatenate( __FUNCTION__, ": failed to move Y coordinate of the label! Error code = ",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 = StringConcatenate( __FUNCTION__, ": failed to delete a rectangle label! Error code = ",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 = StringConcatenate( __FUNCTION__, ": failed to change the label's width! Error code = ",GetLastError() ); // LogMessage(message); // return(false); } // if(!ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height)) { // string message = StringConcatenate( __FUNCTION__, ": failed to change the label's height! Error code = ",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 = StringConcatenate( __FUNCTION__, ": failed to change the border type! Error code = ",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(); // // create a trend line by the given coordinates ... if(!ObjectCreate(chartID, name, OBJ_TREND, subWindow, time1, price1, time2, price2)) { // string message = StringConcatenate( __FUNCTION__, ": failed to create a trend line! Error code = ", GetLastError() ); // LogMessage(message); // return(false); } // // set line color ... ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); // // set line display style ... ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); // // set line width ... 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 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, name, OBJPROP_SELECTABLE, true); ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); // // enable (true) or disable (false) the mode of continuation of the line's display to the right ... ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); // // 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); } // // 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 = StringConcatenate( __FUNCTION__, ": failed to move the anchor point! Error code = ", 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 = StringConcatenate( __FUNCTION__, ": failed to delete a trend line! Error code = ", 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(); // //--- create Text object if(!ObjectCreate(chartID, name, OBJ_TEXT, subWindow, time, price)) { // string message = StringConcatenate( __FUNCTION__, ": failed to create \"Text\" object! Error code = ", GetLastError() ); // LogMessage(message); // return(false); } // // set the text ... ObjectSetString(chartID, name , OBJPROP_TEXT, text); // // set text font ... ObjectSetString(chartID, name, OBJPROP_FONT, font); // // set font size ... ObjectSetInteger(chartID, name, OBJPROP_FONTSIZE, fontSize); // // set the slope angle of the text ... ObjectSetDouble(chartID, name, OBJPROP_ANGLE, angle); // // set anchor type ... ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor); // // set color ... ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); // // display in the foreground (false) or background (true) ... ObjectSetInteger(chartID, name, OBJPROP_BACK, back); // // enable (true) or disable (false) the mode of moving the object by mouse ... ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); 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); } // // 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 = StringConcatenate( __FUNCTION__, ": failed to move the anchor point! Error code = ", 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 = StringConcatenate( __FUNCTION__, ": failed to change the text! Error code = ", 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 = StringConcatenate( __FUNCTION__, ": failed to delete \"Text\" object! Error code = ", 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(); // // Create Fibonacci Retracement by the given coordinates ... if (!ObjectCreate(chartID, name, OBJ_FIBO, subWindow, time1, price1, time2, price2)) { // string message = StringConcatenate( __FUNCTION__, ": failed to create \"Fibonacci Retracement\"! Error code = " , GetLastError() ); // LogMessage(message); // return(false); } // // set color ... ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); // // set line style ... ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); // // set line width ... 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 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, name, OBJPROP_SELECTABLE, true); ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); // // enable (true) or disable (false) the mode of continuation of the object's display to the right ... ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); // // 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); } // // 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(); // // Create Fibonacci Retracement by the given coordinates ... if (!ObjectCreate(chartID, name, OBJ_FIBO, subWindow, time1, price1, time2, price2)) { // string message = StringConcatenate( __FUNCTION__, ": failed to create \"Fibonacci Retracement\"! Error code = " , GetLastError() ); // LogMessage(message); // return(false); } // // set color ... ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); // // set line style ... ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); // // set line width ... 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 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, name, OBJPROP_SELECTABLE, true); ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); // // enable (true) or disable (false) the mode of continuation of the object's display to the right ... ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); // // 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); // // Change Levels Of Fibonacci ... bool result = FibonacciLevelsSet( levels, values, colors, styles, widths, descriptions, chartID, name ); // // 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 = StringConcatenate( __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 = StringConcatenate( __FUNCTION__, ": failed to move the anchor point! Error code = ", 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 = StringConcatenate( __FUNCTION__, ": failed to delete \"Fibonacci Retracement\"! Error code = ", 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 General Functions ... // // // Remove all Drawn Objects ... void RemoveDraws(const string &tag) { // for(int iObj=ObjectsTotal()-1; iObj >= 0; iObj--) { // string on = ObjectName(iObj); if (StringFind(on, tag) == 0) { ObjectDelete(on); } } } // // End General Functions ... //