
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
Looping is one of the most dangerous programming techniques. It causes strange, infrequent errors that are almost impossible to analyze.
On the contrary, you should try to end a user thread as quickly as possible instead of looping. If you want to keep your hand on the pulse - analyze OnTradeTransaction in MT5. MT4 is generally not suitable for such games, because simplicity is worse than theft, as they say.
I meant not a concrete realization, but the principle of TS shaking after any pause. Well and where there is a terrible fixation - is not clear. As it is not clear, why there is a rush to finish a user thread.
Where is the scary looping there - it's not clear.
Calling OnTick from OnTick is a non-trivial loop through recursion:
Neither is it clear why there is a rush to terminate the user thread.
We are working with an event-driven model. Therefore we need to handle the current event as fast as possible to wait for the next one. Time spent in the thread is a black hole. The more time we spend in the flow, the more outdated the trading environment we are working with.
Calling OnTick from OnTick is a non-trivial loop through recursion:
Apparently, this is the only thing that deters.
We are working with an event model. Therefore, we need to handle the current event as fast as possible in order to wait for the next one. Time spent in the flow is a black hole. The more time we spend in the flow, the more outdated the trading environment we work with.
s. We don't understand each other at all. I don't think there can be any dialogue between us.
:
Where did you see a pause in your code, the mere presence of which is the only reason for shaking the TS from scratch? You do not have it!
Where did you see a pause in your code, the mere presence of which is the only reason for shaking the TS from scratch? You do not have it!
So this code is an illustration of why the current thread must be terminated as soon as possible. You should not even try to request the trade environment in OnTick:
Once we are at the point where the two variables are compared, we cannot compare them because the environment keeps changing. The values in total_1 and total_2 are either no longer equal to each other, or they are both obsolete, or they do not contain the existing number of orders, or they contain the correct values. It is pointless to fight a changing trading environment in OnTick, instead just exit OnTick, immediately after the for loop, and wait for new events indicating that the trading environment has changed.
So this code is an illustration of why the current thread should be terminated as quickly as possible. You cannot even attempt to query the trading environment in OnTick:
Once we are at the point where the two variables are compared, we cannot compare them because the environment keeps changing. The values in total_1 and total_2 are either no longer equal to each other, or they are both obsolete, or they do not contain the existing number of orders, or they contain the correct values. It is pointless to struggle with changing trade environment in OnTick, instead, we just need to exit OnTick, right after the for loop, and wait for new events indicating that the trade environment has changed.
So why did you put pauses?!
Once again, after any pause (slips or synchronous trade orders) TC must be shaken up - the trading logic must be started from zero. Accordingly, if asynchronous trade orders are used, the pauses mentioned do not occur and there is an exit from the Event-Function waiting for a new event. If there are no asynchronous operations, the entire trading logic can even be placed in a looped script.
So why did you put pauses?!
Once again, after any pause (slips or synchronous trade orders) the TS must be restarted - the trading logic must be started from zero. Accordingly, if asynchronous trade orders are used, the pauses mentioned do not occur and there is an exit from the Event-Function waiting for a new event. If there are no asynchronous operations, the entire trading logic can even be placed in a looped script.
I will speak about Thomas, and you will speak about Yury. In short, let's finish our dialogue. Go on creating your own looped scripts. Yes, it really works, but it cannot be recommended as a working method.
I am interested to know their opinion on this situation in MT4, how do they handle it?
The Expert Advisor's ToR is to keep pending orders and open positions on a certain fixed distance from the current price on every tick.
Let the broker modifications take a little longer than the average time interval between price ticks.
So, we run in a reverse cycle (in decreasing direction of SELECT_BY_POS) and make corresponding OrderModify.
So, during this loop, packed into OnTick, the following may happen
What to do?
The question is indirectly related to the discussion above, but this is not for its continuation (topic closed). I need to solve some not obvious nuances in MT4Orders for MT5. So it would be useful to hear the opinion on the described situations from those who are good at MT4 specifically. And I am not the only one who may find it useful.
Solve the problem through OnTimer - this is probably the first suggestion. But we do not need it - only OnTick.
I am interested to know their opinion on this situation in MT4, how do they handle it?
The Expert Advisor's ToR is to keep pending orders and open positions on a certain fixed distance from the current price on every tick.
Let the broker modifications take a little longer than the average time interval between price ticks.
So, we run in a reverse cycle (in decreasing direction of SELECT_BY_POS) and make corresponding OrderModify.
So, during this loop, packed into OnTick, the following may happen
What to do?
The question is indirectly related to the discussion above, but this is not for its continuation (topic closed). I need to solve some not obvious nuances in MT4Orders for MT5. So it would be useful to hear the opinion on the described situations from those who are good at MT4 specifically. And I am not the only one who may find it useful.
Solve the problem through OnTimer - this is probably the first suggestion. But let us skip it - only OnTick.
Firstly, the situation is non-standard and very few people, if any, have ever solved it.
Purely theoretically:
We don't have to arrange a reverse loop for OrderModify, so let it be direct.
Then let's check for changes of the list of orders
If the amount of orders has changed, we will start this loop anew with a new amount of orders.
One more question:
fxsaber:
It's understandable that if they were added, they or others will be missed. But what if they were simply deleted? We would not be able to go beyond the order list?