Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1863
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
When the exit/closing condition occurs, we should add the ticket to the array. Then, if the array is not empty, the program will loop through it, calling OrderClose for each ticket. Then check existence of each ticket, and remove it from the list. Repeat these actions at 1-3 second intervals until the list is empty.
Hello.
I need to calculate the net profit of the Expert Advisor at the end of work. I run a loop on OrdersHistoryTotal() in OnDeinit and add OrderProfit().
Profit=Profit+OrderProfit();
But in the end the profit is different from the one reported in the tester. I have found out that the point value differs on a part of orders.
What is the reason for this? Spread is set manually in the tester.
Hello.
I need to calculate the net profit of the Expert Advisor at the end of work. I run a loop on OrdersHistoryTotal() in OnDeinit and add OrderProfit().
Profit=Profit+OrderProfit();
But in the end the profit is different from the one reported in the tester. I have found out that the point value differs on a part of orders.
What is the reason for this? The spread is set manually in the tester.
Swap and commission were forgotten to be added! The spread is already taken into account since it is always between the entry and exit prices.
Swap and commission have been forgotten to be added! The spread is already taken into account as it is always between the entry price and the exit price.
Oh, that's right! Thank you very much!!! )
Can you tell me what the problem is, the code should close orders and if they are missing it should open a new one.
But for some reason, it closes only 1 order and stops until next signal.
2022.01.17 16:22:08.389 2022.01.04 08:00:00 e: Signal 1.1322 < clos 1.1304 ExistPosSell 0
2022.01.17 16:22:08.389 2022.01.04 08:00:00 e: Signal 1.1322 > clos 1.1304 ExistPosBuy 1
2022.01.17 16:22:08.366 2022.01.04 08:00:00 e: Signal 1.1325 < clos 1.1306 ExistPosSell 0
2022.01.17 16:22:08.366 2022.01.04 04:00:00 e: Signal 1.1325 > clos 1.1306 ExistPosBuy 1
2022.01.17 16:22:08.327 2022.01.04 2022.01.04 00:00:00 e: Signal 1.1326 < clos 1.1296 ExistPosSell 0
2022.01.17 16:22:08.327 2022.01.04 00:00:00 e: Signal 1.1326 > clos 1.1296 ExistPosBuy 1
2022.01.17 16:22:08.298 2022.01.03 20:00:00 e: Signal 1.1328 < clos 1.1283 ExistPosSell 0
2022.01.17 16:22:08.298 2022.01.03 20:00:00 e: close #1 buy 0.01 EURUSD at 1.13598 at price 1.12831
2022.01.17 16:22:08.298 2022.01.03 20:00:00 e: Signal 1.1328 > close 1.1283 ExistPosBuy 1
2022.01.17 16:22:08.190 2022.01.03 16:00:00 e: open #4 buy 0.01 EURUSD at 1.13512 ok
2022.01.17 16:22:08.190 2022.01.03 16:00:00 e: Signal 1.134 < close 1.135 ExistPosSell 0
2022.01.17 16:22:08.190 2022.01.03 16:00:00 e: Signal 1.134 > close 1.135 ExistPosBuy 1
I recently wrote an alert:#18550. But it can be improved by adding SendNotification:
Add the lines, which I have highlighted to the source code, drop it in the Indicators folder and compile it. This indicator can be added to the chart as many times as you want and receive signals when different levels are crossed. The code was finalized online. The result is not verified.
Forum on trading, automated trading systems & strategy testing
Any questions from newbies on MQL4 and MQL5, help and discussion on algorithms and codes
GlaVredFX, 2022.01.17 18:59
I'm looking for the code to close orders and if i don't see any, i will open a new order.
But for some reason, it closes only 1 order and stops before the next signal.
2022.01.17 16:22:08.389 2022.01.04 08:00:00 e: Signal 1.1322 < clos 1.1304 ExistPosSell 0
2022.01.17 16:22:08.389 2022.01.04 08:00:00 e: Signal 1.1322 > clos 1.1304 ExistPosBuy 1
2022.01.17 16:22:08.366 2022.01.04 08:00:00 e: Signal 1.1325 < clos 1.1306 ExistPosSell 0
2022.01.17 16:22:08.366 2022.01.04 04:00:00 e: Signal 1.1325 > clos 1.1306 ExistPosBuy 1
2022.01.17 16:22:08.327 2022.01.04 2022.01.04 00:00:00 e: Signal 1.1326 < clos 1.1296 ExistPosSell 0
2022.01.17 16:22:08.327 2022.01.04 00:00:00 e: Signal 1.1326 > clos 1.1296 ExistPosBuy 1
2022.01.17 16:22:08.298 2022.01.03 20:00:00 e: Signal 1.1328 < clos 1.1283 ExistPosSell 0
2022.01.17 16:22:08.298 2022.01.03 20:00:00 e: close #1 buy 0.01 EURUSD at 1.13598 at price 1.12831
2022.01.17 16:22:08.298 2022.01.03 20:00:00 e: Signal 1.1328 > close 1.1283 ExistPosBuy 1
2022.01.17 16:22:08.190 2022.01.03 16:00:00 e: open #4 buy 0.01 EURUSD at 1.13512 ok
2022.01.17 16:22:08.190 2022.01.03 16:00:00 e: Signal 1.134 < close 1.135 ExistPosSell 0
2022.01.17 16:22:08.190 2022.01.03 16:00:00 e: Signal 1.134 > close 1.135 ExistPosBuy 1
If you pay a little more attention to your question and your code, you will see for yourself.
The question is that the 1 most profitable order should close on 1 bar and then we wait for a new bar and close 1 profitable order again. We should not close all of them at once.
This means we close on the first bar, but nothing happens on the next bar.
The issue there is that the 1 most profitable order should close on 1 bar, then wait for a new bar and close 1 profitable order again. You should not close all of them at once.
Then you have to formulate your questions correctly. You have only 1 signal. You will get only 1 signal at the opening of a new bar. 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. Again, if there is a signal.