Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 670

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
How to create an array of class instances?
I made ClassName* className[], then ArrayResize on it, but it doesn't give me access to methods
Your class, whose instances you want to collect into an array, must be inherited from CObject.
And then it's simple: create a list (array) of objects CArrayObj, and add your objects to it.
Searching for the words "indicator template" and your name doesn't find anything, and you've already written here on that War and Peace volume.
Any combination of words from the post come to mind.
Well, I'm sorry, about the indicator template maybe I got it mixed up - the trawl template was posted.
Let's put it this way: create an indicator template in the editor, add the required number of input variables and buffers to be drawn.
Next, break down what you need to do from the specific task.
If you say it's bad, tell me how to make it good. Move the calculations to OnInit?
Fair rebuke )) Here, a variant of the code that was published here:
Try doing it that way. You don't need to move anything to OnInit.
Fair rebuke )) Here, a variant of the code that was published here:
Try to do it this way. You don't need to move anything to OnInit.
I haven't published such code here - not my thing :)
I use other constructions - it's simpler and clearer.
In OnInit() it should be transferred. Why do you need to assign an array to the indicator buffer on each tick?
I haven't published such code here - it's not my thing :)
I use other constructions - simpler and clearer.
It's mine, how could it be simpler? ))) (at least, I also have in my template the commentlimit = rates_total - 1;//--- First call of indicator or change of timeframe or loading of data from history) and my style of formatting - one curly bracket near for() {
To learn to write your own indicator, take the above template and add at least the close price and get your first indicator, then learn to make the MAH from this close price
I haven't published such code here - it's not my thing :)
I use different constructions - simpler and clearer.
Nothing needs to be copied into OnInit(). Why should I assign an array to the indicator buffer at each tick?
It's not your code. It was published by some of my colleagues but I cannot recall who and where. It was this code that I meant when I wrote that nothing should be moved to OnInit but not the source code. I was not quite clear.
And what construction would you recommend? This seems to be very simple.
Ah, there's the author of the piece )))) Ahead of me. By the way, I use this style of formatting too - with one opening curly bracket in a line.Ah, here's the author of the snippet )))) Ahead of me. By the way, I also use this style of formatting - with one opening curly bracket in a line.
You run the Wizard for creating an indicator, select types and colour of lines and add input 's, if necessary
and that's all, the indicator is ready, then copythe body fromOnCalculate() of the template and write the calculations ,
you can write your first indicator in 1 minute, the code "Hello word I indicator! - I showed :)
ZS: By the way, the indicators can be transferred from MT4 to MT5 in this form, the main thing is to set up indicator buffers correctly, in MT5 there is a creep in the indexing of arrays under the buffers.... they are just arrays with the usual array )))) indexing .... it used to be hard to get used to indexing of indicator buffers in MT4, now on the contrary it is impossible to get used to it and switch to MT5 ))))This is not your code. It was published by one of my colleagues, but I can't remember who and where. It was this code I meant when I said that nothing should be moved to OnInit but not the source code. I was not quite clear.
And what construction would you recommend? This one seems to be very simple.
Ah, there's the author of the piece )))) Ahead of me.yeah, what is the indicator template code good for? run the wizard to create an indicator , choose the types and color of the lines and, if necessary, add input 's
and that's it, the indicator is ready, then copy the body from the OnCalculate() template and write the calculations,
you can write your first indicator in 1 minute, the code above is "Hello word I indicator!!!" I showed :)
PS: by the way, in this form, indicators can be transferred from MT4 to MT5, the main thing is to set up indicator buffers correctly, in MT5 there is a horror that with indexing arrays for buffers .... they are just arrays with the usual array)))) indexing .. .. earlier it was hard to get used to the indexing of indicator buffers in MT4, now on the contrary it is impossible to get used to it and switch to MT5))))Nothing complicated. An example of a cross-platform indicator (uses a class), but the template can be pulled out - remove the class and everything superfluous that will give errors after that - the cross-platform template will remain.
This indicator will work the same on both platforms without modification - just compilation with the required extension. I had to split the code into two parts - the class and the indicator itself (everything was in one listing)
Class:
Indicator: