Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1481

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
It will appear if you write this
Hi Alexey, one clarification. Is it necessary to use PositionSelect() instead of a loop, or did I misunderstand something again?
Regards, Vladimir.
Hi Alexey, one clarification. Is it necessary to use PositionSelect() instead of a loop or did I misunderstand something again?
Regards, Vladimir.
You can write it any way you want, the main thing is to write a non-existent character to get an error...
You can write it any way you want, the main thing is to write a non-existent character to get an error....
But don't throw slippers at me!!! I can't get the error code. ((((
Regards, Vladimir.
Error = "
There should be a specifier there
Thank you Artem, it worked!!! Thank you all very much!
Regards, Vladimir.
In short, solved the problem described here in a different way:
Regards, Vladimir.
Good evening everyone!
I am trying to create a function that opens an additional position (without stop and take) to an existing open position. I have written the code:
but for some reason it doesn't see the open position. I tried to find the problem with the debugger, but after starting the loop it immediately leaves the function without seeing what is written inside it. I put the breakpoint at PositionGetTicket(i). Could you please tell me where I have a bug in my code again?
Regards, Vladimir.
but for some reason it doesn't see the open position. I tried to find the problem with the debugger, but after starting the loop it immediately leaves the function without seeing what is written inside it. I put the breakpoint on PositionGetTicket(i). Could you please tell me where I have a bug in my code again?
Regards, Vladimir.
What is pos_total?
What is pos_total equal to?
Hi Alexey, the variable pos_total=PositionsTotal(), but it was set at the global level. Now I have moved it inside the function and it turned out that this was the problem. Everything worked. What's the problem? I didn't understand the trick at all!!!
Now, for the sake of experiment, I moved pos_total to the global level again and it stopped working again, but when I put it inside the function, it works as it should! Just some miracles, well, at least for me!!!! )))
It turns out that a variable at the global level cannot be initialised by a function? Is it so?
Regards, Vladimir.
Hi Alexey, the variable pos_total=PositionsTotal(), it was just set at the global level. Now I have moved it inside the function and it turned out that this was the problem. Everything worked. What's the problem? I don't understand the joke at all!!!
Now, for the sake of experiment, I moved pos_total to the global level again and it stopped working again, but when I put it inside the function, it works as it should! Just some miracles, well, at least for me!!!! )))
It turns out that a variable at the global level cannot be initialised by a function? Is that right?
Regards, Vladimir.
Sometimes you can, but not every variable. In this case, when you run the EA, it does not see open positions yet and the variable is equal to zero....
Actually, yesterday I experimented with position sampling and came to the conclusion that PositionsTotal() is needed only to determine the number of positions. And this number is needed only to limit the loop.
Here is such a loop
works even if you get a list of orders or deals from the history before it. One of these days I will check whether the selection of pending orders will interfere with it.
And in your case it's easier to write without a loop
if you need the last position...