[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 574
![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
I wrote something like trailing for my EA, but it doesn't work, depending on what I try to change to make it work, it generates error 1 when modifying, or just does not go beyond the first print (Print("Leading Buy position"); )... what could be the reason, I would be glad to hear any suggestions, thanks in advance!
Your conditionwhile(OrderCloseTime()==0). If you enter this loop, the modification attempts will be repeated until the order closes or the operator brek or return is encountered, which you don't have in the loop.
Sorry, screwed up. They are there, but I did not notice them at once without glasses. Removed superfluous bracket and added output. Try it, it may work.
I wrote something like trailing for my EA, but it doesn't work, depending on what I try to change to make it work, it generates error 1 when modifying, or just does not go beyond the first print (Print("Leading Buy position" ); )... what could be the reason, I would be glad to hear any suggestions, thanks in advance!
For the sake of interest tell me how does THIS behave - "something like trailing" in the EA??? My guess is that the code should freeze. And what actually happens? Does it open more than one order???
hmmm... why would it hang?!
Trailing starts pulling stops up when there is a profit, so I tried to make it pull stops in the loss zone as well.
It behaves very simply: When price becomes higher than trailing level, it modifies order and accepts new value of stop loss, then it sleeps for a second, to avoid frequent requests (because I can't yet properly test my version of trailing, If the required conditions have not been reached, it will wait for them; all this activity will take place until the order is closed and the time of closing is better than zero, therefore, the loop condition will not be executed and the function will stop working and return true.
hmmm... why should it freeze?!
Trailing starts pulling stops up when there is a profit, so I tried to make it pull stops in the loss zone as well.
It behaves very simply: When price becomes higher than trailing level, it modifies order and accepts new value of stop loss, then it sleeps for a second, to avoid frequent requests (because I can't yet properly test my version of trailing, If the necessary conditions have not been reached, it will wait for them and all this will happen until the order is closed and the time of closing is better than zero; then the loop condition will not be executed and the function will return true
The code has entered the loop on condition of exit - closing of the order at StopLoss. And how much time will it take (for the price to reach the SL level)? Probably not a millisecond, not even a second, and probably not even a minute? CONGRATULATIONS - you've made a "new step" in MQL4 coding!!!
P.S. Or maybe I'm wrong, and you're just an advanced tester codopist! :)))
The code entered the loop by the exit condition - closing the order at StopLoss`. And how much time will it take (for the price to reach the SL level)? Probably not a millisecond, not even a second, and probably not even a minute? CONGRATULATIONS - you've made a "new step" in MQL4 coding!!!
P.S. Or maybe I'm wrong, and you're just an advanced tester codopist! :)))
If everyone knew everything, what would be the point of this thread and forums in general?
The code entered the loop by the exit condition - closing the order at StopLoss`. And how much time will it take (for the price to reach the SL level)? Probably not a millisecond, not even a second, and probably not even a minute? CONGRATULATIONS - you've made a "new step" in MQL4 coding!!!
P.S. Or maybe I'm wrong, and you're just an advanced tester codopist! :)))
What's wrong? I agree, but why doesn't it want to start working?
Explain popularly, what's wrong with a lot of cycles? yes, i agree, but why won't it start working?!
Because the loop is always running and the program does nothing and won't do anything until the loop ends and gives control to the program. It just waits, and it can wait as long as it wants. i.e. the program does not process, for example, new ticks coming into the terminal.
P.S. Actually, it works. The computer isn't smart, but it's not lazy; on the contrary, it's very diligent. If you don't believe me, put a counter at the beginning of the loop and see how many times it executes it.
Explain popularly, what's wrong, that there will be a lot of cycles? yes, I agree, but why doesn't it want to start working, then?!
In this function, it's easier to mark "what's right":
In this function, it is easier to mark "what is right":
I understand that there is a lot of experience and it's okay to be sarcastic! But if you don't mind, write down the right way, teach a newcomer...I'd appreciate it!