iCustom in metatrader5

 

iCustom(symbol,0,"indicator") works only as the symbol matches the symbol of the chart.

In all other cases it returns 0;

Where can I find the solution??

 

bertpost: In all other cases it returns 0;

Did you enable symbol in Market Watch?

 

Please explain in more detail and provide example code as well log output demonstrating your issue.

In MQL5, iCustom returns a handle, so it should not be returning a value of 0. At most it should return a value of -1 ( INVALID_HANDLE ) when it fails.

To obtain the Indicator's buffer data, you should use CopyBuffer.

You may also want to read the following which is related ... Organizing Data Access

I have moved your topic to the section: Technical Indicators

 
Here is a simple example that might help:

int G_Handle;

string G_IndicatorName = "Your_Indicator"; // Path to your indicator
string G_Symbol = "EURCHF";

int OnInit()
  {

   G_Handle     = iCustom(G_Symbol, PERIOD_H1, G_IndicatorName);

   return(INIT_SUCCEEDED);
  }


void OnTick()
  {
  
   double Val[];
   
   if(CopyBuffer(G_Handle, 0, 1, 1, Val) <= 0) 
      return;
   
   Comment(Val[0]);
   
  }
 
Fernando Carreiro #:

Please explain in more detail and provide example code as well log output demonstrating your issue.

In MQL5, iCustom returns a handle, so it should not be returning a value of 0. At most it should return a value of -1 ( INVALID_HANDLE ) when it fails.

To obtain the Indicator's buffer data, you should use CopyBuffer.

You may also want to read the following which is related ... Organizing Data Access

I have moved your topic to the section: Technical Indicators

3 windows open gbpjpy, eurjpy and usdjpy with this indicator.

And on all 3 only the corresponding returns the value.

To try you can take any other custom indicator with return of the 0 and 1 buffer.

I hope this is enough to see my problem.

Files:
 
bertpost #: 3 windows open gbpjpy, eurjpy and usdjpy with this indicator. And on all 3 only the corresponding returns the value. To try you can take any other custom indicator with return of the 0 and 1 buffer.

You are not verifying the return count from CopyBuffer nor are you checking for any error conditions.

It is also best not to read the external indicator repeatedly for the entire rates array range on every call, as this will make it slow and resource intensive.

It is inefficient. Instead, read the other indicator's buffer data incrementally based on the "prev_calculated" variable.

bertpost #: I hope this is enough to see my problem.

Unfortunately not. Your code referes to an external closed source indicator, so we are are unable to test and run your code to try reproduce the issue.

We also have no way of knowing if there are bugs in the external indicator either.

Build in more debugging prints into your code to monitor it or use the built-in debugger in MetaEditor to debug your code.

 
Fernando Carreiro #:

You are not verifying the return count from CopyBuffer nor are you checking for any error conditions.

It is also best not to read the external indicator repeatedly for the entire rates array range on every call, as this will make it slow and resource intensive.

It is inefficient. Instead, read the other indicator's buffer data incrementally based on the "prev_calculated" variable.

Unfortunately not. Your code referes to an external closed source indicator, so we are are unable to test and run your code to try reproduce the issue.

We also have no way of knowing if there are bugs in the external indicator either.

Build in more debugging prints into your code to monitor it or use the built-in debugger in MetaEditor to debug your code.

Fernando,

OK. I tried the same with the Envelopes indicator with iCustom. And that was ok.

So the problem must be in the MyReversal indicator. I cannot find why. That's why I attached the source. Maybe you see the problem.

Bert

Files:
 
bertpost #: Fernando, OK. I tried the same with the Envelopes indicator with iCustom. And that was ok. So the problem must be in the MyReversal indicator. I cannot find why. That's why I attached the source. Maybe you see the problem. Bert

We are not here to debug your code for you, only to offer advice on specific issues you may be having.

To debug your code and figure out what may be causing the problem, either ...

  • ... add extra "print()" calls to your code so that you can monitor it via the Experts log, or ...
  • ... use the built-in debugger in MetaEditor.