Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1505

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
It is clear, on mql5 I have everything and works, I wrote how to make this code work on mql4 highlighted in yellow what I wrote, but in places where it is highlighted in red error gives an error of exceeding the limits of the array
Oops, I apologise, I didn't read the first sentence carefully.
Regarding the error: the size of the high and low arrays is set inside the iGetArray() and CopyRates() functions. But there the size should be set to the value of the count variable, which is equal to 300. And further in the loop you want to get access to 1000 items. I think you don't need to call iGetArray() and CopyRates(). It is enough to call
Hello. Thank you for your response. Below is the inserted code as requeted.
I am also trying to implement the process using the onTradeTransaction() function of mql5. The prgram compiles fine still buy the buy limit orders are not deleted when there is no buy trade. I think I am getting the logic wrongly. Please someone should correct me. See code below
Hello. Thank you for your reply. Below is the pasted code as requested.
Hello.
It looks like your code is missing the selection of the position with index i in the loops of searching for open positions. Without it, it is not clear what type of position PositionGetInteger(POSITION_TYPE) returns.
Similarly, you should add position selection to the code of searching for SELL positions.
for (int i = 0; i < totalPositions; i++) { ulong ticket = PositionGetTicket(i); if (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY) { hasOpenBuyPosition = true; break; } }
Hello.
It looks like your code is missing the selection of the position with index i in the loops of searching for open positions. Without it, it is not clear what type of position PositionGetInteger(POSITION_TYPE) returns.
Similarly, you should add position selection to the code of searching for SELL positions.
Thank you Yuriy Bykov. This worked perfectly. Thank you
Oops, I apologise, didn't read the first sentence carefully.
Regarding the error: the size of the high and low arrays is set inside the iGetArray() and CopyRates() functions. But there the size should be set to the value of the count variable, which is equal to 300. And further in the loop you want to get access to 1000 items. I think you don't need to call iGetArray() and CopyRates(). It is enough to call
Thank you, everything worked.
There is an old problem, maybe you can tell me why this happens.
The theme is as follows: we stretch the fibo grid, take the time of the upper bar and the time of the lower bar.
With the help of the obtained indices we get the number of bars between the upper and tender fibo line.
But if we do the same thing through the cycle, we always get one bar less.
How to make it equal?
As you can see on the screen, the upper index of the fibo line = 19... the lower one is 29, it turns out 10 bars, in fact they are 11, the bars method calculated correctly, but the cycle does not... how to be
There is an old problem, maybe you can tell me why this is happening.
The theme is as follows: we pull the fibo grid, take the time of the upper bar and the time of the lower bar.
With the help of the obtained indices we get the number of bars between the upper and tender fibo line.
But if we do the same thing through the cycle, we always get one bar less.
How to make it equal?
As you can see on the screen, the upper index of the fibo line = 19... lower 29, it turns out 10 bars, in fact they are 11, the bars method calculated correctly, but the cycle is not... how to be
Apparently, "fence post problem", https://ru.wikipedia.org/wiki/Ошибка_на_единицу
Hi, I am still quite new to MQL5 programming and I am stuck writing the code for a grid EA. Basically, I want the EA to do the following:
Step 1. If there are no open positions and pending orders, the EA should call the OpenNewTrade() function
Step 2. While there are open positions or pending orders, the EA should close all other sell positions and delete all buy limit orders whenever a sell position hits take profit. Also, it should close all other buy positions and delete all sell limit orders whenever a buy position hits take profit.
Step 3. If step 2 above is properly executed, there will be no more open positions and pending orders, therefore, step 1 gets called again in a loop.
PROBLEM
==========
All functions work fine except that the function to close positions as in step 2 above isn't working properly so I don't know if there is an error in the logic of the code. For instance, whenever a sell position hits take profit, the buy limit orders are deleted correctly but the other sell position(s) gets deleted along with buy position(s). this is not supposed to be so as I want the EA to function strictly according to step 2. Below is the code for the EA:
Also I don't know how to have the EA set its name as trade comments. It will be nice if you could help me with it as I will like the trades from this EA differentiated from trades placed by other EAs. Thank you.Help for a beginner. I can't figure out how to convert a string.
How to replace the characters in "var_1" substring from the given index, with the characters "var_2'' ?
A Sell position is closed with a Buy transaction.
This code checks if the Sell position is closed.
m_deal.DealType() == DEAL_TYPE_BUY
Try it like this.
In addition, you have the flag of deleting positions and orders, after the first deletion is always true, because nowhere in the code you do not make it false after deleting positions and orders.
Logically, it should be like this.