![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
.
So anyhow, I was trying to make the high fractals only form when another condition occurs such as iMACD crosses, or EMA crosses or some other indicator crosses.
So that the fractals will only show on the indicator when all the conditions are met.
i wasnt sure exactly what your trying to do but try this, notice the external inputs.
Exactly how did you come to that conclusion and what is the functional difference?
I came to that conclusion, because likely, i was looking at from OOP perspectives. yes, this is not true for the case of MQL4, I recall now. Though it can be good practice?
Or maybe something like this ?
you really ought to use IndicatorCounted() though, because if you do it like this your indicator is redrawing all those objects at every new tick instead of drawing all them just one time and adding new ones as new bars are formed
I came to that conclusion, because likely, i was looking at from OOP perspectives. yes, this is not true for the case of MQL4, I recall now. Though it can be good practice?
It's always good practice to limit scope. it's always good practice to define variable/object where used and to initialize them at that point.
Defining an object outside the loop results in a default construction plus N assignments. Defined inside the loop results in N constructions with value - usually quicker.
Never worry about optimizations until you can prove the change makes a difference.
It's always good practice to limit scope. it's always good practice to define variable/object where used and to initialize them at that point.
Defining an object outside the loop results in a default construction plus N assignments. Defined inside the loop results in N constructions with value - usually quicker.
Never worry about optimizations until you can prove the change makes a difference.
This should apply to its iterator as well. for (int i=0;...
Although, I am slightly confused as to why the declaring of the variables (faster and slower) outside the loop is no good while it's ok inside the loop
And yet the int i = Bars will works outside the loop or inside the loop ?
Anyhow good to see that some of my ideas I was working on are already posted in this thread so this is good news and means I'm getting a little closer to being able to code something on my own someday. So a little progress is better then non. Thanks
So now I can work on comparing some of the indicator times, I'll try to figure this out now.
Such as:
Compare v1[i] to v2[i] Currently formed indicator Times && / || if(v1[i] time is > v2[i] time) and other comparisons like this.
Thanks for all the tips everyone this has been a great help.
It's always good practice to limit scope. it's always good practice to define variable/object where used and to initialize them at that point.
Defining an object outside the loop results in a default construction plus N assignments. Defined inside the loop results in N constructions with value - usually quicker.
Never worry about optimizations until you can prove the change makes a difference.
Ok, I seem to have some variations of a working code now thanks.
Although, I am slightly confused as to why the declaring of the variables (faster and slower) outside the loop is no good while it's ok inside the loop
And yet the int i = Bars will works outside the loop or inside the loop ?
You have to consider what it is you are doing, when you create an indicator you are applying your code to each and every bar on the chart, this means you need to get the macd indicator value as it was for each of those historical bars.
in your original code you did:
the last parameter 1 is the value of the macd as it was at Bar 1 of the chart, the bar previous to the current bar which is indexed as bar 0Obviously you do not want to use that single value of the macd in your conditional operator over the whole historical chart .
You need to index the macd to the same bar index as each bar so for instance at bar 500 you need this
that last parameter must change to match the bar number your indicator is applying its algorithms to.
this is why you need it inside the loop, so you can use the loop cycle iterator ( i ) for the last parameter therfore you get your macd value as it was for each bar of the historical chart.
i hope that helps to clear things up a little.
Try this change
And why is this better then for(int i = Bars ??
Please advise thanks