Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1802
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
Dobro. Let me put it in simple Russian terms.
You're going fishing.
Or you can take everything you need from the pantry (OnInit) straight away, fish without running around and, when you get home, put everything in the pantry and refrigerator (OnDeinit).
You may have known that here on the forum. You just need to listen and hear what you are told sometimes.
Otherwise you get a question, get an answer, say "bullshit" and do as you think.
You must first think over the question, ask questions, and then start editing.
Are you aware that the simplest thing in programming is printing code? And the lion's share of development is thinking over the logic.
That's a ridiculous analogy. In that case let's make all variables, class objects etc. global and not create them on demand or maybe a graphical object is something else (certainly not a fishing rod or a net :)) ? So my approach is quite rational and justified, it's just that mql or metatrader screws up.
This way the signal will be missed
Either I'm being obtuse, or there is no condition if there are open orders AND there is a signal and the bar is already new.
If the signals are long, more than a bar multiple, it will also work on the first tick of the bar.
The only question is when to open an order, when the signal appears or at the first tick of the next bar.Either I'm being obtuse, or there is no condition if there are open orders AND there is a signal and the bar is already new.
If the signals are long, more than a bar multiple, it will also work on the first tick of the bar.
The only question is when the order should be opened, at the moment of the signal or at the first tick of the next bar.The code now looks like this:
Before opening, check if there is an open position on this candle. If not, open it.
In principle, an open order would normally close on the ticks of an already open bar. MakarFX and Artem have correctly noted. Therefore, the right thing to do would be to do this:
In principle, an open order would normally close on the ticks of an already open bar. MakarFX and Artem have correctly noted. Therefore, the right thing to do is this:
Artem is right, it should be like this
You're right, Artem, it should be like this.
The result will be the same here. Only the code is more complicated. You are writing the same code in two different functions. And it will be less readable. Although, everyone writes as he likes or feels comfortable...
There's a lot going on here.
An open position has an opening time. The open time can be compared to the time of a candle - to find out if the time of opening the position is inside the candle (and this is the current candle).
And why do you always find out the number of orders in all the examples? And if there are zero orders, then you open them. This greatly limits the possibilities.
Generally, we should only focus on the number of orders/positions for a very narrow strategy direction.
The result here will be the same. Only the code is more confusing. You are writing the same code in two different functions. And it will be less readable. Although, everyone writes as he likes or feels comfortable...
Your code
(A bar has opened and no order has been placed)
checked for a signal - no signal
... we wait for the next bar.
You repeated the same mistake as last time
P.S.
this is
must be carried out after the order has been openedYou're right, Artem, it should be like this
In your code, if one position is open, another one will not open by the opposite signal. I.e., first of all, when the signal comes in, you need to check whether there is an opposite position and close it.
But again, this all greatly limits the possibilities to improve the strategies.
We should avoid binding to the presence/absence of orders (especially in four - pending orders (which is correct) and positions (which is wrong)).
No, it is correct and necessary to have the number of orders and positions by their types at hand. But it is wrong to rely on the absence of any orders only for the signals.
In general, the correct way is to have functions to count orders and positions (one function that fills the structure when the number of orders and positions changes), functions to open/close positions, functions to set orders and alarm functions. Functions of various trawls and getting data from indicators. Plus - ability to compare the data of a position (open or closed) with some values.
Any strategy can be built out of this set.