PositionSelectByTicket and Deselect ?

 

Hi everyone

Just as there's a function for selecting a position by ticket "PositionSelectByTicket", there's also a solution for deselecting a position, although I don't think this will be of much use, since according to the documentation, even when a position doesn't exist, you can still retrieve values using the PositionGetDouble() , PositionGetInteger(), and  PositionGetString() functions.

I'll ask anyway in case I miss something

Best Reguards,
ZeroCafeione😊.

Documentation on MQL5: Trade Functions / PositionGetInteger
Documentation on MQL5: Trade Functions / PositionGetInteger
  • www.mql5.com
PositionGetInteger - Trade Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
ZeroCafeine:

Hi everyone

Just as there's a function for selecting a position by ticket "PositionSelectByTicket", there's also a solution for deselecting a position, although I don't think this will be of much use, since according to the documentation, even when a position doesn't exist, you can still retrieve values using the PositionGetDouble() , PositionGetInteger(), and  PositionGetString() functions.

I'll ask anyway in case I miss something

Best Reguards,
ZeroCafeione😊.

At the moment you select a position, the state of the positions parameters is captured and you can access these values with the appropriate functions, PositionGet*

In case the position gets closed or otherwise altered externally, the functions PositionGet* will give you the values from the time PositionSelect* was called...

For an update, you must reselect the position.

No, there is no unselect function available.
 
thank you very much Dominik Egert
Dominik Egert #: In case the position gets closed or otherwise altered externally

This piece of feedback is very constructive for me, so it is imperative to check the return of the PositionSelectByTicket() function. And perhaps, for safety's sake, call up the PositionSelectByTicket function once I've retrieved all my data to make sure the position still exists, Correct me if I'm wrong 😅

Best Reguards,
ZeroCafeine

Dominik Egert
Dominik Egert
  • 2022.03.20
  • www.mql5.com
Trader's profile
 
ZeroCafeine #:
thank you very much Dominik Egert

This piece of feedback is very constructive for me, so it is imperative to check the return of the PositionSelectByTicket() function. And perhaps, for safety's sake, call up the PositionSelectByTicket function once I've retrieved all my data to make sure the position still exists, Correct me if I'm wrong 😅

Best Reguards,
ZeroCafeine

Usually you do a select and then work with the positions data in a loop. Since the processing is very fast, you won't suffer any changes. But it might have edge cases where you need to take this into account.

Generally speaking, your program will always be late to the show, always will have data based on what already has happened. Like price updates. When you get a new tick price, this value is already "old". Still you base your decision on it.

Don't worry to much, just check the return values and error codes for errors and process them accordingly.

 
tks you  Dominik Egert 😉
Dominik Egert
Dominik Egert
  • 2022.03.20
  • www.mql5.com
Trader's profile