Jan-HarmZ63: transfer elements from one array to another but only if the values meet specific
criteria. (E.g. If the value is !=0).
Not compiled, not tested, just typed.
When in doubt, THINK!
template<typename T> int copyNonzero(T& to[], const T& from[], int iEnd=WHOLE_ARRAY, int iBeg=0){ if(iEnd == WHOLE_ARRAY) iEnd = ArraySize(from); int nTo=0; for(; iBeg < iEnd; ++iBeg) if(from[iBeg] != 0){ ArrayResize(to, nTo+1); to[nTo] = from[iBeg]; ++nTo; } return nTo; }Not compiled, not tested, just typed.
It's a lot easier to use dynamic collections for this kind of stuff.
#include <arrays/arraydouble.mqh> void OnStart() { int zz_handle = iCustom(NULL, PERIOD_H1, "Examples\\ZigZag", 20, 5, 3); CArrayDouble res_up, res_dn; double zz_up[], zz_dn[]; ArraySetAsSeries(zz_up, true); ArraySetAsSeries(zz_dn, true); int upsize = CopyBuffer(zz_handle, 1, 0, 1000, zz_up); int dnsize = CopyBuffer(zz_handle, 2, 0, 1000, zz_dn); upsize = fmin(upsize, dnsize); for (int i = 0; i < upsize; i++) { double u = zz_up[i]; double d = zz_dn[i]; if (u != 0.0) res_up.Add(u); if (d != 0.0) res_dn.Add(d); } Print(res_up[0], " ", res_up[1]); Print(res_dn[0], " ", res_dn[1]); }
nicholi shen:
It's a lot easier to use dynamic collections for this kind of stuff.
Thank you for this. I will look into dynamic collections. This makes sense to me.
I appreciate your response.
William Roeder:
Not compiled, not tested, just typed. Not compiled, not tested, just typed.
When in doubt, THINK!
Thank you for your response William. I appreciate it.
Its easier than I thought :-)
nicholi shen:
It's a lot easier to use dynamic collections for this kind of stuff.
Nice one. I'd recommend this approach.
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
Good day,
I am trying to transfer elements from one array to another but only if the values meet specific criteria. (E.g. If the value is !=0).
Can someone please point me in a direction of how to approach this. Below are some thought I had but I have no clue. Please keep in mind that I am NEW TO PROGRAMMING!!