Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1864
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
Then you have to formulate the questions correctly. You only get 1 signal. And it is at the opening of a new bar. And if there is only 1 signal, how many orders will be closed? And only if the signal appears on a new bar. And, if there is no signal, the orders will be closed on the next bars. And again, if there is a signal.
In such cases a flow chart usually helps. Or we need to describe the algorithm in detail point by point on a piece of paper or in a text file. And only then you will understand how to write your code.
Need function to close 1 order opened first among all available orders. who can share.
So if you've noticed, the algorithm is written in the code.
1) New bar appears
2) If the MA is higher than the previous bar close price, go to step 3 if the MA is below the close price, go to step 4.
3)If we have a BUY position, we close one position with maximum profit in the currency pair.
3.1)If there is no open BUY order,open a SELL position.
4) If we have a BUY position, we close one position with a maximum profit in the currency pair.
4.1)If there is no open SELL order we open a BUY position.
Now again I have a question, what is wrong in this code of the above described algorithm:
This code contains a set of commands. The terminal does not know what you need, it only knows what is written in the code!
Write the buySignal andsellSignal variables globally.A set of commands is written in the code. The terminal does not know what you need, it only knows what is written in the code!
I deleted this message because the problem is that orders should be closed not by profit but by time.
This is because we have profit not always and not always where it should be.
Therefore, we need the function"Close one position opened at the very beginning of all available positions".
I deleted this message, because the problem is that orders should be closed according to time rather than profit.
Because the profit is not always there and not always where it should be.
Therefore, we need the function"Close one position opened at the very beginning of all available positions".
I have added an example of position opening in the timer in the previous post. So that the position is guaranteed to be opened. You can substitute your own function there.
Added an example of a timer position opening in the previous post. So that the position is guaranteed to open. You can substitute your own function there.
But not like this. You need to monitor the result of
or a new function of yours in OnTradeTransaction. And if there are no positions, it will enter. Or write the signal in buySignal orsellSignal and process it in OnTimer as I have shown in the example.
Not so, though. You need to keep track of the result of
or your new function in OnTradeTransaction. And if there are no positions, you should enter. Or write the signal in buySignal orsellSignal and process it in OnTimer as I have shown in the example.
This function is no longer relevant. It is not suitable. Instead of it, we need to substitute the function that will close one order opened first, if it exists.
I do not understand the buySignal andsellSignal variables written on the global scope. But when I try to compile it, it gives me the following error
https://book.mql4.com/ru/trading/orderclose
Good afternoon.
I've certainly read all of this, and I can write out each order separately, but the question was to shorten the code.
Good afternoon.
I've certainly read all of this, and I can write out each order separately, but the question was to shorten the code.
What exactly is the code shortening not working out?