
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
Exactly. (was writing previous post while you posted this).
Okay, another go... avoiding any unnecessary re-calculation of MA values; any unnecessary use of iBarShift(); and watching for MT4 asynchronously back-filling on start-up with intermediate history data since it was last run.
This is more complicated that I'd probably actually use myself. I'd sacrifice some unnecessary re-calculation of static MA values (which MT4 probably caches itself) in favour of code simplicity and cleanliness. And even despite that, it feels more complex than it needs to be; I blame last night's alcohol.
Okay, another go... avoiding any unnecessary re-calculation of MA values; any unnecessary use of iBarShift(); and watching for MT4 asynchronously back-filling on start-up with intermediate history data since it was last run.
This is more complicated that I'd probably actually use myself. I'd sacrifice some unnecessary re-calculation of static MA values (which MT4 probably caches itself) in favour of code simplicity and cleanliness. And even despite that, it feels more complex than it needs to be; I blame last night's alcohol.
Thanks guys appreciate the help, I have been trying to keep up and researching the functions your using, as I said still fairly new to this.
Sorry if my description was a bit vague, but yes my aim was to identify the two crosses happening within a certain number of bars to each other.
Thanks guys appreciate the help, I have been trying to keep up and researching the functions your using, as I said still fairly new to this.
Sorry if my description was a bit vague, but yes my aim was to identify the two crosses happening within a certain number of bars to each other.
Going back to my very first response, the complexity of the code depends whether you want to maximise speed and avoid things like unnecessary recalculation of historic MA values which can't change. This will have minimal or zero impact in live use, but will affect the speed of backtesting, if that's what you want to do with the code.
The most recent stuff above could be very much simpler (and easier to read) if it weren't attempting to avoid any unnecessary operation.
But the various code above does illustrate various ways of determining when the most recent MA cross happened. You then add in something similar for the stochastic, and only take action if both events lie within a certain number of bars; are in the same direction etc.
Going back to my very first response, the complexity of the code depends whether you want to maximise speed and avoid things like unnecessary recalculation of historic MA values which can't change. [...]
[ ** completely untested; treat only as an example ... ** ]
For example, the following code handles both the MA cross and the stochastic cross, and is much cleaner in terms of tidy subdivision into functions. But it's much less optimised than the code above, and repeatedly recalculates values which can't have changed (though MT4 may itself cache these, with the result that the difference might be minimal).
Going back to my very first response, the complexity of the code depends whether you want to maximise speed and avoid things like unnecessary recalculation of historic MA values which can't change. This will have minimal or zero impact in live use, but will affect the speed of backtesting, if that's what you want to do with the code.
The most recent stuff above could be very much simpler (and easier to read) if it weren't attempting to avoid any unnecessary operation.
But the various code above does illustrate various ways of determining when the most recent MA cross happened. You then add in something similar for the stochastic, and only take action if both events lie within a certain number of bars; are in the same direction etc.
Yes it is my intention to maximise speed and avoid unnecessary re-calculation, which is why I first thought storing signals in an array was the most efficient. But I was wary of continually adding to an array with an infinite size thinking it would slow the program down eventually if I leave it running continually.
Thanks for the examples above you are giving me plenty of homework to go through which is great.
Yes it is my intention to maximise speed and avoid unnecessary re-calculation [...]
Again going back to my initial response, it also depends whether (a) you want to look at interim indicator/cross values on each tick during the current bar (which can then change back/un-cross again later in the bar), or only (b) to evaluate signals when a bar closes.
The various example code above does (a). If you only want to do (b), and will therefore only be calculating MA and stochastic values once per bar, then the benefit of caching/optimisation such as the #11 example is going to be absolutely tiny compared to the simpler #15 example, even in backtesting.
I have found the above thread while looking for some help. I would like to be able to compare the last two moving average cross prices (slow MA).
How would I be able to change the methods shown in this thread to be able to do this?
The methods seem to only get the last MA cross. How would you create an array to store the last two crosses that could then be read and used to get the proce data from to then compare?
Any help would be appreciated.