MT5 EA: Incorrect POSITION_TYPE retrieved

 
Hi,

Using an EA , I'm opening a SELL position and then retrieve the order type.

But strange enough when I read the POSITION_TYPE it says it's a BUY position !!!!
What's wrong ?


#include <Trade/Trade.mqh>
CTrade myTrade;      //my trade object


//---
int OnInit()
{

        double v_Bid = SymbolInfoDouble(Symbol(),SYMBOL_BID);
        double v_TP = 0.0;
        double v_SL = 0.0;
        double v_Lots = 1.0;
           
        myTrade.Sell(v_Lots, Symbol(), v_Bid, v_SL, v_TP, "test");
        

        ENUM_POSITION_TYPE   pos_type=NULL;       // Position type

        //Retrieve position type        
        pos_type       =(ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);
        
        if(pos_type == POSITION_TYPE_SELL)
                Print("It's a SELL position");
        else if(pos_type == POSITION_TYPE_BUY)
                Print("It's a BUY position");


//---
   return(INIT_SUCCEEDED);
}



2020.06.15 09:50:02.328	Core 1	2020.06.12 00:00:00   It's a BUY position
 
Joao Paulo Ferreira Fortes:
Hi,

Using an EA , I'm opening a SELL position and then retrieve the order type.

But strange enough when I read the POSITION_TYPE it says it's a BUY position !!!!
What's wrong ?



you read the position type in wrong way, 

you can get the results with myTrade. and choose what you need

 
Joao Paulo Ferreira Fortes:
Hi,

Using an EA , I'm opening a SELL position and then retrieve the order type.

But strange enough when I read the POSITION_TYPE it says it's a BUY position !!!!
What's wrong ?



The issue with this is that you havent specified which position you want to get information about .

Perhaps if you first select it with 

PositionSelect(_Symbol)

it will work

 
Stanislav Ivanov:

The issue with this is that you havent specified which position you want to get information about .

Perhaps if you first select it with 

it will work

 Or you can run a  loop though all positions to find a specific one

 
Thanks amando and Stanislav ,

I will loop through the positions and return the order details.

Cheers,

JP.

Reason: