iCustom buffer request does not match indicator buffer

 

In the attached file "5MinutesScalping-i4.mq4" you'll find the source code of an indicator I downloaded. It has 2 buffers (buffer 0 and 1) which provide buy/sell signals.


Now I want to create my own custom indicator (attached file "Onno - Indicator.mq4") that uses the attached indicator by calling iCustom with either buffer 0 or buffer 1.

This always returns the value EMPTY_VALUE, even though the indicator (when attached to a chart) has some valid value.

Now, when I call iCustom with either buffer 2 or 3, it does give me the correct values. How is this possible? Is it something I overlooked, is it some peculiarity I am not aware of, or is it an "undocumented feature"?


Thanks for looking into it.

 
Onno Rijkers:

In the attached file "5MinutesScalping-i4.mq4" you'll find the source code of an indicator I downloaded. It has 2 buffers (buffer 0 and 1) which provide buy/sell signals.


Now I want to create my own custom indicator (attached file "Onno - Indicator.mq4") that uses the attached indicator by calling iCustom with either buffer 0 or buffer 1.

This always returns the value EMPTY_VALUE, even though the indicator (when attached to a chart) has some valid value.

Now, when I call iCustom with either buffer 2 or 3, it does give me the correct values. How is this possible? Is it something I overlooked, is it some peculiarity I am not aware of, or is it an "undocumented feature"?


Thanks for looking into it.


verify all of your parameters in iCustom()
It seems to have one too many.
======
extern int    ATRperiod=14;
extern bool   AlertMode=true;
extern bool   ControlChart_EURUSD_M5=true;

 
Soewono Effendi:

verify all of your parameters in iCustom()
It seems to have one too many.
======

I don't see how it has one too many?


The call: iCustom(Symbol(), PERIOD_CURRENT, "::Indicators\\5MinutesScalping-i4.ex4", 14, false, false, 2, shift);

param 1 = symbol

param2 = period

param3 = indicator name

param4 = ATRperiod (= 14)

param5 = AlertMode (= false)

param6 = ControlChart_EURUSD_M5 (= false)

param7 = buffer (= 2)

param8 = shift


param 4 - 6 are the 3 indicator parameters, the others are iCustom parameters.

 

the easiest way to test, is to create another indicator that plots these buffers.

 
Onno Rijkers:

In the attached file "5MinutesScalping-i4.mq4" you'll find the source code of an indicator I downloaded. It has 2 buffers (buffer 0 and 1) which provide buy/sell signals.

Now I want to create my own custom indicator (attached file "Onno - Indicator.mq4") that uses the attached indicator by calling iCustom with either buffer 0 or buffer 1.

This always returns the value EMPTY_VALUE, even though the indicator (when attached to a chart) has some valid value.

Now, when I call iCustom with either buffer 2 or 3, it does give me the correct values. How is this possible? Is it something I overlooked, is it some peculiarity I am not aware of, or is it an "undocumented feature"?

Thanks for looking into it.

In your 5MinutesScalping-i4.mq4, these few lines are problematic (first run, straightaway return -1, subsequent runs re-calculate almost all the bars repeatedly slowing - wasting cpu resources), and they are the primary reason why your iCustom can't get any value):

   ExtCountedBars=IndicatorCounted()-2;
   if(ExtCountedBars>Bars-2) ExtCountedBars=Bars-2;
   if(ExtCountedBars<0) return(-1);
   if(ExtCountedBars>0) ExtCountedBars--;
   Limit=ExtCountedBars;

Replace them with this line instead and see what happens:

Limit = MathMin(rates_total-3,rates_total-prev_calculated);
Reason: