Author: Copyright © 2021, Vladimir Karputov
0 Views
0 Downloads
0 Favorites
Extend Box
ÿþ//+------------------------------------------------------------------+

//|                                                   Extend Box.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 indicator_chart_window

#property indicator_buffers 0

#property indicator_plots   0

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

//| Enum Rectangles                                                  |

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

enum ENUM_RECTANGLES

  {

   any=0,      // Any rectangle

   prefix=1,   // A rectangle starting with prefix ...

  };

//--- input parameters

input ENUM_RECTANGLES   InpRectangleType        = any;            // Rectangle type:

input string            InpPrefixRectangleType  = "extend_box_";  // Prefix (only for 'A rectangle starting with prefix...'):

input bool              InpStretch              = false;          // Stretch to Maximum and Minimum

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

//---

   return(INIT_SUCCEEDED);

  }

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

//| Custom indicator iteration function                              |

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

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])

  {

   ArraySetAsSeries(time,true);

   ArraySetAsSeries(high,true);

   ArraySetAsSeries(low,true);

//---

   long chart_id=ChartID();

   int total=ObjectsTotal(chart_id,0,OBJ_RECTANGLE);

   for(int i=total-1; i>=0; i--)

     {

      string name=ObjectName(chart_id,i,0,OBJ_RECTANGLE);

      if((InpRectangleType==any) || (InpRectangleType==prefix && StringFind(name,InpPrefixRectangleType,0)>=0))

        {

         long rec_time_0=ObjectGetInteger(chart_id,name,OBJPROP_TIME,0);

         long rec_time_1=ObjectGetInteger(chart_id,name,OBJPROP_TIME,1);

         double rec_price_0=ObjectGetDouble(chart_id,name,OBJPROP_PRICE,0);

         double rec_price_1=ObjectGetDouble(chart_id,name,OBJPROP_PRICE,1);

         long time_left,time_right;

         double price_min,price_max;

         //--- check time

         if(rec_time_0<rec_time_1)

           {

            time_left=rec_time_0;

            time_right=rec_time_1;

           }

         else

           {

            //---

            ObjectSetInteger(chart_id,name,OBJPROP_TIME,0,rec_time_1);

            ObjectSetInteger(chart_id,name,OBJPROP_TIME,1,rec_time_0);

            time_left=rec_time_1;

            time_right=rec_time_0;

           }

         //--- check price

         if(rec_price_0<rec_price_1)

           {

            price_min=rec_price_0;

            price_max=rec_price_1;

           }

         else

           {

            ObjectSetDouble(chart_id,name,OBJPROP_PRICE,0,rec_price_1);

            ObjectSetDouble(chart_id,name,OBJPROP_PRICE,1,rec_price_0);

            price_min=rec_price_1;

            price_max=rec_price_0;

           }

         if(!InpStretch)

           {

            ObjectSetInteger(chart_id,name,OBJPROP_TIME,1,time[0]);

           }

         else

           {

            ObjectSetInteger(chart_id,name,OBJPROP_TIME,1,time[0]);

            double highest=DBL_MIN,lowest=DBL_MAX;

            for(int j=0; j<rates_total; j++)

              {

               if(time[j]<time_left)

                  break;

               if(high[j]>highest)

                  highest=high[j];

               if(low[j]<lowest)

                  lowest=low[j];

              }

            ObjectSetDouble(chart_id,name,OBJPROP_PRICE,0,lowest);

            ObjectSetDouble(chart_id,name,OBJPROP_PRICE,1,highest);

           }

        }

     }

//--- return value of prev_calculated for next call

   return(rates_total);

  }

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

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---