Need Little help print signal name on chart

 

Hi,

This help I am seeking from expert traders, Below is the code of an indicator in which 2 small lines moves together along with each new candle. I just stuck to add name of line just above it which could move along with line & candle.

I just want to know the function and where to add it, if you anybody add in it with highlighted text, I will be thankful to you.

LINE NAME ARE -> OP_3 and MX_3

          

Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Account Properties
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Account Properties
  • www.mql5.com
Account Properties - Environment State - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Files:
mxop.PNG  2 kb
 

I doubt that there are many that will even try to decipher that mess.

You should know how to post code properly by now.

</> or Alt + S

 
Keith Watford #:

I doubt that there are many that will even try to decipher that mess.

You should know how to post code properly by now.

</> or Alt + S

Thank you for suggesting me to send it correctly.

Attaching mql5 file.

Files:
Sample_code.mq5  30 kb
 
Manpreet Singh #: Thank you for suggesting me to send it correctly. Attaching mql5 file.

Start firstly by changing your coding style. As it is now makes it a complete nightmare to understand or debug.

For now use the internal Code Styler in MetaEditor to sort out your code — MetaEditor Menu: Tools → Styler

You can choose the style you prefer in the options — MetaEditor Menu: Options → Styler

I personally currently like to use the "Google" style, and for example, your original code at line 50:

double M15_Value(int st0, int st1) {ENUM_TIMEFRAMES per = PERIOD_M15; int n = st1- st0+1; double sy = iClose(_Symbol, per,st0); double sx = 0.0; double sxy = 0.0; double sxx = 0.0; for(int i = 1; i < n && IsStopped() != true; i++) {double x = i; double y = iClose(_Symbol,per,st0+i); sx = sx+x; sy  = sy+y; sxx = sxx+(x*x); sxy = sxy+(x*y);} double c = sxx*n-sx*sx; if(c == 0.0) {return(0);} double Beta = (n*sxy-sx*sy)/c; double Alfa = (sy-Beta*sx)/n; double rv = Alfa; return(rv);}

Would become this which is much more readable and easier to visually debug:

double M15_Value(int st0, int st1) {
   ENUM_TIMEFRAMES per = PERIOD_M15;
   int n = st1 - st0 + 1;
   double sy = iClose(_Symbol, per, st0);
   double sx = 0.0;
   double sxy = 0.0;
   double sxx = 0.0;
   for(int i = 1; i < n && IsStopped() != true; i++) {
      double x = i;
      double y = iClose(_Symbol, per, st0 + i);
      sx = sx + x;
      sy  = sy + y;
      sxx = sxx + (x * x);
      sxy = sxy + (x * y);
   }
   double c = sxx * n - sx * sx;
   if(c == 0.0) {
      return(0);
   }
   double Beta = (n * sxy - sx * sy) / c;
   double Alfa = (sy - Beta * sx) / n;
   double rv = Alfa;
   return(rv);
}

I would clean it up even further manually, but that is just my personal preference. It really is up to you to style in a way that helps you to write better code.

Once you have adapted a better coding style, it will be easier for you to find the logic bugs and fix your own code more easily.

 
Manpreet Singh:

Hi,

This help I am seeking from expert traders, Below is the code of an indicator in which 2 small lines moves together along with each new candle. I just stuck to add name of line just above it which could move along with line & candle.

I just want to know the function and where to add it, if you anybody add in it with highlighted text, I will be thankful to you.

LINE NAME ARE -> OP_3 and MX_3

          

You sir have a very wide screen .

this is the function (only for horizontals and trends that are horizontal)

/*
pass the line name first - which you have created before
*/ 
    /* Anchor options
    ANCHOR_LEFT_UPPER 
    ANCHOR_LEFT 
    ANCHOR_LEFT_LOWER
    ANCHOR_LOWER
    ANCHOR_RIGHT_LOWER
    ANCHOR_RIGHT
    ANCHOR_RIGHT_UPPER
    ANCHOR_UPPER
    ANCHOR_CENTER 
    */
void add_price_text_to_line(long chart_id,//which chart id 
                            string line_name,//the name of the hline
                            ENUM_ANCHOR_POINT anchor,//anchor of the text ,or positioning around the display point
                            datetime price_label_time,//the position of the price label in the x axis (time)
                            color price_label_color,
                            int price_label_fontsize,
                            string price_label_text){//NULL for just price
//first get the price line 
  ResetLastError();//reset the last error before this command so you know if it fails 
  double price=ObjectGetDouble(chart_id,line_name,OBJPROP_PRICE,0);
  //if there are no errors 
    //which means if the line exists 
      if(GetLastError()==0)
      {
      //now you have the price and the time so you create the text of the price  
        //give it a handy name 
          string name=line_name+"_PRICE_LABEL";
          ObjectCreate(chart_id,name,OBJ_TEXT,0,price_label_time,price);
          //and adjust it
            ObjectSetInteger(chart_id,name,OBJPROP_COLOR,price_label_color);
            ObjectSetInteger(chart_id,name,OBJPROP_FONTSIZE,price_label_fontsize);
            ObjectSetInteger(chart_id,name,OBJPROP_ANCHOR,anchor);
            //final property , if the label text sent is not empty set it as the label text 
            if(price_label_text!=NULL&&StringLen(price_label_text)>0)
              {
              ObjectSetString(chart_id,name,OBJPROP_TEXT,price_label_text);
              }//otherwise just place the price in
              else{
              ObjectSetString(chart_id,name,OBJPROP_TEXT,DoubleToString(price,_Digits));
              }
      ChartRedraw(chart_id);
      }else{
      Print("Line "+line_name+" Does not exist ");
      }
}

and i skimmed through the code and added it where it could logically go but you know your system better , and also what Fernando said . 

//+----------------------------------------------------------------------------------------------------------------------------------------+
           bool                 line_remove                    = true;                     // Line remove with indicator
           string               line_seperator_01;                                         // -------Lines color------------------------
           color                ssi_MX_3_clr                   = clrYellow;                // MX_3
           color                OP_3_clr                       = clrYellow;                // OP_3
           string               line_seperator_02;                                         // -------Lines style------------------------
           ENUM_LINE_STYLE      ssi_MX_3_style                 = STYLE_SOLID;              // MX_3
           ENUM_LINE_STYLE      OP_3_style                     = STYLE_DASHDOTDOT;         // OP_3
           string               line_seperator_03;                                         // -------Lines width------------------------
           int                  ssi_MX_3_width                 = 0001;                     // MX_3
           int                  OP_3_width                     = 0001;                     // OP_3
           string               line_seperator_06;                                         // -------H1 time frame----------------------
           bool                 ssi_MX_3_h1_show               = false;                    // MX_3
           bool                 OP_3_h1_show                   = false;                    // OP_3
           string               line_seperator_07;                                         // -------M30 time frame---------------------
           bool                 ssi_MX_3_m30_show              = false;                    // MX_3
           bool                 OP_3_m30_show                  = false;                    // OP_3
    input  string               line_seperator_08;                                         // -------M15 time frame---------------------
    input  bool                 ssi_MX_3_m15_show              = true;                     // MX_3
    input  bool                 OP_3_m15_show                  = true;                     // OP_3
           string               line_seperator_11;                                         // -------SSI_Config.------------------------
           int                  ssi_period                     = 21;                       // Period
           int                  ssi_shift                      = 00;                       // Shift
           int                  ssi_level                      = 00;                       // Level
    input ENUM_ANCHOR_POINT     texts_anchor = ANCHOR_LEFT_LOWER;
    input int fontsize=20;
//+----------------------------------------------------------------------------------------------------------------------------------------+
    int MX_3_left_value = 07;  int MX_3_right_value = 05;
    int OP_3_l_value = 00; int OP_3_r_value = 10;
//+----------------------------------------------------------------------------------------------------------------------------------------+
    int _DateSummation; datetime _ExpireDate; datetime _TimesLocal;
    double _Buffer_01[]; string _FileName;
    string OP_3_line = "OP_3"; 
    string ssi_MX_3_line = "MX_3";
    string ob_1 = "Info 1"; string ob_2 = "Info 2"; string ob_3 = "Info 3";   string ob_4 = "Info 4";
    string dash = "Dashboard";
//+----------------------------------------------------------------------------------------------------------------------------------------+
    void AllDELETE()
    {
    ObjectDelete(0,dash); ObjectDelete(0,ob_1); ObjectDelete(0,ob_2); ObjectDelete(0,ob_3); ObjectDelete(0,ob_4);
    if(line_remove == true)
    {
    long current_id = 0, prev_id = ChartFirst(); int s = 0, limits = 100; double prev_price = 0;
    while(s < limits)
    {
    current_id = ChartNext(current_id); if(current_id < 0) break; string sym = ChartSymbol(current_id); prev_id = current_id; s++; if(sym == _Symbol)
    {
    ObjectDelete(current_id,OP_3_line); ObjectDelete(current_id,ssi_MX_3_line);  
    }}}}
//+----------------------------------------------------------------------------------------------------------------------------------------+
    double M15_Value(int st0, int st1) {ENUM_TIMEFRAMES per = PERIOD_M15; int n = st1- st0+1; double sy = iClose(_Symbol, per,st0); double sx = 0.0; double sxy = 0.0; double sxx = 0.0; for(int i = 1; i < n && IsStopped() != true; i++) {double x = i; double y = iClose(_Symbol,per,st0+i); sx = sx+x; sy  = sy+y; sxx = sxx+(x*x); sxy = sxy+(x*y);} double c = sxx*n-sx*sx; if(c == 0.0) {return(0);} double Beta = (n*sxy-sx*sy)/c; double Alfa = (sy-Beta*sx)/n; double rv = Alfa; return(rv);}
    //double M30_Value(int st0, int st1) {ENUM_TIMEFRAMES per = PERIOD_M30; int n = st1- st0+1; double sy = iClose(_Symbol, per,st0); double sx = 0.0; double sxy = 0.0; double sxx = 0.0; for(int i = 1; i < n && IsStopped() != true; i++) {double x = i; double y = iClose(_Symbol,per,st0+i); sx = sx+x; sy  = sy+y; sxx = sxx+(x*x); sxy = sxy+(x*y);} double c = sxx*n-sx*sx; if(c == 0.0) {return(0);} double Beta = (n*sxy-sx*sy)/c; double Alfa = (sy-Beta*sx)/n; double rv = Alfa; return(rv);}
    //double H1_Value(int st0, int st1) {ENUM_TIMEFRAMES per = PERIOD_H1; int n = st1- st0+1; double sy = iClose(_Symbol, per,st0); double sx = 0.0; double sxy = 0.0; double sxx = 0.0; for(int i = 1; i < n && IsStopped() != true; i++) {double x = i; double y = iClose(_Symbol,per,st0+i); sx = sx+x; sy  = sy+y; sxx = sxx+(x*x); sxy = sxy+(x*y);} double c = sxx*n-sx*sx; if(c == 0.0) {return(0);} double Beta = (n*sxy-sx*sy)/c; double Alfa = (sy-Beta*sx)/n; double rv = Alfa; return(rv);}
//+----------------------------------------------------------------------------------------------------------------------------------------+
    int OnInit()
    {
    EventSetTimer(1);
    AllDELETE();
//--trial protection variable:
    _FileName = MQLInfoString(MQL_PROGRAM_NAME)+": "; _TimesLocal = TimeLocal(); _ExpireDate = StringToTime(string(_ExpireTime_)+" 23:59:59"); _DateSummation = int(StringSubstr(_ExpireTime_,0,2))+int(StringSubstr(_ExpireTime_,3,2))+int(StringSubstr(_ExpireTime_,6,4));
    if((((_DateSummation > 0 && TimeCurrent() <= _ExpireDate) || _DateSummation <= 0) && ((_AccountNumber_ > 0 && AccountInfoInteger(ACCOUNT_LOGIN) == _AccountNumber_) || _AccountNumber_ <= 0)))
//--trial time expiration alert:
    if(_DateSummation > 0 && TimeCurrent() > _ExpireDate) {Alert(_FileName+"Trial Period is over!");}
//--last 30 days trial time alert:
    int trial1_remaining_days = int(int(StringToTime(TimeToString(_ExpireDate,TIME_DATE|TIME_DATE))-StringToTime(TimeToString(TimeCurrent(),TIME_DATE|TIME_DATE)))/(60*60*24)); if(_DateSummation > 0 && trial1_remaining_days <= 31 && trial1_remaining_days >= 0) {Alert(_FileName+"You have more "+string(trial1_remaining_days)+" day(s) trial period!");}
//--account un-authorized alert:
    if(_AccountNumber_ > 0 && AccountInfoInteger(ACCOUNT_LOGIN) != _AccountNumber_) {Alert(_FileName+"This Account is not authrized by developer!");}
//--account non-demo alert:
    if(AccountInfoInteger(ACCOUNT_TRADE_MODE) != ACCOUNT_TRADE_MODE_DEMO && _LicenseDemo_ == true) {Alert(_FileName+"Your Account is not demo. But this Indicator is only for demo account!");}
    return(INIT_SUCCEEDED);
    }
//+----------------------------------------------------------------------------------------------------------------------------------------+
    void OnDeinit(const int reason)
    {
    AllDELETE();
    EventKillTimer();
    }
//+----------------------------------------------------------------------------------------------------------------------------------------+
    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[])
    {
    return(rates_total);
    }
//+----------------------------------------------------------------------------------------------------------------------------------------+
    void OnTimer()
    {
    if((((_DateSummation > 0 && TimeCurrent() <= _ExpireDate) || _DateSummation <= 0) && ((_AccountNumber_ > 0 && AccountInfoInteger(ACCOUNT_LOGIN) == _AccountNumber_) || _AccountNumber_ <= 0) && (_LicenseDemo_ == false || (_LicenseDemo_ == true && (AccountInfoInteger(ACCOUNT_TRADE_MODE) == ACCOUNT_TRADE_MODE_DEMO || MQLInfoInteger(MQL_TESTER) == true)))))
    {
    datetime set_time = TimeLocal();
    datetime ob_set_time = (set_time+(365*24*60*60));
    ENUM_TIMEFRAMES m1 = PERIOD_M1; ENUM_TIMEFRAMES m5 = PERIOD_M5; ENUM_TIMEFRAMES m15 = PERIOD_M15; ENUM_TIMEFRAMES m30 = PERIOD_M30; ENUM_TIMEFRAMES h1 = PERIOD_H1; ENUM_TIMEFRAMES h4 = PERIOD_H4; ENUM_TIMEFRAMES d1 = PERIOD_D1; ENUM_TIMEFRAMES w1 = PERIOD_W1; ENUM_TIMEFRAMES mn1 = PERIOD_MN1;

//--symbol details:
    double _Price; double _Pips; int _Pipettes;
    if(_Digits <= 3) {_Price = 0.01; _Pips = 100.00; _Pipettes = 1000;} else{_Price = 0.0001; _Pips = 10000.00; _Pipettes = 100000;} if(StringSubstr(_Symbol,0,3) == "XAU" || StringSubstr(_Symbol,0,4) == "GOLD") {_Price = 0.10; _Pips = 10.00; _Pipettes = 100;} else{_Price = _Price; _Pips = _Pips; _Pipettes = _Pipettes;}
    double ask_price = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
    double bid_price = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);

//--ssi indicator value:
    double ssi_MX_3_price = NormalizeDouble((M15_Value(0,0+ssi_period-1)+ssi_level*_Point),_Digits);

//--Shooter price:
    double OP_3 = NormalizeDouble(iOpen(_Symbol,PERIOD_M15,0),_Digits);

//--frame:
    string per = NULL; if(_Period == PERIOD_M1) {per = "M1";} else if(_Period == PERIOD_M5) {per = "M5";} else if(_Period == PERIOD_M15) {per = "M15";} else if(_Period == PERIOD_M30) {per = "M30";} else if(_Period == PERIOD_H1) {per = "H1";} else if(_Period == PERIOD_H4) {per = "H4";} else if(_Period == PERIOD_D1) {per = "D1";} else if(_Period == PERIOD_W1) {per = "W1";} else if(_Period == PERIOD_MN1) {per = "MN1";}
    double diff_1 = 0; double diff_2 = 0;

//--shooter lines:
    {string line_name = "OP_3_line"; double line_price = OP_3; color line_clr = OP_3_clr; ENUM_LINE_STYLE line_style = OP_3_style; int line_width = OP_3_width; long current_id = 0, prev_id = ChartFirst(); int s = 0, limits = 100; while(s < limits) {current_id = ChartNext(current_id); if(current_id < 0) break; string sym = ChartSymbol(current_id); ENUM_TIMEFRAMES peri = ChartPeriod(current_id); prev_id = current_id; s++; int pr = 0; if(peri == PERIOD_M1) {pr = 1;} else if(peri == PERIOD_M5) {pr = 5;} else if(peri == PERIOD_M15) {pr = 15;} else if(peri == PERIOD_M30) {pr = 30;} else if(peri == PERIOD_H1) {pr = 60;} else if(peri == PERIOD_H4) {pr = 240;} else if(peri == PERIOD_D1) {pr = 1440;} else if(peri == PERIOD_W1) {pr = 10080;} else if(peri == PERIOD_MN1) {pr = 43200;} else{pr = peri;} double diff = (pr*60); static datetime OP_3_static[101]; datetime tm_0 = iTime(sym,peri,0); datetime time_01 = datetime(tm_0+(OP_3_r_value*diff)); datetime time_02 = datetime(tm_0-((OP_3_l_value-6)*diff)); bool sr_show_ok = false; if((peri == m15 && OP_3_m15_show == true) || (peri == m30 && OP_3_m30_show == true) || (peri == h1 && OP_3_h1_show == true)) {sr_show_ok = true;} else{sr_show_ok = false;} if(sym == _Symbol && sr_show_ok == true) {if(line_name != NULL && line_name != "" && ObjectFind(current_id,line_name) < 0) {ObjectCreate(current_id,line_name,OBJ_TREND,0,time_01,line_price,time_02,line_price); ObjectSetInteger(current_id,line_name,OBJPROP_STYLE,line_style); ObjectSetInteger(current_id,line_name,OBJPROP_WIDTH,line_width); ObjectSetInteger(current_id,line_name,OBJPROP_COLOR,line_clr); add_price_text_to_line(current_id,line_name,texts_anchor,time_02,line_clr,fontsize,NULL); ObjectSetInteger(current_id,line_name,OBJPROP_SELECTABLE,true); ObjectSetInteger(current_id,line_name,OBJPROP_HIDDEN,true); ObjectSetInteger(current_id,line_name,OBJPROP_BACK,true);} if(OP_3_static[s] != tm_0) {ObjectMove(current_id,line_name,0,time_01,line_price); ObjectMove(current_id,line_name,1,time_02,line_price); OP_3_static[s] = tm_0;}}}}

//--ssi lines:
    {
    string n_MX_3 = ssi_MX_3_line; 
    double prev_price = 0; {long current_id = 0, prev_id = ChartFirst(); int s = 0, limits = 100; while(s < limits) {current_id = ChartNext(current_id); if(current_id < 0) break; string sym = ChartSymbol(current_id); prev_id = current_id; s++;}} double prev_lower_price = 0; {long current_id = 0, prev_id = ChartFirst(); int s = 0, limits = 100; while(s < limits) {current_id = ChartNext(current_id); if(current_id < 0) break; string sym = ChartSymbol(current_id); prev_id = current_id; s++;}} {long current_id = 0, prev_id = ChartFirst(); int s = 0, limits = 100; while(s < limits) {current_id = ChartNext(current_id); if(current_id < 0) break; string sym = ChartSymbol(current_id);
    ENUM_TIMEFRAMES peri = ChartPeriod(current_id); prev_id = current_id; s++;
    int pr = 0; if(peri == PERIOD_M1) {pr = 1;} else if(peri == PERIOD_M5) {pr = 5;} else if(peri == PERIOD_M15) {pr = 15;} else if(peri == PERIOD_M30) {pr = 30;} else if(peri == PERIOD_H1) {pr = 60;} else if(peri == PERIOD_H4) {pr = 240;} else if(peri == PERIOD_D1) {pr = 1440;} else if(peri == PERIOD_W1) {pr = 10080;} else if(peri == PERIOD_MN1) {pr = 43200;} else{pr = peri;} double diff = (pr*60);
    datetime MX_3_time_01 = datetime(iTime(sym,peri,0)+(MX_3_right_value*diff)); datetime MX_3_time_02 = datetime(iTime(sym,peri,0)-((MX_3_left_value-6)*diff));
    bool ssi_MX_3_show_ok = false; if((peri == m15 && ssi_MX_3_m15_show == true) || (peri == m30 && ssi_MX_3_m30_show == true) || (peri == h1 && ssi_MX_3_h1_show == true)) {ssi_MX_3_show_ok = true;} else{ssi_MX_3_show_ok = false;}
    if(sym == _Symbol && ssi_MX_3_show_ok == true) {if(ObjectFind(current_id,n_MX_3) < 0) {ObjectCreate(current_id,n_MX_3,OBJ_TREND,0,MX_3_time_01,ssi_MX_3_price,MX_3_time_02,ssi_MX_3_price); ObjectSetInteger(current_id,n_MX_3,OBJPROP_STYLE,ssi_MX_3_style); ObjectSetInteger(current_id,n_MX_3,OBJPROP_WIDTH,ssi_MX_3_width); ObjectSetInteger(current_id,n_MX_3,OBJPROP_COLOR,ssi_MX_3_clr); add_price_text_to_line(current_id,n_MX_3,texts_anchor,MX_3_time_02,ssi_MX_3_clr,fontsize,NULL); ObjectSetInteger(current_id,n_MX_3,OBJPROP_SELECTABLE,false); ObjectSetInteger(current_id,n_MX_3,OBJPROP_SELECTED,false); ObjectSetInteger(current_id,n_MX_3,OBJPROP_HIDDEN,true); ObjectSetInteger(current_id,n_MX_3,OBJPROP_BACK,true);} else if(ObjectFind(current_id,n_MX_3) >= 0) {double g_price = NormalizeDouble(ObjectGetDouble(current_id,n_MX_3,OBJPROP_PRICE),_Digits); datetime g_time = datetime(ObjectGetInteger(current_id,n_MX_3,OBJPROP_TIME)); if(g_price != ssi_MX_3_price || g_time != MX_3_time_01) {ObjectMove(current_id,n_MX_3,0,MX_3_time_01,ssi_MX_3_price); ObjectMove(current_id,n_MX_3,1,MX_3_time_02,ssi_MX_3_price); ObjectMove(current_id,n_MX_3+"_PRICE_LABEL",0,MX_3_time_02,ssi_MX_3_price);}}}
    }}}}}
//+----------------------------------------------------------------------------------------------------------------------------------------+
/*
pass the line name first - which you have created before
*/ 
    /* Anchor options
    ANCHOR_LEFT_UPPER 
    ANCHOR_LEFT 
    ANCHOR_LEFT_LOWER
    ANCHOR_LOWER
    ANCHOR_RIGHT_LOWER
    ANCHOR_RIGHT
    ANCHOR_RIGHT_UPPER
    ANCHOR_UPPER
    ANCHOR_CENTER 
    */
void add_price_text_to_line(long chart_id,//which chart id 
                            string line_name,//the name of the hline
                            ENUM_ANCHOR_POINT anchor,//anchor of the text ,or positioning around the display point
                            datetime price_label_time,//the position of the price label in the x axis (time)
                            color price_label_color,
                            int price_label_fontsize,
                            string price_label_text){//NULL for just price
//first get the price line 
  ResetLastError();//reset the last error before this command so you know if it fails 
  double price=ObjectGetDouble(chart_id,line_name,OBJPROP_PRICE,0);
  //if there are no errors 
    //which means if the line exists 
      if(GetLastError()==0)
      {
      //now you have the price and the time so you create the text of the price  
        //give it a handy name 
          string name=line_name+"_PRICE_LABEL";
          ObjectCreate(chart_id,name,OBJ_TEXT,0,price_label_time,price);
          //and adjust it
            ObjectSetInteger(chart_id,name,OBJPROP_COLOR,price_label_color);
            ObjectSetInteger(chart_id,name,OBJPROP_FONTSIZE,price_label_fontsize);
            ObjectSetInteger(chart_id,name,OBJPROP_ANCHOR,anchor);
            //final property , if the label text sent is not empty set it as the label text 
            if(price_label_text!=NULL&&StringLen(price_label_text)>0)
              {
              ObjectSetString(chart_id,name,OBJPROP_TEXT,price_label_text);
              }//otherwise just place the price in
              else{
              ObjectSetString(chart_id,name,OBJPROP_TEXT,DoubleToString(price,_Digits));
              }
      ChartRedraw(chart_id);
      }else{
      Print("Line "+line_name+" Does not exist ");
      }
}

I did not test it as there are components missing 

  ☕️

 
Fernando Carreiro #:

Start firstly by changing your coding style. As it is now makes it a complete nightmare to understand or debug.

For now use the internal Code Styler in MetaEditor to sort out your code — MetaEditor Menu: Tools → Styler

You can choose the style you prefer in the options — MetaEditor Menu: Options → Styler

I personally currently like to use the "Google" style, and for example, your original code at line 50:

Would become this which is much more readable and easier to visually debug:

I would clean it up even further manually, but that is just my personal preference. It really is up to you to style in a way that helps you to write better code.

Once you have adapted a better coding style, it will be easier for you to find the logic bugs and fix your own code more easily.

Thank you, noted.

 
Lorentzos Roussos #:

You sir have a very wide screen .

this is the function (only for horizontals and trends that are horizontal)

and i skimmed through the code and added it where it could logically go but you know your system better , and also what Fernando said . 

I did not test it as there are components missing 

  ☕️

Thank you for correcting me, I have added the code but struggling to fix the errors.
Files:
Sample_CS.mq5  45 kb
Reason: