Rectangle from to

Author: Copyright © 2021, Vladimir Karputov
Miscellaneous
It issuies visual alerts to the screen
0 Views
0 Downloads
0 Favorites
Rectangle from to
ÿþ//+------------------------------------------------------------------+

//|                                            Rectangle from to.mq5 |

//|                              Copyright © 2021, Vladimir Karputov |

//|                      https://www.mql5.com/en/users/barabashkakvn |

//+------------------------------------------------------------------+

#property copyright "Copyright © 2021, Vladimir Karputov"

#property link      "https://www.mql5.com/en/users/barabashkakvn"

#property version   "1.000"

#property script_show_inputs

//--- input parameters

input datetime    InpLeftTime    = D'2021.10.18 10:10';  // Left time

input datetime    InpRightTime   = D'2021.10.21 10:10';  // Right time

input color       InpColor       = clrSpringGreen;       // Sunday color

input string      InpPrefix      = "RFT_";               // Prefix

//+------------------------------------------------------------------+

//| Script program start function                                    |

//+------------------------------------------------------------------+

void OnStart()

  {

//---

   MqlRates rates[];

   ArraySetAsSeries(rates,true);

   int res=CopyRates(Symbol(),Period(),InpLeftTime,InpRightTime,rates);

   if(res<2)

     {

      Alert("result ",res,", last error: ",GetLastError());

      return;

     }

   double price_max=DBL_MIN,price_min=DBL_MAX;

   for(int i=0; i<res; i++)

     {

      if(rates[i].high>price_max)

         price_max=rates[i].high;

      if(rates[i].low<price_min)

         price_min=rates[i].low;

     }

   string name=TimeToString(InpLeftTime,TIME_DATE|TIME_MINUTES)+"-"+TimeToString(InpRightTime,TIME_DATE|TIME_SECONDS);

   if(!RectangleCreate(ChartID(),InpPrefix+name,0,InpLeftTime,price_max,InpRightTime,price_min,InpColor,name))

      Alert("RectangleCreate error");

  }

//+------------------------------------------------------------------+

//| Create rectangle by the given coordinates                        |

//+------------------------------------------------------------------+

bool RectangleCreate(const long            chart_ID=0,        // chart's ID

                     const string          name="Rectangle",  // rectangle name

                     const int             sub_window=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,        // rectangle color

                     const string          text="Rectangle",  // rectangle text

                     const ENUM_LINE_STYLE style=STYLE_DASH,  // style of rectangle lines

                     const int             width=2,           // 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=false,      // hidden in the object list

                     const long            z_order=0)         // priority for mouse click

  {

//--- reset the error value

   ResetLastError();

//--- create a rectangle by the given coordinates

   if(!ObjectCreate(chart_ID,name,OBJ_RECTANGLE,sub_window,time1,price1,time2,price2))

     {

      Print(__FUNCTION__,

            ": failed to create a rectangle! Error code = ",GetLastError());

      return(false);

     }

//--- set rectangle color

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);

//---

   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);

//--- set the style of rectangle lines

   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);

//--- set width of the rectangle lines

   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);

//--- enable (true) or disable (false) the mode of filling the rectangle

   ObjectSetInteger(chart_ID,name,OBJPROP_FILL,fill);

//--- display in the foreground (false) or background (true)

   ObjectSetInteger(chart_ID,name,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(chart_ID,name,OBJPROP_SELECTABLE,selection);

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);

//--- hide (true) or display (false) graphical object name in the object list

   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);

//--- set the priority for receiving the event of a mouse click in the chart

   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);

//--- successful execution

   return(true);

  }

//+------------------------------------------------------------------+

Comments