These 2 functions need to be moved outside OnCalculate(). You can't declare a function inside an other function.
//Main program int OnCalculate(...) { ... } //Custom range function 1 int RangeStart(int CurrentBarVal) { return (CurrentBarVal-CurrentBarVal); } //Custom range function 2 int BarsInRange(int HighVal,int LowVal) { return (HighVal-LowVal); }
Alain, you're a wonderful, wonderful man. That simple fact had sailed straight past me. Thank you very much. :)
Carl.
Just as a suggestion - try not to mix the use of the parameter arrays (open[], high[], etc.) with the old style Chart data arrays (Open[], High[], etc.).
Instead of the iHighest() and iLowest() which works on the Chart Data arrays, rather use ArrayMaximum() and ArrayMinimum() on the high[] and low[] arrays which are the parameters of the function.
This will surely prevent any future inconsistencies (as there may be differences between the data sources) and make your OnCalculate() portable.
Quick question: am i right in thinking that iLowest/Highest has the benefit, over ArrayMaximum/Minimum, of being able to pull data from other timeframes? I'm working towards making this a multi-timeframe EA.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Good morning all. Totally though i'd gotten the hang of it then started receiving the following issue...
1. Just for general awareness: I've elected for the current bar to be the value of IndicatorCounted () - and consistently refer to this as "i" - therefore, the oldest bar on the chart is always [0] - right or wrong i found it easier to understand this way
2. I've written two functions (highlighted in pink) which i'm having issues placing within the body of my code; wherever i choose to place text i receive the error message "function can be declared only in the global scope"
Can anyone suggest where i'm going wrong, please?
Any and all help, as always, is very much appreciated.
Thanks,
Carl.