![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
Well I wouldn't block it of course. I would have passed the error up and decided what to do with it.
If you block the EA at this point, there may be an open position left by this EA, which would be a disaster.
You have now answered your own question about the long pause. It is done to wait for the signal to open a position or set an order.
Thank you, Vasily, once again for having successfully led me astray. I almost rushed to fix the codes... And thank you again for bringing me back on my way :-)
:-) You have now answered your own question about the long pause. It is done in order to wait for the signal to open a position or set an order.
Thank you, Vasily, once again for having successfully led me astray. I almost rushed to fix the codes... And thank you again for bringing me back on my way :-)
To be honest, I don't understand the logic.
For example, we placed an order for 0.000001 lot. The server, of course, slaps us for it.
Instead of changing the lot (outside the function), we pause.
As a result of this break we may lose the signal to set an order, but we should change the lot instead of waiting.
That is why I do not agree with the pause. We should simply leave this function and pass the error code upwards and handle it there.
If we go my way, we might not miss a profitable trade! And we might even get a loss :)
PS: I'll lead you astray from the untrue path :)
and I thought, you need to call the function of lot calculation at once (and not to go to the top), going to the top only after the error counter overflow
Yes of course you need to call this function immediately, but if an error does occur!!!
Exit to the top I call a situation where you have to exit the function SetOrder.
I see it approximately as follows
int ticket = SetOrder(.....);
if (ticket > 0) {
// all ok} else {
// correct logic error
}
int SetOrder(....) // returns either a ticket or an error number only with a negative sign.
{
int ticket = OrderSend(....)
if (ticket < 0) {
// correct set order errors
}
}
So I think we need to distinguish between logic errors and order setting errors. I hope I will give an example of an implementation today.
To be honest, I don't understand the logic.
I have built the lot size calculation function in such a way that it will give an incorrect lot (zero) only if there is not enough money. In other cases, the lot is normalized and is driven within the limits between the minimum and maximum sizes. If there's not enough money, we have to wait for some position to close.
If you have ordered 0.000001 lot. Our server has surely given us a slap on the wrist.
Why did we do that? Why did we deliberately pass the wrong lot size? How can we justify this behaviour?
We should simply leave this function and pass the error code upwards and handle it there.
I just think that your function is a library function, i.e. universal, and therefore you should divide all errors into 2 categories:
Функцию расчёта размера лота я строю таким образом, что неверный лот (ноль) она выдаст только в случае не хватки денег. В остальных случаях лот нормализуется и загоняется в рамки между минимальным и максимальным размерами. Если денег не хватает, то надо ждать, когда закроется какая-нибудь позиция.
error checking block.
That's my vision of this case :) As I wrote above, I hope to give an example of implementation today.
My version of fashion:
My version of the mod:
Dear TheXpert, your code looks very compact. Which of course is a fat plus! >> Thank you.
Attached is an Expert Advisor that uses the function. I have used AI Expert Advisor as a basis.
I have not had time to check the function by time. In other words, I believe that the signal should be checked again after 8 minutes.
Added generation of errors of the trade server that will allow to examine operation of the function in details and detect errors.
errTest - sequence of errors generated, no error 0. This is a random sequence and there is no catch to be found in it.
I'm waiting for some criticism :)
As promised, I'm posting my version of the function.
Attached file contains EA where this function is used. I have used AI Expert Advisor as the basis.
I have not had enough time to check how the function works by time. I.e. I believe the signal should be checked again after 8 minutes have passed.
Added generation of errors of the trade server that will allow to thoroughly study operation of the function and detect errors.
errTest - sequence of errors generated, no error 0. This is a random sequence and there is no catch to be found in it.
I'm waiting for criticism :)
I don't really care about the function, I can say one thing :), I'm not going to be original and say as always :) -- too overloaded.
As a result, the Expert Advisor has become a 32KB clean and clear code where I don't feel like messing around.
There are questions about the code.
1. If you disable the Expert Advisor, it won't work again until it is restarted. Why not make it wait for a relatively long period of time?
2. Neural network -- first of all it never outputs the signal of a flat. Secondly, how can you expect it to optimize something, if it has no threshold? By missing threshold you kill 80% of its already low efficiency (linear, though).
SZZH: Don't be offended, I'm moonlighting as a critic in this thread :) .