Questions from Beginners MQL5 MT5 MetaTrader 5 - page 983
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
Hello colleagues.
Question: In mql4, in order to calculate the number of positions, you can write the function like this
How is it implemented in mql5? How can I calculate the number of positions by magik or by type?
Hello colleagues.
Question: In mql4, in order to calculate the number of positions, you can write the function like this
How is it implemented in mql5? How can we calculate the number of positions by a magic number or by a type?
Example inEhlers_CG EA code, function CalculateAllPositions.
Example inEhlers_CG EA code, function CalculateAllPositions.
Thank you very much. Tried to change it to a more understandable form. But it returns 0 and opens endless orders, please advise, where have I screwed up? I do not want to pay attention to my trading idea, I just want to learn it in general.
Thank you very much. Tried to change it to a form that makes more sense to me. But it returns 0 and opens endless orders, please advise, where did I screw up? Please do not pay attention to my trading idea, I am just trying to get acquainted with it.
The key word of your error is that I have not written so much verification code in my EAs for nothing. You have left out almost all the innards, and in particular OnTradeTransaction.
I faced a problem, the indicator based EA works correctly on the real account, but it is lying in the tester, in tick generation modes both by OHLC and by all ticks - the result is the same. The result of the error is the empty buffer of the indicator at zero bar (only when there is a new bar at the upper TF, which is used for the calculation of the indicator). However, I have managed to make indicator to be calculated by adding Sleep to my Expert Advisor. But I have found out that depending on the mode of ticks generation this Sleep should be different - for generation from all ticks Sleep(15000) is enough, while for OHLC Sleep(30000) is needed.
So the question arises - is the situation with Sleep normal, because it logically turns out that different delay times are modeled there depending on the mode of ticks generation!
Dear developers, I ask you to explain the situation with the indicator, because I myself cannot understand what the reason is - a bug in the code or in the tester!
I am ready to give the indicator and the Expert Advisor in the PM, but tell me to whom.
I faced a problem, the indicator based EA works correctly on the real account, but it is lying in the tester, in tick generation modes both by OHLC and by all ticks - the result is the same. The result of the error is the empty buffer of the indicator at zero bar (only when there is a new bar at the upper TF, which is used for the calculation of the indicator). But I have managed to make indicator to be calculated by adding Sleep, and it was found out, that depending on the mode of ticks generation this Sleep should be different - for generation from all ticks Sleep(15000) is enough, but for OHLC Sleep(30000) is needed.
So the question arises - is the situation with Sleep normal, because it logically turns out that different delay times are modeled there depending on the mode of ticks generation!
Dear developers, I ask you to explain the situation with the indicator, because I myself cannot understand what the reason is - a bug in the code or in the tester!
I am ready to give you the indicator and EA in the PM, but tell me to whom.
Sleep does not work in this indicator. Moreover, it is ignored even in the Expert Advisor, if we are talking about the tester.
Sleep does not work in the indicator. Moreover, it is ignored even in the Expert Advisor, if we are talking about the tester.
I have already written that Sleep is in the Expert Advisor, and if it is ignored, and you are 100% sure about it, then it is an extra confirmation that the error is in the tester.
The delay may not occur in time, but it may be emulated for the program.
Added: Sleep works in the tester, here is a simple code that confirms it
Result
Sleep does not work in the indicator. Moreover, it is ignored even in the EA when it comes to the tester.
It is not.
I have already written that Sleep is in the EA, and if it is ignored, and you are 100% sure of this, then it is an extra confirmation that the error is in the tester.
The delay may not occur in time, but it may be emulated for the program.
Added: Sleep works in the tester, here is a simple code that confirms it
Result
This was originally the case in your post:
However, I managed to get the indicator to read by adding Sleep, and here it was revealed...
That's why I reacted to Sleep in the indicator.
And about Sleep in the EA, I don't understand why you had to make it behave differently in 4 and in 5. In 4, it's like that:
As for the fact of the question. Sleep should not have any effect on the recalculation of data in the indicator. Something is wrong with buffer filling. Maybe there is a reproducible piece of code?