Hi
After i use "PositionClose()" and my open position get closed, I want to know ticket of last the order and use "GetLastOrderTicket()" Function as below:
but the ticket returnd is for The last one left. How can i fix it?
If you want to know something about a closed position, you have to work with "deals" not with "orders".
Please make some researches on the forum, there are plenty of topics about similar things.
If you want to know something about a closed position, you have to work with "deals" not with "orders".
Please make some researches on the forum, there are plenty of topics about similar things.Hi
Hi
Thanks alot.
If you want to know something about a closed position, you have to work with "deals" not with "orders".
Please make some researches on the forum, there are plenty of topics about similar things.
But i could'nt solve my problem.
Immediately
after PositionClose() , I cant get profit of last closed position.
After using PositionClose() function, i use HistorySelect() and HistoryDealsTotal(). but the last Deal returned does'nt refers to Last Closed position.
if(!HistorySelect(from,to + 100))
But i could'nt solve my problem.
Immediately
after PositionClose() , I cant get profit of last closed position.
After using PositionClose() function, i use HistorySelect() and HistoryDealsTotal(). but the last Deal returned does'nt refers to Last Closed position.
There are plenty of problems with your code. The 2 main in your specific case is :
1° When PositionClose() returns true, that means the order to close has been successfully sent, not that the position is already close (and
that MT5 is aware of it). In a script you would need to use Sleep(), in an EA better use OnTrade() or OnTradeTransaction().
2° No need to use HistorySelect() (wrongly as noted by fxsaber), and you can't be sure the last index (deals-1) is the one concerning your position.
You know the position ticket, you should use it :
if(HistorySelectByPosition(lastTicket)) { ... }(strictly speeking, a position ID should be use with HistorySelectByPosition(), but in your case is the same as the position ticket anyway).
There are plenty of problems with your code. The 2 main in your specific case is :
1° When PositionClose() returns true, that means the order to close has been successfully sent, not that the position is already close
(and that MT5 is aware of it). In a script you would need to use Sleep(), in an EA better use OnTrade() or OnTradeTransaction().
2° No need to use HistorySelect() (wrongly as noted by fxsaber), and you can't be sure the last index (deals-1) is the one concerning your position.
You know the position ticket, you should use it :
(strictly speeking, a position ID should be use with HistorySelectByPosition(), but in your case is the same as the position ticket anyway).Using Sleep() is not OK in Tester , but when I run the program, it works correctly.
Using Sleep() is not OK in Tester , but when I run the program, it works correctly.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi
After i use "PositionClose()" and my open position get closed, I want to know ticket of the last order and use "GetLastOrderTicket()" Function as below:
but the ticket returnd is for The last one left. How can i fix it?