Where is CopyBufferAsSeries() function ??
Sorry I left that out. Added it in.
I had the same problem in MT4. ArraySetAsSeries, is like a local variable, you can't set it in a function and have it effect the caller/callee.
#property strict #define test(a,b) PrintArrayMA(iMAOnArray(a, 0, 1, 0, MODE_SMA, 0),a,b) void PrintArrayMA(double b, const double& array[], bool t){ ArraySetAsSeries(array, t); double a[]; ArraySetAsSeries(a, true); ArrayCopy(a, array); double array_ma = iMAOnArray(array, 0, 1, 0, MODE_SMA, 0); double a_ma = iMAOnArray(a, 0, 1, 0, MODE_SMA, 0); PrintFormat("bef=%g array={%g,%g,%g} ave=%g a={%g,%g,%g} ave=%g", b, array[2], array[1], array[0], array_ma, a[2], a[1], a[0], a_ma); } void OnStart(){ double sa[]={1,2,3,4}; // not series test(sa,1); // bef=4 array={2,3,4} ave=4 a={2,3,4} ave=4 ns r to l/pass no diff/set breaks copy test(sa,0); // bef=4 array={3,2,1} ave=4 a={3,2,1} ave=1 passed array must be set correctly for copy. ArraySetAsSeries(sa,true); for(int i=0; i<4; ++i) sa[i]=i+1; test(sa,1); // bef=1 array={3,2,1} ave=1 a={3,2,1} ave=1 series=ok/pass no diff/ test(sa,0); // bef=1 array={2,3,4} ave=1 a={2,3,4} ave=4 passed array must be set correctly for copy. }
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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
Basically, it prints out proper values in the visual tester for Close2[], but nonsense values when run through the backtester.
Am I missing something?