PositionSelect() function is returning false when I create 2 open positions(1 Buy and 1 Sell) for the same SYMBOL.
Hi All,
Can anyone here please tell me why the PositionSelect() function is returning false when I create 2 open positions(1 Buy and 1 Sell) for the same SYMBOL.. My objective is to manage each position's profit individually.
I am unable to do so as the function PositionSelect() is returning 'false'. When I create my first open position(Buy) the function PositionsTotal()=1. After creating a second position (Sell), PositionsTotal()=0 and eventually PositionSelect() returns false.
Does anyone have a solution for this situation?
Note: Both positions are for the same 'SYMBOL'.
Thank you,
Raj
Show your code. Describe the situation at the time the code was run (how many positions are open, which positions are open).
I wrote a short example:
//+------------------------------------------------------------------+ //| PositionsTotal PositionSelect.mq5 | | //+------------------------------------------------------------------+ #property version "1.00" //--- input parameters input int Input1=9; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- Comment(""); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- ResetLastError(); bool position_select=PositionSelect(Symbol()); string text=""; if(position_select) text="PositionSelect \"true\", selected position (ticket) "+IntegerToString(PositionGetInteger(POSITION_TICKET)); else text="PositionSelect \"false\", ERROR: "+IntegerToString(GetLastError()); Comment("Number of open positions: ",PositionsTotal(),"\n",text); //--- } //+------------------------------------------------------------------+
Trading environment: BUY 0.03 and SELL 0.01 are open on the USDPLN symbol. The EA is launched on USDJPY. Result - everything works correctly
Raj:
Hi Vladimir Karputov,thank you to get back but the PositionSelect is false is in your screenshot.
Raj:
Hi Vladimir Karputov ,thank you to get back but the PositionSelect is false is in your screenshot.
Everything is correct. I showed you that everything works absolutely correctly.
We carefully read:
Trading environment: BUY 0.03 and SELL 0.01 are open on the USDPLN symbol. The EA is launched on USDJPY.
void OnTick() { //--- ResetLastError(); bool position_select=PositionSelect(Symbol())Result - everything works correctly
Everything is correct. I showed you that everything works absolutely correctly.
We carefully read:
Trading environment: BUY 0.03 and SELL 0.01 are open on the USDPLN symbol. The EA is launched on USDJPY.
Result - everything works correctly
The PositionSelect() function must return true. It's not the case bros. See the definition, it returns false only when it fails.
PositionSelect
Chooses an open position for further working with it. Returns true if the function is successfully completed. Returns false in case of failure.
The PositionSelect() function must return true. It's not the case bros. See the definition, it returns false only when it fails.
PositionSelect
Chooses an open position for further working with it. Returns true if the function is successfully completed. Returns false in case of failure.
I’m not your brother. Do you even read the help?
PositionSelect
Chooses an open position for further working with it. Returns true if the function is successfully completed. Returns false in case of failure. To obtain information about the error, call GetLastError().
bool PositionSelect( string symbol // Symbol name );
Parameters
symbol
[in] Name of the financial security.
Pay attention to the parameter
string symbol // Symbol name
Now read ATTENTIVELY my example:
Trading environment: BUY 0.03 and SELL 0.01 are open on the USDPLN symbol. The EA is launched on USDJPY.
void OnTick() { //--- ResetLastError(); bool position_select=PositionSelect(Symbol())
Result - everything works correctly
- www.mql5.com
I’m not your brother. Do you even read the help?
PositionSelect
Chooses an open position for further working with it. Returns true if the function is successfully completed. Returns false in case of failure. To obtain information about the error, call GetLastError().
Parameters
symbol
[in] Name of the financial security.
Pay attention to the parameter
Now read ATTENTIVELY my example:
Trading environment: BUY 0.03 and SELL 0.01 are open on the USDPLN symbol. The EA is launched on USDJPY.
Result - everything 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 All,
Can anyone here please tell me why the PositionSelect() function is returning false when I create 2 open positions(1 Buy and 1 Sell) for the same SYMBOL.. My objective is to manage each position's profit individually.
I am unable to do so as the function PositionSelect() is returning 'false'. When I create my first open position(Buy) the function PositionsTotal()=1. After creating a second position (Sell), PositionsTotal()=0 and eventually PositionSelect() returns false.
Does anyone have a solution for this situation?
Note: Both positions are for the same 'SYMBOL'.
Thank you,
Raj