Hello,
I am writing a function to get 10 RSI values from copybuffer, how do return the function as an array/pointer?
thank you
Your function contains a gross error: in MQL5, the indicator handle MUST BE CREATED ONCE! You need to do this in OnInit.
Correct your code, then I can tell you further ...

- 2020.07.05
- www.mql5.com
-
Handle = iRSI (Symbol(), Period(), RSI _Period, RSI I_Apply); CopyBuffer(Handle, 0, Position, 10, Values);
Perhaps you should read the manual, especially the examples.
They all (including iCustom) return a handle (an int.) You get that in OnInit. In OnTick (after the indicator has updated its buffers,) you use the handle, shift and count to get the data.
How To Ask Questions The Smart Way. 2004
How To Interpret Answers.
RTFM and STFW: How To Tell You've Seriously Screwed Up.
Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 2020.03.08
How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 2020.07.05
How to call indicators in MQL5 - MQL5 Articles 12 March 2010 -
double Values; CopyBuffer(Handle, 0, Position, 10, Values);
CopyXXXX requires an array; don't post code that will not even compile. Perhaps you should read the manual. -
double RSI[] ( …
As the documentation clearly says "With the return operator you can't return any arrays, class objects, variables of compound structure type." Perhaps you should read the manual.
You can pass an array into a function by (non-constant) reference, which allows the function to modify the caller's array.
Hello, I am trying to create an RSI indicator of 7 currencies but seems to have issue with the array in first position CopyBuffer (native functiomn)...
ArrayInitialize(iTsi, EMPTY_VALUE); for(x = 0; x < 28; x++) if(StringSubstr(symbols[x], 0, 3) == "USD"|| StringSubstr(symbols[x], 3, 3) == "USD") { int ii = iBarShift(symbols[x], tf, iTime(_Symbol, tf, _i), true); if(ii == -1) continue; if(!getCopyBuffer(TSI[x], MAIN_LINE, ii, 1, iTsi)) return DBL_MIN; count++; if(iTsi[0] != EMPTY_VALUE) if(StringSubstr(symbols[x], 0, 3) == "USD") res += iTsi[0]; else if(StringSubstr(symbols[x], 3, 3) == "USD") res -= iTsi[0]; } return res / count;

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I am writing a function to get 10 RSI values from copybuffer, how do return the function as an array/pointer?
thank you