MQL4: Calls from EA to Currency Strength Ind return wrong values

 

I have [written] a quite simple currency strength indicator (for CAD), it just uses the average of the close price of all seven CAD crosses.  Then, since that line is quite jagged, I added a moving average to smooth it out.  When I call it from an EA with iCustom, it get 'similar' values, but not the exact values shown in the Data window.  So far I'm s tumped as to why.  Can anyone enlighten me?

The ind code is attached, and I am calling it like this:

value = iCustom(NULL, 0, "PowerOfCAD", 34, 0, MODE_EMA, 0, 1, sh);

...where sh = 1 & 2, so calling for closed candle and next one back.  The value returned is sometimes exactly correct, most of the time just pretty close.  Any help appreciated.

I was trying to use the MaxBars parameter (the zero after MODE_EMA) for a while, but then it gives even worse values.  But when I send zero, I get warnings on the experts tab like this:

2023.12.19 04:05:07.317 PowerOfCAD CADJPY,M5: indicator is too slow, 2484 ms. rewrite the indicator, please
Improperly formatted code edited by moderator.
Moving Average - Trend Indicators - Technical Indicators - Price Charts, Technical and Fundamental Analysis - MetaTrader 5 Help
  • www.metatrader5.com
The Moving Average Technical Indicator shows the mean instrument price value for a certain period of time. When one calculates the moving average...
Files:
 

Please, always use the CODE button (Alt-S) when inserting code.

Code button in editor

 
Derk Wehler: I was trying to use the MaxBars parameter (the zero after MODE_EMA) for a while, but then it gives even worse values.  But when I send zero, I get warnings on the experts tab like this:

Zero means all bars. Use something non-zero like 3*length.

 
Fernando Carreiro #:

Please, always use the CODE button (Alt-S) when inserting code.

Thanks, I had a hard time finding that

 
William Roeder #:

Zero means all bars. Use something non-zero like 3*length.

Yes, zero means all bars. So I tried a smaller number (like twice the MA period) and the return values were even worse (compared to value in data window) than when I send zero.

I'm not clear exactly what happens when you do an iCustom call.  When I ask for index 1, but it's a buffer of a MA of the main (index zero) value, how does it have enough values to run the iMAOnArray?

If anyone knows of any in-depth articles that describe exactly how MT4 deals with this, please send a link.  Thanks.

Reason: