
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
Ahm... No.
Apples and Peaches... Haha
OK, let me try to explain the issue.
Lets say you have an array, close prices, given to you by a function, like OnCalculate().
Lets say you want to have an object that calculates the mean over the last 15 values. When instantiating this object, you cannot give reference to the array and make it store this reference. Because you cannot create reference-variables, except as paramter in functions, which loose focus on return.
This means, you cannot have a memory address pointer to point to an external array within the given object, and you are forced to pass the array every time to the object.
Therefore you cannot write such code as this:
Thats why it is neccessary to keep track of data internally, within the object itself.
Yes I see - my solution with this is simply to have a receiver array embedded in the object and use ArrayCopy() to select the values you need.
You then use the embedded array copy to process the data in the way you want - not difficult to do and quite common really
Alternatively pass the source array into a method of the object - it is call by ref anyway so you will be transacting directly on the source array
If you need a code example of what I am suggesting...
Output sample (random data):
2022.08.27 18:21:06.408 //--- Sum = 184190.00 Count=9.00 Mean = 20465.56 Max = 32233.00 Min = 1851.00
2022.08.27 18:21:06.408 Check ArrayMax[2] true = 32233.00
2022.08.27 18:21:06.408 Check ArrayMin[3] true = 1851.00
2022.08.27 18:21:06.408 29554.00000 17037.00000 32233.00000 1851.00000 22728.00000 31879.00000 25929.00000 6003.00000 16976.00000
And please note - this is just an example, not a finished version. But using this approach one could build a function which accepts a stream or set of numbers - the sum, count, mean, max, min could be retained so each time the same number of operations are executed.
Yes I see - my solution with this is simply to have a receiver array embedded in the object and use ArrayCopy() to select the values you need.
You then use the embedded array copy to process the data in the way you want - not difficult to do and quite common really
You are not the only who is tired... I gave you an explanation, it is pretty simple stuff but if you don't get it, so be it.
Alternatively pass the source array into a method of the object - it is call by ref anyway so you will be transacting directly on the source array
Anyway, if you say its not possible so be it, I'll keep finding ways to do the needful...
You are not the only who is tired... I gave you an explanation, it is pretty simple stuff but if you don't get it, so be it.
People! You are both going off on a "rabbit hole" tangent and loosing sight of the original question and the points the OP refers to. I have outlined them here:
The answer to all these points are just one (or two) ... a simple built-in function, as the OP requested ... "iMA()" or "iMAOnArray()".
People! You are both going off on a "rabbit hole" tangent and loosing sight of the original question and the points the OP refers to. I have outlined them here:
The answer to all these points are just one (or two) ... a simple built-in function, as the OP requested ... "iMA()" or "iMAOnArray()".
Amen to that...
I don't know better - I just find it puzzling why someone would write so much code for such simple tasks.
This is easy stuff, but as Fernando has pointed out, time to terminate this discussion
People! You are both going off on a "rabbit hole" tangent and loosing sight of the original question and the points the OP refers to. I have outlined them here:
The answer to all these points are just one (or two) ... a simple built-in function, as the OP requested ... "iMA()" or "iMAOnArray()".
Yes. Thannk you for getting this back on track.
In fact, my original post was to give a code example on what I have described as method to calculate the mean of a series. As by the given answeres, it seemed to me, it was not obvious to everyone what exactly I meant.
Maybe I should not have asked for feedback on it, but simply post the code and close the issue (for me).
I was motivated to write that code because it was asked in another thread as well, and given the fact, an example was asked for "find the average value of the Close price minus the Open prices over the past x number of bars", which is not easily possible with the built-in functions, I decided to give an example code to solve this request.
Also WIlliams code was not addressing this request directly, as any of the other answeres failed to do so.
Whatever, it took me about 20 Mins to write that piece of code and another maybe 20 mins to test, debug and refine it. - So all in all, its a contribution to the community, as it gets asked again over time.
Similar to the code around Tick-Value, which was really a hazzle and took me maybe 3 weeks to figure out in all details, although I havent shared that code in total, at least I could shed some light on the whole issue.
Sometimes I also mistakenly understand something wrong and it takes me a while to get away from what I believe.