Indicator short name is not changing within expert advisor code (EA)

 

Hi i have this problem that i have not found a solution for it in the forum 

this is the example code to call indicator within the ea code : (using ChartIndicatorAdd)

#property description "Expert Advisor demonstrating the work with ChartIndicatorAdd() function."
#property description "After launching on the chart (and receiving the error in Journal), open"
#property description "the Expert Advisor's properties and specify correct <symbol> and <period> parameters."
#property description "MACD indicator will be added on the chart."
 
//--- input parameters
input string          symbol="AUDUSD";    // symbol name
input ENUM_TIMEFRAMES period=PERIOD_M12;  // time frame
input int    fast_ema_period=12;          // fast MACD period
input int    slow_ema_period=26;          // slow MACD period
input int      signal_period=9;           // signal period
input ENUM_APPLIED_PRICE apr=PRICE_CLOSE; // price type for MACD calculation
 
int indicator_handle=INVALID_HANDLE;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   indicator_handle=iMACD(symbol,period,fast_ema_period,slow_ema_period,signal_period,apr);

  IndicatorSetString(INDICATOR_SHORTNAME,"New Name") ;  // i have added this line for setting the indicator short name as it use to work in the indicator       

//--- try to add the indicator on the chart
   if(!AddIndicator())
     {
      //--- AddIndicator() function refused to add the indicator on the chart
      int answer=MessageBox("Do you want to add MACD on the chart anyway?",
                            "Incorrect symbol and/or time frame for adding the indicator",
                            MB_YESNO // "Yes" and "No" selection buttons will be shown
                            );
      //--- if a user still insists on incorrect usage of ChartIndicatorAdd()
      if(answer==IDYES)
        {
         //--- first of all, a Journal entry will be made about that
         PrintFormat("Attention! %s: Trying to add MACD(%s/%s) indicator on %s/%s chart. Receiving error 4114",
                     __FUNCTION__,symbol,EnumToString(period),_Symbol,EnumToString(_Period));
         //--- receive the number of a new subwindow, to which we will try to add the indicator
         int subwindow=(int)ChartGetInteger(0,CHART_WINDOWS_TOTAL);
         //--- now make an attempt resulting in error
         if(!ChartIndicatorAdd(0,subwindow,indicator_handle))
            PrintFormat("Failed to add MACD indicator on %d chart window. Error code  %d",
                        subwindow,GetLastError());
        }
     }
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
// Expert Advisor performs nothing
  }
//+------------------------------------------------------------------+
//| Function for checking and adding the indicator on the chart      |
//+------------------------------------------------------------------+
bool AddIndicator()
  {
//--- displayed message
   string message;
//--- check if the indicator symbol and chart symbol match each other
   if(symbol!=_Symbol)
     {
      message="Displaying the use of Demo_ChartIndicatorAdd() function:";
      message=message+"\r\n";
      message=message+"Unable to add the indicator calculated on another symbol on the chart.";
      message=message+"\r\n";
      message=message+"Specify the chart symbol in Expert Advisor's property - "+_Symbol+".";
      Alert(message);
      //--- premature exit, the indicator will not be added on the chart
      return false;
     }
//--- check if the indicator's and chart's time frames match each other
   if(period!=_Period)
     {
      message="Unable to add the indicator calculated on another time frame on the chart.";
      message=message+"\r\n";
      message=message+"Specify the chart time frame in Expert Advisor properties - "+EnumToString(_Period)+".";
      Alert(message);
      //--- premature exit, the indicator will not be added on the chart
      return false;
     }
//--- all checks completed, symbol and indicator time frame match the chart
   if(indicator_handle==INVALID_HANDLE)
     {
      Print(__FUNCTION__,"  Creating MACD indicator");
      indicator_handle=iMACD(symbol,period,fast_ema_period,slow_ema_period,signal_period,apr);
      if(indicator_handle==INVALID_HANDLE)
        {
         Print("Failed to create MACD indicator. Error code ",GetLastError());
        }
     }
//--- reset the error code
   ResetLastError();
//--- apply the indicator to the chart 
   Print(__FUNCTION__,"  Adding MACD indicator on the chart");
   Print("MACD is generated on ",symbol,"/",EnumToString(period));
//--- receive the number of a new subwindow, to which MACD indicator is added
   int subwindow=(int)ChartGetInteger(0,CHART_WINDOWS_TOTAL);
   PrintFormat("Adding MACD indicator on %d chart window",subwindow);
   if(!ChartIndicatorAdd(0,subwindow,indicator_handle))
     {
      PrintFormat("Failed to add MACD indicator on %d chart window. Error code  %d",
                  subwindow,GetLastError());
     }
//--- Indicator added successfully
   return(true);
  }

if any one have a solution i would be glad to help me out. 

Thanks  

Files:
 
Wissam Hussein:

Hi i have this problem that i have not found a solution for it in the forum 

this is the example code to call indicator within the ea code : (using ChartIndicatorAdd)

if any one have a solution i would be glad to help me out. 

Thanks  

 //indicator_handle = iMACD(symbol, period, fast_ema_period, slow_ema_period, signal_period, apr);
 indicator_handle = iCustom(Symbol(), PERIOD_CURRENT, "MACD.ex5");

 //IndicatorSetString(INDICATOR_SHORTNAME, "New Name") ; // i have added this line for setting the indicator short name as it use to work in the indicator

Try this code.

 
Still not working , any ideas ?
 
Wissam Hussein #:
Still not working , any ideas ?

You want to add MACD to the sub-window when that program runs, yes ?

I made sure it would work as it should before I posted it.

 
Nagisa Unada #:

You want to add MACD to the sub-window when that program runs, yes ?

I made sure it would work as it should before I posted it.

I have tried it the macd short name has not changed?? Still the default name , i want the indicator short name to be changed 
 
Wissam Hussein #:
I have tried it the macd short name has not changed?? Still the default name , i want the indicator short name to be changed 
You can only change the indicator short name within the indicator itself. You cannot change it from outside.

Also you cannot change the name of an EA, Script or Service. IndicatorShortName is only effective in indicators, and only for itself.
 
Dominik Egert #:
You can only change the indicator short name within the indicator itself. You cannot change it from outside.

Also you cannot change the name of an EA, Script or Service. IndicatorShortName is only effective in indicators, and only for itself.
Ok i see , i have been thinking about this lately and seems it's not possible only within the indicator code ,, thanks man 
Reason: