Questions from Beginners MQL5 MT5 MetaTrader 5 - page 919
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
Your indicator calculation is from the beginning to the end (from the most recent historical data to the most recent current data). This is an indication of indexing as in timeseries. So the arrays must be indexed accordingly, which is what you have.
What's wrong with it?
It all works the same as my port in MQL5 from MQL4, but I see that the code is ugly because ofArraySetAsSeries(), that's why I asked
here are both codes
teach me how to write this indicator for MT5! - My code is not nice, full stop! )))
ZSZ don't remember how to write indicators for MT5, sat down and rewrote it in 40 minutes using Help, but the result ... imho, not so good ((!
Yes, everything works exactly as my port in MQL5 from MQL4, but I see that the code is ugly because ofArraySetAsSeries(), so I asked
here are both codes
teach me how to write this indicator for MT5! - My code is not nice, full stop! )))
When you reverse the loop, you must necessarily make the arrays timeseries, otherwise the indexing of buffers in the loop will not coincide with the indexing of required data - the loop index in the array of indicator buffers will go from the beginning to the end, while in open[], high[], low[], close[] and others - from end to beginning. Or, you can reverse the loop to match its indexing of arrays open[], high[], low[], close[] and the rest with indexing of buffers, which is more complicated.
If you want an allegory to make it clearer, here's an allegory for you:
You're standing at the railroad tracks and looking at two trains. They either go in one direction - both from left to right (ArraySetAsSeries(array,true) - first train and a loop from limit to 0 - second train),
Or they go towards each other - (ArraySetAsSeries(array,false) - right-to-left - first train, and the loop from limit to 0 - left-to-right - second train)
And, yes: I didn't look through the code - I don't want to download, save (there's already a lot of unnecessary code from the forum), compare them with each other...
It would be easier to put them in codes in message - one and second - then it would be visible at once what to what.
Or flip the loop to match its indexing of arrays open[], high[], low[], close[] and the rest, which is harder.
I've been reversing it all night today, my patience has run out (((
As far as I understand the problem:
- in MT5 the arrays that are assigned to indicator buffers are indexed from left to right by default;
- in MT5 time seriesopen[], high[], low[], close[] available from OnCalculate() are always passed indexed from right to left
- i.e. based on steps 1 and 2, in order to calculate the indicator from the end of the history to the zero bar
a) or reassign the buffer arrays indexing
b) or to make a loop in which the array elements will be recalculated from left to right, and in another loop from right to left:
i.e.,there is no beautiful solution to my question? option a) - in my sources is implemented, option b) - I do not see the point of doing extra calculations
sources:
MT5:
MT4:
I've been flipping all night tonight, but my patience has run out (((
as far as i understand the problem:
- in MT5 the arrays that are assigned to indicator buffers are indexed from left to right by default;
- in MT5 time seriesopen[], high[], low[], close[] available from OnCalculate() are always passed indexed from right to left
- i.e. based on steps 1 and 2, in order to calculate the indicator from the end of the history to the zero bar
a) or reassign the buffer arrays indexing
b) or to make a loop in which the array elements will be recalculated from left to right, and in another loop from right to left:
i.e., there isno beautiful solution to my question? variant a) - in my source code is implemented, variant b) - I don't see the point in doing extra calculations
All arrays are indexed from right to left. Therefore, to fully comply with the loop from left to right (and it is from left to right - from limit to 0), you need to set all used arrays to required indexing: buffers in OnInit(), used timeservers - in OnCalculate().
Or, do the cycle from 0 to limit, which is not always easy to do when mql4 is ported to mql5.
Therefore, the ArraySetAsSeries() option is better in this case.
All arrays are indexed from right to left. Therefore, to fully comply with the loop from left to right (and it is from left to right from limit to 0), you need to set all used arrays to required indexing: buffers in OnInit(), used timeservers - in OnCalculate().
Or, you have to do the cycle from 0 to limit, which is not always easy to do when mql4 is ported to mql5.
That's why in this case the ArraySetAsSeries() method works better.
Look, remove allArraySetAsSeries() from your code(above in Init() and OnCalculate() in first lines) and corrected the loop:
for(i=0;i<limit;i++)
Theoretically, everything should fit together! But no! The charts turned out different - this is what I cannot figure out!
Look, I removed allArraySetAsSeries() from my code(at the top in Init() and in OnCalculate() in the first lines) and fixed the loop:
for(i=0;i<limit;i++)
In theory, everything should fit together! But no! The charts turned out different, and that's what I cannot figure out!
I'm telling you - it's more complicated than that. You have to change the logic. It's not enough just to invert the loop.
Here's one small example: in the code there is
Buf_NTLine1[i+1])
Where will the i+1 index go when the arrays are indexed differently?
And there's a lot of it. IHighest() - start and number. Where does it start at one indexation and where does it start at another?
And so on ...
and there's a lot of it. IHighest() - start and number of... Where does it start at one indexing and at the other?
oh man! that's right! well done!!! yeah, that's the tricky part!!!
Yeah... a lot of differences in MT5, a lot of checks and all sorts of precautions on the programmer's head...
When I saw it not long ago I had a message that in MT5 not always everythingis initialized correctly inInit(), it looks likeInit() may end even if timeframes are not ready.
I saw a bug yesterday: if this indicator in MT5 switches timeframes, sometimes indicator buffers may not be empty - it seems the old values remain if not to assign a specific value to each element in the indicator array in OnCalculate(), I triedto put ArrayInitialize(arr, 0.0) inInit()- it works too, then not...
as far as I understand it correctly:
- in MT5, at initialization inInit(), indicator buffers are not initialized automatically? (in MT4 I do not remember anything remained in buffers)
- in MT5 inInit() the sizes of buffer arrays may be unknown if the history is not loaded, that is whyArrayInitialize(arr, 0.0) also does not always initialize buffers correctly?
Damn it! That's right! Well done!!! Yeah, that's the fun part!!!
Yeah... There are a lot of differences in MT5, the programmer has a lot of checks and all sorts of precautions...
When I saw it not long ago I had a message that in MT5 not always everythingis initialized correctly inInit(), it looks likeInit() may end even if timeframes are not ready.
I saw a bug yesterday: if this indicator in MT5 switches timeframes, sometimes indicator buffers may not be empty - it seems the old values remain if not to assign a specific value to each element in the indicator array in OnCalculate(), I triedto put ArrayInitialize(arr, 0.0) inInit()- it works too, then not...
as far as I understand it correctly:
- in MT5, at initialization inInit(), indicator buffers are not initialized automatically? (in MT4 I do not remember anything remained in buffers)
- in MT5 inInit() the sizes of buffer arrays may be unknown if the history is not loaded, that is whyArrayInitialize(arr, 0.0) also does not always initialize buffers correctly?
Didn't really get into the logic of it.
Didn't really get into the logic of it.
This is the right way to go: don't put entry points at max/min price - better at the opening price.
And the lines should be removed - what for are they on the chart? If only to drag a stop on them?
declaration without type
If I compile a include file, there's no error. If I compile the main program file where I include this include file, there is a declaration without type error. It doesn't see the object declared in the include file protected CSomeClass *object. The include file has the #include "SomeClass.mqh" directive. And in the main file, an object of the class of the included file is created and one of the methods is called.