Ok, here is the thing. Very simple but maybe I dont understand the concept of copybuffer in mql5 (I am new to it).
Well, I understand that after you define a handle in OnInit(), and then you use the CopyBuffer() method, you copy elements from the first array to the second.
However in my code that doesnt work because it copies only one element .
In the following code I just want to copy the ATR values from the second and the third candle to my "atrA" array, that is it. It only copies the one from the 2nd candle and the EA crashes. And
as it fails it triggers the "CopyBuffer from atr1 failed, no data" message.
I know maybe this is so simple but really dont understand what happens. Thanks in advance.
Hi spazioalto,
Actually in your case, there's only a typo problem. Here's your code,
if(CopyBuffer(atrH,0,1,2,atrA)!=1) { Print("CopyBuffer from atr1 failed, no data"); return; }
Please read the funny manual, CopyBuffer() return the number of copied data. You tried to copy 2 data but set "if it's not 1" then it's an error. What you should do is this
ResetLastError(); if(CopyBuffer(atrH,0,1,2,atrA)!= 2) { Print("CopyBuffer from atr1 failed, no data",GetLastError()); return; } else { Print("CopyBuffer success"); }
If you sure there's an err, do use ResetLastError() and GetLastError().
You should see my MetaEditor, it's always show error and warning all the time, never no error no warning - LOL.
:D
Please do not forget to check amount of calculated values(using BarsCalculated function) before you copy any data from buffer.
- www.mql5.com
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Ok, here is the thing. Very simple but maybe I dont understand the concept of copybuffer in mql5 (I am new to it).
Well, I understand that after you define a handle in OnInit(), and then you use the CopyBuffer() method, you copy elements from the first array to the second.
However in my code that doesnt work because it copies only one element .
In the following code I just want to copy the ATR values from the second and the third candle to my "atrA" array, that is it. It only copies the one from the 2nd candle and the EA crashes. And
as it fails it triggers the "CopyBuffer from atr1 failed, no data" message.
I know maybe this is so simple but really dont understand what happens. Thanks in advance.