#property indicator_buffers 2 if(!IndicatorBuffers(2)){Print("Error allocating memory");return INIT_FAILED;}
First you specify that you have two visible buffers. Then you specify that you have a total of two buffers. That second line is only necessary when you have extra buffers.int OnInit(){ : buf_1[i]=Close[i]; buf_2[i]=High[i];
Don't try to use any price or server related functions in OnInit (or on load,) as there may be no connection/chart yet:- Terminal starts.
- Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
- OnInit is called.
- For indicators OnCalculate is called with any existing history.
- Human may have to enter password, connection to server begins.
- New history is received, OnCalculate called again.
- New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent and prices are valid.
for(int i=Bars-2; i>=0; i--){
Don't recalculate all bars every tick.
Detailed explanation of iCustom - MQL4 and MetaTrader 4 - MQL4 programming forum
Great! Thank you very much. Now it works properly.
Algosupremacy:
can you show the correct working script
Great! Thank you very much. Now it works properly.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello all!
I open this topic because I have a problem in assigning values to buffers and I didn't find a solution.
Here is a summary of the code
It gives me no compiling error, but if I attach the indicator on a chart, the terminal gives me an array out of range error and inside the brackets it writes the line and the column of this point (red highlighted):
I tried to search in this forum other similar issues, but I didn't find anything.
I tried also to make some attempts using ArraySize(buf_1) to verify the size of the buffer (I'm not sure if it can be used ArraySize for this purpose) and it gives me always 0.