Download MetaTrader 5

Call Indicator from an expert

To add comments, please log in or register
HongDi s& t development co.,ltd.
1603
hongbin fei  

Loading:
  ResetLastError();
   R_H4_Handle=iCustom(NULL,PERIOD_H4,"rindicator", false, 600,  true, PRICE_CLOSE  );
   if(R_H4_Handle==INVALID_HANDLE)
     {
      Print("R_H4_Handle = ",R_H4_Handle,"  error = ",GetLastError());
      return(false);
     }
      else
      Print("R_H4_Handle = ",R_H4_Handle,"load success");
     

   if (ChartIndicatorAdd(0,0,R_H4_Handle))
        Print("R_H4_Handle = ",R_H4_Handle,"attached success");
   
 
   
      ResetLastError();
     R_H1_Handle=iCustom(NULL,PERIOD_H1,"rindicator", false, 600,  true, PRICE_CLOSE  );
   if(R_H1_Handle==INVALID_HANDLE)
     {
      Print("R_H1_Handle = ",R_H1_Handle,"  error = ",GetLastError());
      return(false);
     }
     else
      Print("R_H1_Handle = ",R_H1_Handle,"load success");

 
    if (ChartIndicatorAdd(0,0,R_H1_Handle))
        Print("R_H1_Handle = ",R_H1_Handle,"attached success");

 

release:

 

void Robot::~Robot(void)
  {

   
   
   if (R_H1_Handle!= INVALID_HANDLE)
   ChartIndicatorDelete(0,0,"rindicator");
   if (R_H4_Handle!= INVALID_HANDLE)
   ChartIndicatorDelete(0,0,"rindicator");
}

 I run robot, there are message " rindicator  load success ",  the message"attached success" is not shown, maybe ChartIndicatorAdd return false,

if the indicator list, there are 1 indicator (rindicator) appeared.

Who can help me? thanks! 

 

Documentation on MQL5: Chart Operations / ChartIndicatorAdd
  • www.mql5.com
Chart Operations / ChartIndicatorAdd - Documentation on MQL5
HongDi s& t development co.,ltd.
1603
hongbin fei  

ERR_CHART_INDICATOR_CANNOT_ADD

4114

Error adding an indicator to chart

I found this error, how to slove? 

 

Slava
Moderator
6971
Slava  

What is period of chart your EA attached to?

If indicator period is H4 but chart period is not H4 then you get error

Documentation on MQL5: Standard Constants, Enumerations and Structures / Chart Constants / Chart Timeframes
  • www.mql5.com
Standard Constants, Enumerations and Structures / Chart Constants / Chart Timeframes - Documentation on MQL5
HongDi s& t development co.,ltd.
1603
hongbin fei  

it is run on H1 chart, but I can know the 2 indicators are running. in the indicator list window, there are only 1 indicator (rindicator) appeared. maybe the short name same?

Slava
Moderator
6971
Slava  

You should be sure that indicator to be added and chart must have the same symbol-period!

I see your code

   R_H4_Handle=iCustom(NULL,PERIOD_H4,"rindicator", false, 600,  true, PRICE_CLOSE  );
...
   if (ChartIndicatorAdd(0,0,R_H4_Handle))
      Print("R_H4_Handle = ",R_H4_Handle,"attached success");

 You added indicator to the current chart. Indicator created on the period H4. If period of current chart (EA attached to) differs from H4 (you say about H1) then you get error. Any questions?

 

HongDi s& t development co.,ltd.
1603
hongbin fei  
stringo:

You should be sure that indicator to be added and chart must have the same symbol-period!

I see your code

 You added indicator to the current chart. Indicator created on the period H4. If period of current chart (EA attached to) differs from H4 (you say about H1) then you get error. Any questions?

 

but the indicator with H4, it is running normally, even I donot get correct result with ChartIndicatorAdd.
Documentation on MQL5: Chart Operations / ChartIndicatorAdd
  • www.mql5.com
Chart Operations / ChartIndicatorAdd - Documentation on MQL5
Slava
Moderator
6971
Slava  

do not mix indicator calculating and indicator adding to chart.

You can create any indicator in the EA. Created indicator can be added to the chart with the same symbol-period only 

To add comments, please log in or register