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

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 do I know the type of input parameter?
the compiler itself substitutes the types at the moment of template function call, if such call was not yet in the code, then the compiler will create another function copy and set the types itself - well, as if logically - a template
if the question is about how to define the type in such a function, use
typename
UPD: added to the example above the parameter type printers:
2020.09.16 18:58:21.679 tst (EURUSD,M5) int myfunc<int,int>(int,int)
2020.09.16 18:58:21.680 tst (EURUSD,M5) val1 = 2, typename = int
2020.09.16 18:58:21.681 tst (EURUSD,M5) val2 = 3, typename = int
2020.09.16 18:58:21.681 tst (EURUSD,M5) 5
2020.09.16 18:58:21.681 tst (EURUSD,M5) int myfunc<double,double>(double,double)
2020.09.16 18:58:21.681 tst (EURUSD,M5) val1 = 10.0, typename = double
2020.09.16 18:58:21.681 tst (EURUSD,M5) val2 = 30.0, typename = double
2020.09.16 18:58:21.681 tst (EURUSD,M5) 40
UPD: added__FUNCSIG__ to this example
Afternoon.
I am facing some strange thing when writing an indicator in MQL5 (indicator in a separate subwindow, 4 lines).
The initial buffer descriptions are as follows:
Next in OnInit:
Essentially: the indicator draws 4 lines: the first two are just single-coloured, the next two are bicoloured (they change colour on kinks).
Bicolor is due to the way of drawing DRAW_COLOR_LINE.
Question: first line (buffers 2 and 3 in the code above) is perfectly drawn and all code written for it in OnInit works;
I.e. instead of the text I set in the data window, just the name of the indicator is displayed in place of the buffer. Although the line itself is drawn, and it is, as it should be, multicoloured.second line shows up for some reason, for example line doesn't work:
I think the trick is in the numbering shift? For example, I'm not sure why in the upper part of the code, when I declare the last line with #property directive, the index should be 4, not 5, as 4 buffers have already been used before. Is there any relation at all between line numbering when declaring with #property and buffer numbering when linking with arrays in OnInit?
Please advise what is wrong in the code above. Maybe someone can find an example of indicator where at least two lines are drawn using DRAW_COLOR_LINE.... drawing method
One more related question: how do the colorful line buffers get tied together? I mean, how does the compiled code know that if I put a value into a colour buffer, this colour should be used to colour a line from some other buffer?
Afternoon.
I am facing some strange thing when writing an indicator in MQL5 (indicator in a separate subwindow, 4 lines).
The initial buffer descriptions are as follows:
Next in OnInit:
Essentially: the indicator draws 4 lines: the first two are just single-coloured, the next two are bicoloured (they change colour on kinks).
Bicolor is due to the way of drawing DRAW_COLOR_LINE.
Question: first line (buffers 2 and 3 in the code above) is perfectly drawn and all code written for it in OnInit works;
I.e. instead of the text I set in the data window, just the name of the indicator is displayed in place of the buffer. Although the line itself is drawn, and it is, as it should be, multicoloured.second line shows up for some reason, for example line doesn't work:
I think the trick here is in the numbering shift? For example, I'm not sure why in the upper part of the code, when I declare the last line with #property directive, the index should be 4, not 5, as 4 buffers have already been used before. Is there any relation at all between line numbering when declaring with #property and buffer numbering when linking with arrays in OnInit?
Please advise what is wrong in the code above. Maybe someone can find an example of indicator where at least two lines are drawn using DRAW_COLOR_LINE.... drawing method
One more related question: how do the colorful line buffers get tied together? I mean, how does the compiled code know that if I put a value into a colour buffer, this colour should be used to colour a line from some other buffer?
Mappings are numbered differently than buffers.
This should work.
Good afternoon everyone!
I made a function to modify stoploss. But when it works it gives out EURUSD,H1: OrderModify error 130.
And the price is far from the place where stoploss should be set.
Here is the function:
Wrote a function to find the bar number of a fractal out of 3 bars. On the online chart it seems to find it correctly. But during visual testing in the tester it lies. May any of the professionals take a look at the code and find some errors?
I'd be most grateful.
Good afternoon. WHAT CODE SHOULD I ADD SO THAT THE INDICATOR STOPS WORKING IN THE TESTER AFTER A MONTH ? I.E. I WROTE ALL OK ! BUT WHEN I DO A BACKTEST IT WORKS AGAIN. (mgl4)
Hello!
I wanted to put a condition in the order closing cycle onthe order opening day, so that the ones that were opened on Friday would not be closed.
Good afternoon. WHAT CODE SHOULD I ADD SO THAT THE INDICATOR STOPS WORKING IN THE TESTER AFTER A MONTH ? I.E. I WROTE ALL OK ! BUT WHEN I DO A BACKTEST IT WORKS AGAIN. (mgl4)
You need to write this code not in OnInit, but in OnTick().
Hello!
I wanted to put a condition in the order closing cycle onthe order opening day, so that the ones opened on Friday would not be closed.
Try it this way: