My Color Levels.x

Author: Copyright 2017, Tor & omutmoren
Miscellaneous
It plays sound alerts
0 Views
0 Downloads
0 Favorites
My Color Levels.x
ÿþ//+------------------------------------------------------------------+

//|                                              My Color Levels.mq4 |

//|                                              Copyright 2017, Tor |

//|                                             http://einvestor.ru/ |

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

#property copyright "Copyright 2017, Tor & omutmoren"

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

#property version   "1.00"

#property strict

#property indicator_chart_window



ENUM_BASE_CORNER  InpCorner=CORNER_LEFT_UPPER;   // Snapping angle for panel

extern string           NameL1 = "TIU";   // Level 1 name (with alerts)

extern string           NameL2 = "RUZ";   // Level 2 name

extern string           NameL3 = "URST";  // Level 3 name

extern color             clrTIU      = clrGray;              //Level 1 color

extern color             clrRUZ      = clrGreen;             //Level 2 color

extern color             clrURST     = clrGold;              //Level 3 color

extern bool              Alerts      = true;                 //Alert signal

extern bool              Flash       = true;                 //Flash alerts

extern bool              LongTIU     = true;                 //Extend rectangles Level 1 (false = no)

extern color             clrUpper    = clrRed;               //Rectangle color above price

extern color             clrLower    = clrGreen;             //Rectangle color below price

extern color             clrDefaultBG= clrWhite;             //Default background color

extern color             clrAlertBG  = clrYellow;            //Alarm background color

extern string            soundFile   ="alert.wav";           //Beep file

extern int               soundMax    =1;                     //The number of repetitions of the signal

extern bool              Magnit      = true;                 //Magnetic level to the body of the candle

extern bool              TextWrite   = true;                 //Sign levels



extern string t2="Other settings";

extern color   panl_0_cl   =  clrGainsboro;        // Panel color

extern bool    panl_0_st   =  true;                // Display panel?

                                                   // 

extern int x_coor = 10;    // X axis shift

extern int y_coor = 20;    // Y axis shift

                           // 

bool              InpSelection      =  false;               // Highlight to move

bool              InpHidden         =  true;                // Hide in the list of objects

bool              InpHidden_OBJ     =  false;               // Hide in the list of objects

bool              InpBackRect       =  false;               // Object in the background



int x_size=202; int y_size=40; int x_step=5; int y_panl=20; int x_rect=60; int y_rect=20; int y_line=6;

int lastAlert=0; static double lastBid=Bid; string secret="8wJgN";



string obj_name[8]={"name_1","name_2","name_3","name_4"};

long clrCandle=ChartGetInteger(0,CHART_COLOR_CANDLE_BEAR,0);

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   MathSrand(GetTickCount());

   ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,true);

   ChartSetInteger(0,CHART_EVENT_OBJECT_DELETE,true);

   CheckObjects();

   long lastBGcolor=ChartGetInteger(0,CHART_COLOR_BACKGROUND,0);

   if(lastBGcolor!=clrDefaultBG){ ChartSetInteger(0,CHART_COLOR_BACKGROUND,clrDefaultBG); }



//---

   return(INIT_SUCCEEDED);

  }

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

//|                                                                  |

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

void OnDeinit(const int reason)

  {

   Comment("");

   if(_UninitReason==REASON_REMOVE)

     {

      RectLabelDelete(0,obj_name[0]);

      RectLabelDelete(0,obj_name[1]);

      RectLabelDelete(0,obj_name[2]);

      RectLabelDelete(0,obj_name[3]);

      del(secret,-1);

     }

  }

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

//| 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[])

  {

//---



   CreatePanel();

   CreateRect();



   if(Alerts || Flash)

     {

      WaitCrossing();

     }

   RecolorThisLevel();



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

   return(rates_total);

  }

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

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

//| ChartEvent function                                              |

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

void OnChartEvent(const int id,

                  const long &lparam,

                  const double &dparam,

                  const string &sparam)

  {

   datetime dt_1     = 0;

   double   price_1  = 0;

   datetime dt_2     = 0;

   double   price_2  = 0;

   int      window   = 0;

   int      x        = 0;

   int      y        = 0;



// Clicking on Level 1 Rectangle

   if(id==CHARTEVENT_OBJECT_CLICK)

     {

      string clickedChartObject=sparam;

      if(clickedChartObject==obj_name[1])

        {

         string name=secret+"name_TIU_"+IntegerToString(MathRand()+10000);



         y=y_coor+3*y_rect+4*x_step;

         ChartXYToTimePrice(0,x_coor+x_step,y,window,dt_1,price_1);



         y=y_coor+4*y_rect+5*x_step;

         ChartXYToTimePrice(0,x_coor+x_size,y,window,dt_2,price_2);



         RectangleCreate(0,name,0,dt_1,price_1,dt_2,price_2,clrTIU,STYLE_SOLID,0,true,false,true,InpHidden_OBJ,0,StringConcatenate(NameL1," ",ReturnTF(_Period)));

         if(LongTIU){ LongThisLevel("name_TIU_"); }

         RecolorThisLevel("name_TIU_");

        }

     }

// Clicking on Level 2 Rectangle

   if(id==CHARTEVENT_OBJECT_CLICK)

     {

      string clickedChartObject=sparam;

      if(clickedChartObject==obj_name[2])

        {

         string name=secret+"name_RUZ_"+IntegerToString(MathRand()+10000);



         y=y_coor+4*y_rect+5*x_step;

         ChartXYToTimePrice(0,x_coor+x_step,y,window,dt_1,price_1);



         y=y_coor+5*y_rect+6*x_step;

         ChartXYToTimePrice(0,x_coor+x_size,y,window,dt_2,price_2);



         RectangleCreate(0,name,0,dt_1,price_1,dt_2,price_2,clrRUZ,STYLE_SOLID,0,true,false,true,InpHidden_OBJ,0,StringConcatenate(NameL2," ",ReturnTF(_Period)));

        }

     }

// Clicking on Level 3 Rectangle

   if(id==CHARTEVENT_OBJECT_CLICK)

     {

      string clickedChartObject=sparam;

      if(clickedChartObject==obj_name[3])

        {

         string name=secret+"name_URST_"+IntegerToString(MathRand()+10000);



         y=y_coor+5*y_rect+6*x_step;

         ChartXYToTimePrice(0,x_coor+x_step,y,window,dt_1,price_1);



         y=y_coor+6*y_rect+7*x_step;

         ChartXYToTimePrice(0,x_coor+x_size,y,window,dt_2,price_2);



         RectangleCreate(0,name,0,dt_1,price_1,dt_2,price_2,clrURST,STYLE_SOLID,0,true,false,true,InpHidden_OBJ,0,StringConcatenate(NameL3," ",ReturnTF(_Period)));

        }

     }

// Moving rectangles or clicking on the chart window

   if(id==CHARTEVENT_MOUSE_MOVE && sparam=="1")

     {

      long lastBGcolor=ChartGetInteger(0,CHART_COLOR_BACKGROUND,0);

      if(lastBGcolor!=clrDefaultBG){ ChartSetInteger(0,CHART_COLOR_BACKGROUND,clrDefaultBG); }

      lastAlert=0;

      lastBid=Bid;

      RecolorThisLevel("name_TIU_");

     }

// Verify deletion of objects

   if(id==CHARTEVENT_OBJECT_DELETE)

     {// check and remove unnecessary

      CheckObjects();

     }

   if(Magnit){ Magnite("name_TIU_"); }

   if(LongTIU){ LongThisLevel("name_TIU_"); }



  }

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

void CreatePanel()

  {

// Toolbar



   if(panl_0_st)

     {



      int x_pn=x_coor,y_pn=y_coor;

      if(InpCorner == 1)  x_pn = x_coor + x_size + x_step;

      if(InpCorner == 2)  y_pn = y_coor + y_rect + x_step;

      if(InpCorner==3) {x_pn=x_coor+x_size+x_step; y_pn=y_coor+y_rect+x_step;}



      if(!RectLabelCreate(0,obj_name[0],0,x_pn,y_pn,x_size,y_size,panl_0_cl,BORDER_SUNKEN,InpCorner,

         clrBlack,STYLE_SOLID,2,true,InpSelection,true,0))

        {

         return;

        }

        } else {

      panl_0_cl=ChartBackColorGet(0);

     }

  }

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

void CreateRect()

  {

// Level 1 rectangle

   int x_pn=x_coor+x_step,y_pn=y_coor+x_step;

   if(InpCorner == 1)  x_pn = x_coor + x_size - 2*x_step - 2*x_rect;

   if(InpCorner == 2)  y_pn = y_coor + y_rect;

   if(InpCorner==3) {x_pn=x_coor+x_size-2*x_step-2*x_rect; y_pn=y_coor+y_rect;}



   if(!RectLabelCreate(0,obj_name[1],0,x_pn,y_pn,x_rect,y_rect,clrTIU,BORDER_FLAT,InpCorner,

      clrTIU,STYLE_SOLID,0,InpBackRect,InpSelection,InpHidden,0))

     {

      return;

     }



// Level 2 rectangle

   x_pn=x_coor+x_rect+2*x_step; y_pn=y_coor+x_step;

   if(InpCorner == 1)  x_pn = x_coor + x_size - 3*x_step - 3*x_rect;

   if(InpCorner == 2)  y_pn = y_coor + y_rect;

   if(InpCorner==3) {x_pn=x_coor+x_size-3*x_step-3*x_rect; y_pn=y_coor+y_rect;}



   if(!RectLabelCreate(0,obj_name[2],0,x_pn,y_pn,x_rect,y_rect,clrRUZ,BORDER_FLAT,InpCorner,

      clrRUZ,STYLE_SOLID,0,InpBackRect,InpSelection,InpHidden,0))

     {

      return;

     }



// Level 3 rectangle

   x_pn=x_coor+2*x_rect+3*x_step; y_pn=y_coor+x_step;

   if(InpCorner == 1)  x_pn = x_coor + x_size - 4*x_step - 4*x_rect;

   if(InpCorner == 2)  y_pn = y_coor + y_rect;

   if(InpCorner==3) {x_pn=x_coor+x_size-4*x_step-4*x_rect; y_pn=y_coor+y_rect;}



   if(!RectLabelCreate(0,obj_name[3],0,x_pn,y_pn,x_rect,y_rect,clrURST,BORDER_FLAT,InpCorner,

      clrURST,STYLE_SOLID,0,InpBackRect,InpSelection,InpHidden,0))

     {

      return;

     }



   x_pn=x_coor+x_step+(int)(MathCeil(x_rect/2)) -(StringLen(NameL1)*8/2); y_pn=y_coor+(int)(MathCeil(x_step/2))+y_panl;

   if(!TextLabelCreate(secret+"labelTIU",x_pn,y_pn,InpCorner,NameL1,10,clrBlack,InpBackRect,InpHidden,InpSelection))

     {

      return;//clrTIU

     }



   x_pn=x_coor+x_rect+2*x_step+(int)(MathCeil(x_rect/2)) -(StringLen(NameL2)*8/2); y_pn=y_coor+(int)(MathCeil(x_step/2))+y_panl;

   if(!TextLabelCreate(secret+"labelRUZ",x_pn,y_pn,InpCorner,NameL2,10,clrBlack,InpBackRect,InpHidden,InpSelection))

     {

      return;//clrRUZ

     }



   x_pn=x_coor+2*x_rect+3*x_step+(int)(MathCeil(x_rect/2)) -(StringLen(NameL3)*8/2); y_pn=y_coor+(int)(MathCeil(x_step/2))+y_panl;

   if(!TextLabelCreate(secret+"labelURST",x_pn,y_pn,InpCorner,NameL3,10,clrBlack,InpBackRect,InpHidden,InpSelection))

     {

      return;//clrURST

     }

//InpBackRect,InpHidden,InpSelection

  }

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

//| Creates a rectangular label                                      |

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

bool RectLabelCreate(const long             chart_ID=0,               // 

                     const string           name="RectLabel",         //

                     const int              sub_window=0,             // 

                     const int              x=0,                      // 

                     const int              y=0,                      //

                     const int              width=50,                 // 

                     const int              height=18,                // 

                     const color            back_clr=C'236,233,216',  // 

                     const ENUM_BORDER_TYPE border=BORDER_SUNKEN,     // 

                     const ENUM_BASE_CORNER corner=CORNER_LEFT_UPPER, // 

                     const color            clr=clrRed,               // 

                     const ENUM_LINE_STYLE  style=STYLE_SOLID,        // 

                     const int              line_width=1,             // 

                     const bool             back=false,               // 

                     const bool             selection=false,          // 

                     const bool             hidden=true,              // 

                     const long             z_order=0)                // 

  {

//--- 

   ResetLastError();

//--- 

   if(ObjectFind(name)==-1)

      ObjectCreate(chart_ID,name,OBJ_RECTANGLE_LABEL,sub_window,0,0);



   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);              // 

   ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);

   ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width);              // 

   ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height);

   ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr);         // 

   ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_TYPE,border);       // 

   ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);            //

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);                // 

   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);              // 

   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,line_width);         // 

   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);                // 

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);     // 

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);

   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);            // 

   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);           // 



   return(true);

  }

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

//| Removes a rectangular label.                                     |

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

bool RectLabelDelete(const long   chart_ID=0,       // 

                     const string name="RectLabel") // 

  {

//--- 

   ResetLastError();

//--- 

   if(ObjectFind(chart_ID,name)>=0)

      ObjectDelete(chart_ID,name);

//--- 

   return(true);

  }

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

//| The function gets the background color of the chart.                              |

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

color ChartBackColorGet(const long chart_ID=0)

  {

//--- 

   long result=clrNONE;

//--- 

   ResetLastError();

//--- 

   if(!ChartGetInteger(chart_ID,CHART_COLOR_BACKGROUND,0,result))

     {

      //--- 

      Print(__FUNCTION__+", Error Code = ",GetLastError());

     }

//--- 

   return((color)result);

  }

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

//| Creates a rectangle by the given coordinates                     |

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

bool RectangleCreate(const long            chart_ID=0,        // 

                     const string          name="Rectangle",  // 

                     const int             sub_window=0,      // 

                     datetime              time1=0,           // 

                     double                price1=0,          // 

                     datetime              time2=0,           // 

                     double                price2=0,          // 

                     const color           clr=clrRed,        // 

                     const ENUM_LINE_STYLE style=STYLE_SOLID, // 

                     const int             width=1,           // 

                     const bool            fill=false,        // 

                     const bool            back=false,        // 

                     const bool            selection=true,    // 

                     const bool            hidden=true,       // 

                     const long            z_order=0,         // 

                     const string          tooltip="Level")

  {

//--- 

   ResetLastError();

//--- 

   if(ObjectFind(name)==-1)

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



   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);             //--- 

   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);           //--- 

   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);           //--- 

   ObjectSetInteger(chart_ID,name,OBJPROP_FILL,fill);             //--- 

   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);             //--- 

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);  //--- 

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);    //--- 

   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);         //--- 

   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);        //--- 

   ObjectSetString(chart_ID,name,OBJPROP_TOOLTIP,tooltip);

   ObjectSetString(chart_ID,name,OBJPROP_LEVELTEXT,tooltip);

   ObjectSetString(chart_ID,name,OBJPROP_TEXT,tooltip);

   return(true);

  }

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

//| Removes a rectangle                                              |

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

bool RectangleDelete(const long   chart_ID=0,       // 

                     const string name="Rectangle") // 

  {

//--- 

   ResetLastError();

//--- 

   if(ObjectFind(chart_ID,name)>=0)

      ObjectDelete(chart_ID,name);



   return(true);

  }

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

//|                                                                  |

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

bool TextLabelCreate(const string        name="Label",// 

                     const int               x=0,                      // 

                     const int               y=0,                      // 

                     const ENUM_BASE_CORNER  corner=CORNER_LEFT_UPPER, // 

                     const string            text="Label",             //  

                     const int               font_size=10,             // 

                     const color             clr=clrRed,               // 

                     const bool              back=false,               // 

                     const bool              hidden=true,              //  

                     const bool              selection=false)          //  

  {

   long              chart_ID=0;               //  

   int               sub_window=0;             // 

   string            font="Arial";             //  

   double            angle=0.0;                // 

   ENUM_ANCHOR_POINT anchor=ANCHOR_LEFT_UPPER; //  

   long              z_order=0;                // 

   ResetLastError();



   if(ObjectFind(name)==-1)

      ObjectCreate(chart_ID,name,OBJ_LABEL,sub_window,0,0);



   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x); //---  

   ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);

   ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner); //--- 

   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text); //--- 

   ObjectSetString(chart_ID,name,OBJPROP_FONT,font); //--- 

   ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size); //---  

   ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle); //--- 

   ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor); //---  

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); //--- 

   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); //--- 

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); //--- 

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);

   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); //---  

   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); //--- 

   return(true);

  }

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

//|                                                                  |

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

void LongThisLevel(string prefix="all")

  {

// we extend once when moving levels, resize them

   for(int n=ObjectsTotal()-1; n>=0; n--)

     {

      string Obj_Name=ObjectName(n);

      if(ObjectGetInteger(0,Obj_Name,OBJPROP_TYPE)==OBJ_RECTANGLE && ((StringFind(Obj_Name,prefix,0)!=-1 && prefix!="all") || (prefix=="all" && StringFind(Obj_Name,"name_TIU_",0)!=-1)))

        { // the desired level, we obtain and check the properties

         double price1 = ObjectGetDouble(0,Obj_Name,OBJPROP_PRICE1);

         double price2 = ObjectGetDouble(0,Obj_Name,OBJPROP_PRICE2);

         long dt1 = ObjectGetInteger(0,Obj_Name,OBJPROP_TIME1);

         long dt2 = ObjectGetInteger(0,Obj_Name,OBJPROP_TIME2);

         long clrRec3=ObjectGetInteger(0,Obj_Name,OBJPROP_COLOR);

         // 

         string ids[]; bool have=false;

         int k=StringSplit(Obj_Name,StringGetCharacter("_",0),ids);

         if(k>2)

           {

            if(StringLen(ids[2])==5)

              { // 

               // 

               long newclr=clrRec3;

               if(Bid<price2 && Bid<price1)

                 {

                  newclr=clrUpper;

                 }

               if(Bid>price2 && Bid>price1)

                 {

                  newclr=clrLower;

                 }

               for(int xx=ObjectsTotal()-1; xx>=0; xx--)

                 {

                  string where=ObjectName(xx);

                  if(StringLen(where)>StringLen(Obj_Name) && StringSubstr(where,0,StringLen(Obj_Name)+1)==(Obj_Name+"-"))

                    {// && where!=Obj_Name

                     //Print(StringSubstr(where,0,StringLen(Obj_Name)+1));

                     have=true;

                     long dt4=ObjectGetInteger(0,where,OBJPROP_TIME2);

                     long clrRec2=ObjectGetInteger(0,where,OBJPROP_COLOR);

                     if(dt1<dt2)

                       {

                        ObjectMove(0,where,0,dt2,price1);

                          }else{

                        ObjectMove(0,where,0,dt1,price1);

                       }

                     ObjectMove(0,where,1,dt4,price2);

                     if(newclr!=clrRec2){ ObjectSetInteger(0,where,OBJPROP_COLOR,newclr); }

                     break;

                    }

                 }

               if(newclr!=clrRec3){ ObjectSetInteger(0,Obj_Name,OBJPROP_COLOR,newclr); }

               if(!have)

                 {

                  long dt3=dt1+60*60*10*24*365;

                  string Obj_Name2=Obj_Name+"-"+IntegerToString(MathRand()+10000);

                  RectangleCreate(0,Obj_Name2,0,dt2,price1,dt3,price2,clrTIU,STYLE_SOLID,0,true,false,false,InpHidden_OBJ,0,NameL1);

                 }

              }

           }

        }

     }

   return;

  }

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

//|                                                                  |

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

void RecolorThisLevel(string prefix="all")

  {

// repaint

   for(int n=ObjectsTotal()-1; n>=0; n--)

     {

      string Obj_Name=ObjectName(n);

      if(ObjectGetInteger(0,Obj_Name,OBJPROP_TYPE)==OBJ_RECTANGLE && ((StringFind(Obj_Name,prefix,0)!=-1 && prefix!="all") || (prefix=="all" && StringFind(Obj_Name,"name_TIU_",0)!=-1)))

        { // 

         double price1 = ObjectGetDouble(0,Obj_Name,OBJPROP_PRICE1);

         double price2 = ObjectGetDouble(0,Obj_Name,OBJPROP_PRICE2);

         long dt1 = ObjectGetInteger(0,Obj_Name,OBJPROP_TIME1);

         long dt2 = ObjectGetInteger(0,Obj_Name,OBJPROP_TIME2);

         long clrRec = ObjectGetInteger(0,Obj_Name,OBJPROP_COLOR);

         long newclr = clrRec;

         if(Bid<price2 && Bid<price1)

           {

            newclr=clrUpper;

           }

         if(Bid>price2 && Bid>price1)

           {

            newclr=clrLower;

           }

         if(clrRec!=newclr){ ObjectSetInteger(0,Obj_Name,OBJPROP_COLOR,newclr); }

         if(StringFind(Obj_Name,"-",0)!=-1 && StringFind(Obj_Name,"_",0)!=-1)

           { // 

            long dt3=dt1+60*60*10*24*365;

            if(dt2<(dt3-60*60*24*365))

              {

               ObjectSetInteger(0,Obj_Name,OBJPROP_TIME2,dt3);

              }

           }

         if(TextWrite)

           {

            // check the signing of levels

            if(StringFind(Obj_Name,"name_TIU_",0)!=-1 && StringFind(Obj_Name,"-",0)==-1)

              {// 

               string txtname=Obj_Name+"txt";

               double priceTxt=0; long dateTxt=0,dateTxt2=0; double pr1=0; int subw=0;

               int pixWidth=(int)NormalizeDouble((ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,0))/2,0);



               if(ObjectFind(0,txtname)!=-1)

                 { // 

                  priceTxt= ObjectGetDouble(0,txtname,OBJPROP_PRICE);

                  dateTxt = ObjectGetInteger(0,txtname,OBJPROP_TIME);

                  //Print("dateTxt="+dateTxt+"  priceTxt="+priceTxt);

                    }else{// 

                  string RecText=ObjectGetString(0,Obj_Name,OBJPROP_TEXT);

                  priceTxt=NormalizeDouble((price1+price2)/2,_Digits);



                  ChartXYToTimePrice(0,pixWidth,100,subw,dateTxt,pr1);

                  if(!TextCreate(txtname,dateTxt,priceTxt,RecText,(color)clrCandle))

                    {

                     return;

                    }

                 }

               // 

               bool fix=false;

               // move to the visible part of the screen by date

               ChartXYToTimePrice(0,pixWidth,100,subw,dateTxt2,pr1);

               if(dateTxt!=dateTxt2)

                 {

                  fix=true;

                  dateTxt=dateTxt2;

                 }

               if(dt1<dt2 && dateTxt<dt1)

                 {

                  fix=true;

                  dateTxt=dt1+10*60*_Period;

                 }

               if(dt2<dt1 && dateTxt<dt2)

                 {

                  fix=true;

                  dateTxt=dt2+10*60*_Period;

                 }

               if(priceTxt!=(NormalizeDouble((price1+price2)/2,_Digits)))

                 {

                  fix=true;

                  priceTxt=NormalizeDouble((price1+price2)/2,_Digits);

                 }

               if(fix){ ObjectMove(0,txtname,0,dateTxt,priceTxt); }

              }



              }else{

            // 

            del(secret,OBJ_TEXT);

           }

        }

     }

   return;

  }

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

//|                                                                  |

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

void CheckObjects()

  {



   for(int n=ObjectsTotal()-1; n>=0; n--)

     {

      string ids[]; bool have=false;

      string Obj_Name=ObjectName(n);

      int k=StringSplit(Obj_Name,StringGetCharacter("_",0),ids);

      if(k>2)

        {

         if(ObjectGetInteger(0,Obj_Name,OBJPROP_TYPE)==OBJ_RECTANGLE && StringLen(ids[2])>5 && StringFind(ids[2],"-",0)>0)

           {

            if(LongTIU)

              {

               string subs[];

               int k2=StringSplit(ids[2],StringGetCharacter("-",0),subs);

               if(k2==2)

                 {

                  //

                  if(ObjectFind(0,StringConcatenate(ids[0],"_",ids[1],"_",subs[0]))<0)

                    {

                     ObjectDelete(0,Obj_Name);

                     del(StringConcatenate(ids[0],"_",ids[1],"_",subs[0]),OBJ_TEXT);

                       }else{// 



                    }

                 }

                 }else{

               // 

               ObjectDelete(0,Obj_Name);

              }

              }else{//  

            if(LongTIU)

              {

               LongThisLevel();

              }

           }

        }

     }

   return;

  }

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

//|                                                                  |

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

void WaitCrossing()

  {



   if(lastAlert<soundMax && (Alerts || Flash))

     {

      long lastBGcolor=ChartGetInteger(0,CHART_COLOR_BACKGROUND,0);

      for(int n=ObjectsTotal()-1; n>=0; n--)

        {

         string Obj_Name=ObjectName(n);

         if(ObjectGetInteger(0,Obj_Name,OBJPROP_TYPE)==OBJ_RECTANGLE)

           { // 

            double price1 = ObjectGetDouble(0,Obj_Name,OBJPROP_PRICE1);

            double price2 = ObjectGetDouble(0,Obj_Name,OBJPROP_PRICE2);

            long dt1 = ObjectGetInteger(0,Obj_Name,OBJPROP_TIME1);

            long dt2 = ObjectGetInteger(0,Obj_Name,OBJPROP_TIME2);

            long clrRec = ObjectGetInteger(0,Obj_Name,OBJPROP_COLOR);

            long newclr = clrRec;



            if(price1>price2)

              {

               if((lastBid<price2 && Close[0]>price2) || (lastBid>price1 && Close[0]<price1))

                 {

                  if(Alerts){ PlaySound(soundFile); }

                  if(Flash && lastBGcolor!=clrAlertBG){ ChartSetInteger(0,CHART_COLOR_BACKGROUND,clrAlertBG); }

                  lastAlert++;

                 }

              }

            if(price1<price2)

              {

               if((lastBid<price1 && Close[0]>price1) || (lastBid>price2 && Close[0]<price2))

                 {

                  if(Alerts){ PlaySound(soundFile); }

                  if(Flash && lastBGcolor!=clrAlertBG){ ChartSetInteger(0,CHART_COLOR_BACKGROUND,clrAlertBG); }

                  lastAlert++;

                 }

              }

           }

        }

     }



   return;

  }

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

//|                                                                  |

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

void Magnite(string prefix="all")

  {

// we tighten levels to candles

   for(int n=ObjectsTotal()-1; n>=0; n--)

     {

      string Obj_Name=ObjectName(n);

      if(ObjectGetInteger(0,Obj_Name,OBJPROP_TYPE)==OBJ_RECTANGLE && StringFind(Obj_Name,"-",0)==-1 && ((StringFind(Obj_Name,prefix,0)!=-1 && prefix!="all") || prefix=="all"))

        { // 

         double price1 = ObjectGetDouble(0,Obj_Name,OBJPROP_PRICE1);

         double price2 = ObjectGetDouble(0,Obj_Name,OBJPROP_PRICE2);

         double deltaPrice=MathAbs(price1-price2);

         //

         long dt1 = ObjectGetInteger(0,Obj_Name,OBJPROP_TIME1);

         long dt2 = ObjectGetInteger(0,Obj_Name,OBJPROP_TIME2);

         long deltaDate=MathAbs(dt1-dt2);

         //

         long startTime=0; double maxBody=0; int kuda=0; int tochka=0; long dateTochka=0;

         if(dt1<dt2){ startTime=dt1; }else{ startTime=dt2; }

         int shiftStart=iBarShift(_Symbol,_Period,startTime);

         for(int b=shiftStart;b>0;b--)

           {

            if(b==shiftStart)

              {

               if(price2<price1 && price2<=Low[b])

                 {// 

                  kuda=1;

                  if(Open[b]>Close[b])

                    {// 

                     maxBody=Close[b]; tochka=0; dateTochka=dt1;

                       }else{//

                     maxBody=Open[b]; tochka=0;  dateTochka=dt1;

                    }

                 }

               if(price1<price2 && price1<=Low[b])

                 {// 

                  kuda=1;

                  if(Open[b]>Close[b])

                    {// 

                     maxBody=Close[b]; tochka=1; dateTochka=dt2;

                       }else{// 

                     maxBody=Open[b]; tochka=1; dateTochka=dt2;

                    }

                 }

               if(price2<price1 && price1>=High[b])

                 {// 

                  kuda=-1;

                  if(Open[b]>Close[b])

                    {// 

                     maxBody=Open[b]; tochka=1; dateTochka=dt2;

                       }else{// 

                     maxBody=Close[b]; tochka=1;  dateTochka=dt2;

                    }

                 }

               if(price1<price2 && price2>=High[b])

                 {// 

                  kuda=-1;

                  if(Open[b]>Close[b])

                    {// 

                     maxBody=Open[b]; tochka=0; dateTochka=dt1;

                       }else{// 

                     maxBody=Close[b]; tochka=0; dateTochka=dt1;

                    }

                 }



                 }else{

               if(kuda==1)

                 {

                  if(Open[b]>Close[b])

                    {// 

                     if(maxBody<Close[b])

                       {// 

                        if(price2<price1)

                          {

                           ObjectMove(0,Obj_Name,0,dt1,maxBody);

                           ObjectMove(0,Obj_Name,1,dt2,maxBody-deltaPrice);

                             }else{

                           ObjectMove(0,Obj_Name,0,dt1,maxBody-deltaPrice);

                           ObjectMove(0,Obj_Name,1,dt2,maxBody);

                          }

                        break;

                          }else{

                        maxBody=Close[b];

                       }

                       }else{// 

                     if(maxBody<Open[b])

                       {// 

                        if(price2<price1)

                          {

                           ObjectMove(0,Obj_Name,0,dt1,maxBody);

                           ObjectMove(0,Obj_Name,1,dt2,maxBody-deltaPrice);

                             }else{

                           ObjectMove(0,Obj_Name,0,dt1,maxBody-deltaPrice);

                           ObjectMove(0,Obj_Name,1,dt2,maxBody);

                          }

                        break;

                          }else{

                        maxBody=Open[b];

                       }

                    }

                 }

               if(kuda==-1)

                 {//  

                  if(Open[b]>Close[b])

                    {// 

                     if(maxBody>Open[b])

                       {// 

                        if(price2<price1)

                          {

                           ObjectMove(0,Obj_Name,0,dt1,maxBody+deltaPrice);

                           ObjectMove(0,Obj_Name,1,dt2,maxBody);

                             }else{

                           ObjectMove(0,Obj_Name,0,dt1,maxBody);

                           ObjectMove(0,Obj_Name,1,dt2,maxBody+deltaPrice);

                          }

                        break;

                          }else{

                        maxBody=Open[b];

                       }

                       }else{// 

                     if(maxBody>Close[b])

                       {// 

                        if(price2<price1)

                          {

                           ObjectMove(0,Obj_Name,0,dt1,maxBody+deltaPrice);

                           ObjectMove(0,Obj_Name,1,dt2,maxBody);

                             }else{

                           ObjectMove(0,Obj_Name,0,dt1,maxBody);

                           ObjectMove(0,Obj_Name,1,dt2,maxBody+deltaPrice);

                          }

                        break;

                          }else{

                        maxBody=Close[b];

                       }

                    }

                 }

              }

           }

        }

     }



   return;

  }

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

//|                                                                  |

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

string ReturnTF(int tfw=0)

  {

   switch(tfw)

     {

      case 1:

         return "M1";

         break;

      case 5:

         return "M5";

         break;

      case 15:

         return "M15";

         break;

      case 30:

         return "M30";

         break;

      case 60:

         return "H1";

         break;

      case 240:

         return "H4";

         break;

      case 1440:

         return "D1";

         break;

      case 10080:

         return "W1";

         break;

      case 43200:

         return "MN";

         break;

     }

   return "";

  }

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

bool TextCreate(const string            name="Text",              // 

                datetime                time=0,                   //  

                double                  price=0,                  // 

                const string            text="Text",              //  

                const color             clr=clrRed)               //

  {

   long              chart_ID=0;               // 

   int               sub_window=0;             // 

   string            font="Arial";             //  

   int               font_size=10;             // 

   double            angle=0.0;                //  

   ENUM_ANCHOR_POINT anchor=ANCHOR_LEFT; // 

   bool              back=false;               // 

   bool              selection=false;          // 

   bool              hidden=false;              // 

   long              z_order=0;                //  



   ResetLastError();

   if(ObjectFind(name)==-1)

      ObjectCreate(chart_ID,name,OBJ_TEXT,sub_window,time,price);

   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);

   ObjectSetString(chart_ID,name,OBJPROP_FONT,font);

   ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);

   ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle);

   ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor);

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);

   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);

   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);

   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);

   ObjectSetString(chart_ID,name,OBJPROP_TOOLTIP,text);

   return(true);

  }

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

//|                                                                  |

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

int del(string name="all",ENUM_OBJECT type=-1)

  {

   for(int n=ObjectsTotal()-1; n>=0; n--)

     {

      string Obj_Name=ObjectName(n);

      if((type==-1 && name!="all" && StringFind(Obj_Name,name,0)!=-1) || 

         (type>-1 && ObjectGetInteger(0,Obj_Name,OBJPROP_TYPE)==type && name!="all" && StringFind(Obj_Name,name,0)!=-1) ||

         (type>-1 && ObjectGetInteger(0,Obj_Name,OBJPROP_TYPE)==type && name=="all"))

        {

         ObjectDelete(Obj_Name);

        }

     }

   return 0;                                      // 

  }

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

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 ---