ulong ticket = PositionGetTicket(i); if (!PositionSelectByTicket(ticket)) {
You do not need PositionSelectByTicket. PositionGetTicket selects the position already.
if (!PositionGetInteger(POSITION_MAGIC, magicNumber)){
PositionGetInteger return integer type not boolean type. Study the documentation.
floatingPNL += PositionGetDouble(POSITION_PROFIT);
You need deals' commision and POSITION_SWAP for a better estimate of unrealized profit.
You do not need PositionSelectByTicket. PositionGetTicket selects the position already.
PositionGetInteger return integer type not boolean type. Study the documentation.
You need deals' commision and POSITION_SWAP for a better estimate of unrealized profit.
i try with the comments, but the function it's called every tick ( ihmo is not good for the perfomance )
Cycling all trades every tick is not a problem as long as you don't work with a lot of opened trades at the same time.
Anyway you can choose to use the function to check only once per bar, or only if the amount of opened trades changes, but you will not be able to get the instant profit/loss of each one of your trades.
- 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, i'm new here creating a new topic, but i search a lot of things. In special this problem if can we help me
this is mi function to get current PNL, but i think is not the best way because the functions is called in the tick function, does exist the better way?, searching i think found a possible solution.
in this thread https://www.mql5.com/en/forum/364683#comment_21260716
thx for yours reply's