Download MetaTrader 5

Getting price of open position of other symbols

To add comments, please log in or register
Rian Yeo
15
Rian Yeo  

Hi there, 

 

i am trying to enter a code that would allow me to retrieve the open price of a specific symbol other than the current one being work on.

 

anyone know how do i do that?

 

 my code is something like , i tried Position Select, but on my last line i tried printing the value and it return the price of the current symbol only. 

 

 

PositionSelect(mysymbol);

double BUYTP,SELLTP,CurrentPrice,CurrentTP;

double RiskAmt,AccProfit,AccBalance;

BUYTP=PositionGetDouble(POSITION_PRICE_OPEN)+(TPDistance*_Point);

SELLTP=PositionGetDouble(POSITION_PRICE_OPEN)-(TPDistance*_Point);

RiskAmt=AccountInfoDouble(ACCOUNT_BALANCE)*Risk*-1;

AccProfit=AccountInfoDouble(ACCOUNT_PROFIT);

AccBalance=AccountInfoDouble(ACCOUNT_BALANCE);


Print(mysymbol,"= ",PositionGetDouble(POSITION_PRICE_OPEN)); 

Stanislav Korotky
19835
Stanislav Korotky  
You should check result code of PositionSelect. It may fail if, for example, you specified incorrect mysymbol.
Rian Yeo
15
Rian Yeo  

Hi Marketeer, 

 mysymbol seems to be correct .

 

eg , EURUSD and USDJPY  ,  

 

these codes are in a function so i call the function with this two symbol,

 the print line prints the correct symbol and the code manage to open the chart for mysymbol in this case both EURUSD and USDJPY chart were open

print line:

  EURUSD = 1.2***

USDJPY = 1.2***

 let me do a print result of PositionSelect(mysymbol) see if it comes out the correct one 

 

but in any case is there a syntax or a better method where i can call PositionGetDouble(Position_price_open) to specific symbols?

 regards 

Rian Yeo
15
Rian Yeo  

Solved. 

Thanks  

To add comments, please log in or register