" ChartIndicatorAdd " and Error 4114 for any chart symbol and current time frame. Is it important ?

 

hi; i used " ChartIndicatorAdd " with:

if(!ChartIndicatorAdd(0,0,i_handle)) 
      {PrintFormat("*****---> Failed to add i_indicator on %d chart window. Error code  %d",0,GetLastError());}   

& there is error 4114 

https://www.mql5.com/en/docs/chart_operations/chartindicatoradd

as you see : " Error 4114 means that a chart and an added indicator differ by their symbol or time frame. "

is this becouse of " symbol=null & time frame =current " such as define for " ChartIndicatorAdd " and want to draw and add on chart anyway. " ?

is this error important ?
thanks in advance.

Documentation on MQL5: Chart Operations / ChartIndicatorAdd
Documentation on MQL5: Chart Operations / ChartIndicatorAdd
  • www.mql5.com
Chart Operations / ChartIndicatorAdd - Reference on algorithmic/automated trading language for MetaTrader 5
 
How is defined i_handle ? Please show relevant code.
 
angevoyageur:
How is defined i_handle ? Please show relevant code.

hi,Aalin, thank you to reply,

here is it :

.
.
void OnInit()
  {
.
.
.
   //------------------------------------------------------------------------------------------ Ichimoku
   SetIndexBuffer(15,Tenkan_sen,INDICATOR_CALCULATIONS);        
   ArraySetAsSeries(Tenkan_sen,true);
   
   SetIndexBuffer(16,Kijun_sen,INDICATOR_CALCULATIONS);      
   ArraySetAsSeries(Kijun_sen,true);

   SetIndexBuffer(17,Senkou_Span_A,INDICATOR_CALCULATIONS);             
   ArraySetAsSeries(Senkou_Span_A,true);

   SetIndexBuffer(18,Senkou_Span_B,INDICATOR_CALCULATIONS);         
   ArraySetAsSeries(Senkou_Span_B,true);

   SetIndexBuffer(19,Chinkou_Span,INDICATOR_CALCULATIONS);    
   ArraySetAsSeries(Chinkou_Span,true);
            
   Ichimoku_handle=iIchimoku(NULL,0,tenkan_sen,kijun_sen,senkou_span_b);
   if(Ichimoku_handle==INVALID_HANDLE) Print("*****---> Failed to get handle of the Ichimoku indicator error =","  error = ",Ichimoku_handle,GetLastError());  //--- if the handle is not created
   if(!ChartIndicatorAdd(0,0,Ichimoku_handle)) 
     {PrintFormat("*****---> Failed to add Ichimoku indicator on %d chart window. Error code  %d",0,GetLastError());}
     
//------------------------------------------------------------------------------------------  PLOT Moving_Average  
   SetIndexBuffer(20,ExtMoving_AverageBuffer,INDICATOR_CALCULATIONS);
   ArraySetAsSeries(ExtMoving_AverageBuffer,true);
   Moving_Average_handle=iMA(NULL,InpPeriod_MA_TIMEFRAMES,InpMAPeriod,InpMAShift,InpMAMethod,InpAppliedPrice_MA);
   if(Moving_Average_handle==INVALID_HANDLE) Print("*****---> Failed to get handle of the Moving_Average indicator error =",GetLastError());
   if(!ChartIndicatorAdd(0,0,Moving_Average_handle)) 
      {PrintFormat("*****---> Failed to add Moving_Average indicator on %d chart window. Error code  %d",0,GetLastError());}   
.
.
        
  }
 .
.
.
//----------------------------------------------------------------------------------------------------------//
void OnDeinit(const int reason)
  {  
      Comment("");
            
      for(int j=0;j<ChartIndicatorsTotal(0,0);j++)
         {
          ChartIndicatorDelete(0,0,ChartIndicatorName(0,0,j));
         }
     
      ChartRedraw();
      ChartSetInteger(0,CHART_FOREGROUND,foreground);
     
  }
//----------------------------------------------------------------------------------------------------------//
 
TIMisthebest:

hi,Aalin, thank you to reply,

here is it :

Your error is about Ichimoku or Moving average ?

InpPeriod_MA_TIMEFRAMES need to be the same as your current chart timeframe.

   Moving_Average_handle=iMA(NULL,InpPeriod_MA_TIMEFRAMES,InpMAPeriod,InpMAShift,InpMAMethod,InpAppliedPrice_MA);
 
angevoyageur:

Your error is about Ichimoku or Moving average ?

InpPeriod_MA_TIMEFRAMES need to be the same as your current chart timeframe.

sory i forget to paste ,  they are :

....
.

//------------------------------------------------------------------------------------------ Ichimoku
input int tenkan_sen=9;              // period of Tenkan-sen
input int kijun_sen=26;              // period of Kijun-sen
input int senkou_span_b=52;          // period of Senkou Span B
double         Tenkan_sen[];
double         Kijun_sen[];
double         Senkou_Span_A[];
double         Senkou_Span_B[];
double         Chinkou_Span[];
int    Ichimoku_handle;              //--- variable for storing the handle of the iIchimoku indicator

//------------------------------------------------------------------------------------------ Moving_Average
double ExtMoving_AverageBuffer[];
int   Moving_Average_handle;
input ENUM_TIMEFRAMES    InpPeriod_MA_TIMEFRAMES=PERIOD_CURRENT;        // timeframe
input int            InpMAPeriod=50;         // Period
input int            InpMAShift=0;           // Shift
input ENUM_MA_METHOD InpMAMethod=MODE_SMA;  // Method
input ENUM_APPLIED_PRICE InpAppliedPrice_MA=PRICE_CLOSE;   // Applied price

.
.
void OnInit()
  {
.
.
.
   //------------------------------------------------------------------------------------------ Ichimoku
   SetIndexBuffer(15,Tenkan_sen,INDICATOR_CALCULATIONS);        
   ArraySetAsSeries(Tenkan_sen,true);
   
   SetIndexBuffer(16,Kijun_sen,INDICATOR_CALCULATIONS);      
   ArraySetAsSeries(Kijun_sen,true);

   SetIndexBuffer(17,Senkou_Span_A,INDICATOR_CALCULATIONS);             
   ArraySetAsSeries(Senkou_Span_A,true);

   SetIndexBuffer(18,Senkou_Span_B,INDICATOR_CALCULATIONS);         
   ArraySetAsSeries(Senkou_Span_B,true);

   SetIndexBuffer(19,Chinkou_Span,INDICATOR_CALCULATIONS);    
   ArraySetAsSeries(Chinkou_Span,true);
            
   Ichimoku_handle=iIchimoku(NULL,0,tenkan_sen,kijun_sen,senkou_span_b);
   if(Ichimoku_handle==INVALID_HANDLE) Print("*****---> Failed to get handle of the Ichimoku indicator error =","  error = ",Ichimoku_handle,GetLastError());  //--- if the handle is not created
   if(!ChartIndicatorAdd(0,0,Ichimoku_handle)) 
     {PrintFormat("*****---> Failed to add Ichimoku indicator on %d chart window. Error code  %d",0,GetLastError());}
     
//------------------------------------------------------------------------------------------  PLOT Moving_Average  
   SetIndexBuffer(20,ExtMoving_AverageBuffer,INDICATOR_CALCULATIONS);
   ArraySetAsSeries(ExtMoving_AverageBuffer,true);
   Moving_Average_handle=iMA(NULL,InpPeriod_MA_TIMEFRAMES,InpMAPeriod,InpMAShift,InpMAMethod,InpAppliedPrice_MA);
   if(Moving_Average_handle==INVALID_HANDLE) Print("*****---> Failed to get handle of the Moving_Average indicator error =",GetLastError());
   if(!ChartIndicatorAdd(0,0,Moving_Average_handle)) 
      {PrintFormat("*****---> Failed to add Moving_Average indicator on %d chart window. Error code  %d",0,GetLastError());}   
.
.
        
  }
 .
.
.
//----------------------------------------------------------------------------------------------------------//
void OnDeinit(const int reason)
  {  
      Comment("");
            
      for(int j=0;j<ChartIndicatorsTotal(0,0);j++)
         {
          ChartIndicatorDelete(0,0,ChartIndicatorName(0,0,j));
         }
     
      ChartRedraw();
      ChartSetInteger(0,CHART_FOREGROUND,foreground);
     
  }
//----------------------------------------------------------------------------------------------------------//

thanks to reply

 
TIMisthebest:

sory i forget to paste ,  they are :

thanks to reply

Probably because these indicators are already on your chart.
 
angevoyageur:
Probably because these indicators are already on your chart.

no , there is not any other indicator on that chart.

on other chart ; yes i have them.

i will paste full mql5 file here .

thank you .

 

i add this;

my indicator is in seperate window and i use the buffer's of " Ichimoku & Moving average " in that seperate window ,

and i also want to have them  { " Ichimoku & Moving average "  } in that main chart.

is this may be the reson ?

 

hi alain

here is the code, and i attached mql5 file.

the same error code when change time frame or recompiling the file, and alternate for " Ichimoku or Moving average"

and also when delete the indicator from chart , in each time one of them dont delete alternatively.

can you please check it?

thank you.

//+------------------------------------------------------------------+                                         
//|                     Copyright © 2014, BY Mehrdad Shiri           |
//|                                              m100shiri@yahoo.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2014, BY MEHRDAD SHIRI"
#property version   "1.00"

//+------------------------------------------------------------------+
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 6
#property indicator_plots   1
#property indicator_level1 0
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+-----------------------------------+
//|  INDICATOR INPUT PARAMETERS       |
//+-----------------------------------+
//------------------------------------------------------------------------------------------ Ichimoku
input int tenkan_sen=9;              // period of Tenkan-sen
input int kijun_sen=26;              // period of Kijun-sen
input int senkou_span_b=52;          // period of Senkou Span B
double         Tenkan_sen[];
double         Kijun_sen[];
double         Senkou_Span_A[];
double         Senkou_Span_B[];
double         Chinkou_Span[];
int    Ichimoku_handle;              //--- variable for storing the handle of the iIchimoku indicator
//------------------------------------------------------------------------------------------ Moving_Average
double ExtMoving_AverageBuffer[];
int   Moving_Average_handle;
input ENUM_TIMEFRAMES    InpPeriod_MA_TIMEFRAMES=PERIOD_CURRENT;        // timeframe
input int            InpMAPeriod=50;         // Period
input int            InpMAShift=0;           // Shift
input ENUM_MA_METHOD InpMAMethod=MODE_SMA;  // Method
input ENUM_APPLIED_PRICE InpAppliedPrice_MA=PRICE_CLOSE;   // Applied price
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
bool foreground;
string short_name;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {     
//------------------------------------------------------------------------------------------ Ichimoku
   SetIndexBuffer(0,Tenkan_sen,INDICATOR_CALCULATIONS);    ArraySetAsSeries(Tenkan_sen,true);
   SetIndexBuffer(1,Kijun_sen,INDICATOR_CALCULATIONS);     ArraySetAsSeries(Kijun_sen,true);
   SetIndexBuffer(2,Senkou_Span_A,INDICATOR_CALCULATIONS); ArraySetAsSeries(Senkou_Span_A,true);
   SetIndexBuffer(3,Senkou_Span_B,INDICATOR_CALCULATIONS); ArraySetAsSeries(Senkou_Span_B,true);
   SetIndexBuffer(4,Chinkou_Span,INDICATOR_CALCULATIONS);  ArraySetAsSeries(Chinkou_Span,true);
            
   Ichimoku_handle=iIchimoku(NULL,0,tenkan_sen,kijun_sen,senkou_span_b);
   if(Ichimoku_handle==INVALID_HANDLE) Print("*****---> Failed to get handle of the Ichimoku indicator error =","  error = ",Ichimoku_handle,GetLastError());  //--- if the handle is not created
   if(!ChartIndicatorAdd(0,0,Ichimoku_handle)) 
     {PrintFormat("*****---> Failed to add Ichimoku indicator on %d chart window. Error code  %d",0,GetLastError());}
//------------------------------------------------------------------------------------------  PLOT Moving_Average  
   SetIndexBuffer(5,ExtMoving_AverageBuffer,INDICATOR_CALCULATIONS);
   ArraySetAsSeries(ExtMoving_AverageBuffer,true);
   Moving_Average_handle=iMA(NULL,InpPeriod_MA_TIMEFRAMES,InpMAPeriod,InpMAShift,InpMAMethod,InpAppliedPrice_MA);
   if(Moving_Average_handle==INVALID_HANDLE) Print("*****---> Failed to get handle of the Moving_Average indicator error =",GetLastError());
   if(!ChartIndicatorAdd(0,0,Moving_Average_handle)) 
      {PrintFormat("*****---> Failed to add Moving_Average indicator on %d chart window. Error code  %d",0,GetLastError());}
//----------------------------------------------------------------------------------------------------------//
//*************************************************************************   
   foreground=ChartGetInteger(0,CHART_FOREGROUND);
   ChartSetInteger(0,CHART_FOREGROUND,false);  
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits + 1);
   short_name="ShiriMoko";
   IndicatorSetString(INDICATOR_SHORTNAME,short_name);
//*************************************************************************   
//--- initialization done
  }
//+------------------------------------------------------------------+
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     &TickVolume[],
                const long     &Volume[],
                const int      &Spread[])
{
   if (!ArrayGetAsSeries(Close)) ArraySetAsSeries(Close,true);
   if (!ArrayGetAsSeries(Time))  ArraySetAsSeries(Time,true);
   if (!ArrayGetAsSeries(High))  ArraySetAsSeries(High,true);
   if (!ArrayGetAsSeries(Low))   ArraySetAsSeries(Low,true);
   int to_copy;
//------------------------------------------------------------------------------------------ Ichimoku
   if (!checkCalculated(Ichimoku_handle,rates_total,"Ichimoku_handle")) return(0);
   if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
      else {to_copy=rates_total-prev_calculated; if(prev_calculated>0) to_copy++;}
   if (!doCopy(Ichimoku_handle,0,0,to_copy,Tenkan_sen,"Tenkan_sen buffer")) return(0);
   if (!doCopy(Ichimoku_handle,1,0,to_copy,Kijun_sen,"Kijun_sen buffer"   )) return(0);
   if (!doCopy(Ichimoku_handle,2,-kijun_sen,to_copy,Senkou_Span_A,"Senkou_Span_A buffer"   )) return(0);
   if (!doCopy(Ichimoku_handle,3,-kijun_sen,to_copy,Senkou_Span_B,"Senkou_Span_B buffer"   )) return(0);
   if (!doCopy(Ichimoku_handle,4,0,to_copy,Chinkou_Span,"Chinkou_Span buffer"   )) return(0);
//------------------------------------------------------------------------------------------ Moving_Average
   if (!checkCalculated(Moving_Average_handle,rates_total,"Moving_Average")) return(0); 
   if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
      else {to_copy=rates_total-prev_calculated; if(prev_calculated>0) to_copy++;}
   if (!doCopy(Moving_Average_handle,0,0,to_copy,ExtMoving_AverageBuffer,"Moving_Average buffer")) return(0);
//----------------------------------------------------------------------------------------------------------//
 
   Comment(""
           ,"Moving_Average[0]=",ExtMoving_AverageBuffer[0]
           ,"\nMoving_Average[1]=",ExtMoving_AverageBuffer[1]
           ,"\n Tenkan_sen[0]=",Tenkan_sen[0]
           ,"\n Kijun_sen[0]=",Kijun_sen[0]
           ,"\n Senkou_Span_A[0]=",Senkou_Span_A[0]
           ,"\n Senkou_Span_B[0]=",Senkou_Span_B[0]
          );
//----------------------------------------------------------------------------------------------------------//         
//--- done
   return(rates_total);
}
//----------------------------------------------------------------------------------------------------------//
void OnDeinit(const int reason)
  {
      Comment("");
      for(int j=ObjectsTotal(0)-1;j>=0;j--)
         {
          if(StringFind(ObjectName(0,j),"SM")!=-1)
          if(!ObjectDelete(0,ObjectName(0,j)))
             Print("*****---> Error in deleting object (",GetLastError(),")");
         }
      for(int j=0;j<ChartIndicatorsTotal(0,0);j++)
         {
          ChartIndicatorDelete(0,0,ChartIndicatorName(0,0,j));
         }
         
      ChartRedraw();
      ChartSetInteger(0,CHART_FOREGROUND,foreground);
  }
//----------------------------------------------------------------------------------------------------------//
bool checkCalculated(int bufferHandle, int total, string checkDescription)
    {
     int calculated=BarsCalculated(bufferHandle);
     if (calculated<total)
        {
         Print("Not all data of "+checkDescription+" is calculated (",calculated,"bars ). Error",GetLastError());
         return(false);
        }
     return(true);
    }
//---
bool doCopy(int bufferHandle, int buffer_number, int start_position, int copyCount, double& buffer[], string copyDescription)
    {
     if(CopyBuffer(bufferHandle,buffer_number,start_position,copyCount,buffer)<=0)
       {
        Print("Getting "+copyDescription+" failed! Error",GetLastError());
        return(false);
       }
     return(true);
    }
//----------------------------------------------------------------------------------------------------------//
       
Files:
Sz.mq5  10 kb
 
TIMisthebest:

hi alain

here is the code, and i attached mql5 file.

the same error code when change time frame or recompiling the file, and alternate for " Ichimoku or Moving average"

and also when delete the indicator from chart , in each time one of them dont delete alternatively.

can you please check it?

thank you.

If I take a new fresh chart and place your indicator, it's working without any error.

But I recompile your indicator or if I change timeframe for example, while it is still displayed on the chart, I get this error :

2014.09.08 12:05:24.663    36008 (EURUSD,M15)    *****---> Failed to add Moving_Average indicator on 0 chart window. Error code  4114

It's because the moving average indicator remains on chart after your DeInit(). So

The problems comes from the loop you are using to remove the indicator in DeInit(), you need to count down :

      for(int j=ChartIndicatorsTotal(0,0)-1;j>=0;j--)
         {
            string iname=ChartIndicatorName(0,0,j);
          if(!ChartIndicatorDelete(0,0,iname))
            printf("Error(%i) while deleting indicator %s from chart",GetLastError(),iname);
         }


 
angevoyageur:

If I take a new fresh chart and place your indicator, it's working without any error.

But I recompile your indicator or if I change timeframe for example, while it is still displayed on the chart, I get this error :

2014.09.08 12:05:24.663    36008 (EURUSD,M15)    *****---> Failed to add Moving_Average indicator on 0 chart window. Error code  4114

It's because the moving average indicator remains on chart after your DeInit(). So

The problems comes from the loop you are using to remove the indicator in DeInit(), you need to count down :


thank you so much.
Reason: