![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
Is OrderClose guaranteed to close the trade?
Not guaranteed, but there is a check in the code for this. Each OnTick call is independent of the previous one.
Not guaranteed, but there is a check in the code for this case. Each OnTick call is independent of the previous one.
OK, closing on the next tick will do.
@Artyom Trishkin,@Andrey Khatimlianskii, Thanks for participating! It's a pity nobody has commented on MT5 code. Apparently they think everything is fine.
Of course, the example was given to answer that all is not well at all in MT5. Example showing the problem
What do you think, if you run this script on a symbol with no positions, what will happen in the end?
The correct answer is that one or two positions will be opened.
Of course, the example was given to answer that all is not well at all in MT5. Example showing the problem
What do you think, if you run this script on a symbol with no positions, what will happen in the end?
The correct answer is that one or two positions will be opened.
As a consequence, the vast majority of MT5 Expert Advisors in Kodobase are not written correctly!
Few will argue with this statement
This is a universal rule. But not many people think about its implementation in MT5. That's why I wrote a template of most uncomplicated TS (in kodobase almost all of them are like that)
For some reason some people write more code for the same TS. But in fact this code does just as well. Most TCs only require writing BuySignal and SellSignal. Nothing else is needed.
The template example is specifically written with SB. So question for MT5 experts, is the code correct?
I came to this thread by accident and actually wanted to start a thread to discuss strategy templates. Your template is close enough to what I think is correct (readable for me), but still I don't like when a call of one function is inserted into OnTick, which hides a whole mining mill.
At one time I even wrote MetaEditor: Relying on the power of templates. Since then the language has changed, no template editor. It would be interesting to discuss this issue (could be in a separate thread), and also get an article on the subject. I believe that when writing code one should try to make the strategy readable at a glance without having to get into class or macro methods.
As a consequence - the vast majority of MT5 Expert Advisors in Kodobaz are not written correctly!
As always - categorically. Can't be, although I haven't read your code.
I've been wanting to start a thread to discuss strategy templates for a long time now. Your template is close enough to what I think is correct (readable for me), but I still don't like it when a call of one function is inserted into OnTick, which hides the whole mining mill.
If you make OnTick == Strategy, the template will shrink/shrink to an obscene size.
At one time I even wrote an article MetaEditor: Building on the power of templates. Since then the language has changed, no template editor. It would be interesting to discuss this issue (could be in a separate thread), and also get an article on the subject. I believe that when writing code one should try to make the strategy readable at a glance without having to get into class or macro methods.
This is how the template for both platforms showed. It is so simple that it is hard to discuss it, although for MT5 it is fundamentally wrong. But you have CExpert. I haven't looked there myself - it's scary.
As always - categorical. Can't be, although I haven't read your code.
You read it, your opinion is very interesting.
Of course, the example was given to answer that all is not well at all in MT5. Example showing the problem
What do you think, if you run this script on a symbol with no positions, what will happen in the end?
The correct answer is that one or two positions will be opened.
And if we replace GetAmountPositions with standard OnTradeTransaction?
Approximately like this: