Download MetaTrader 5
To add comments, please log in or register
Have you installed MetaTrader 5? Find out more about it!
Icham Aidibe
9915
Icham Aidibe 2014.05.02 19:24 

Hi there,

If i open a long at x1, x2, x3, i can see in the trade tab that the price change. How to return this value in mql5 ?

POSITION_PRICE_OPEN returns only the initial buying price.


Thanks

Rodrigo Malacarne
Moderator
9847
Rodrigo Malacarne 2014.05.02 20:11  
blouf:

Hi there,

If i open a long at x1, x2, x3, i can see in the trade tab that the price change. How to return this value in mql5 ?

POSITION_PRICE_OPEN returns only the initial buying price.


Thanks

Hi, did you try POSITION_PRICE_CURRENT ?
Icham Aidibe
9915
Icham Aidibe 2014.05.02 20:21  
Malacarne:
Hi, did you try POSITION_PRICE_CURRENT ?
Yes it's the current price (ask/bid)
Rodrigo Malacarne
Moderator
9847
Rodrigo Malacarne 2014.05.02 20:30  
blouf:
Yes it's the current price (ask/bid)
Well, if you're using MT5 the current position price can be retrieved with POSITION_PRICE_OPEN. Are you using MT5 or MT4 ?
Icham Aidibe
9915
Icham Aidibe 2014.05.02 21:30  
Malacarne:
Well, if you're using MT5 the current position price can be retrieved with POSITION_PRICE_OPEN. Are you using MT5 or MT4 ?
MT5, but once again, PRICE_OPEN get the result of the initial buying order only
Alain Verleyen
Moderator
30290
Alain Verleyen 2014.05.02 21:37  
blouf:
MT5, but once again, PRICE_OPEN get the result of the initial buying order only
Not at all. POSITION_PRICE_OPEN gives you the average price, not the initial open price. Please check it.
Rodrigo Malacarne
Moderator
9847
Rodrigo Malacarne 2014.05.02 21:48  

Please try this:

//--- GLOBALS
double avgPrice;   

//--- Inside OnTick, OnTimer or OnCalculate
   if(PositionSelect(_Symbol))
     {
      avgPrice = PositionGetDouble(POSITION_PRICE_OPEN);
     }
   //---
   Print("avgPrice = ",DoubleToString(avgPrice,_Digits));

And tell us what you get. 

Icham Aidibe
9915
Icham Aidibe 2014.05.02 22:21  
Malacarne:

Please try this:

And tell us what you get. 

Yep when selecting the symbol it works like a charm.


BTW,  how to pass a param to a function ? example :

Sell(Lots);
Rodrigo Malacarne
Moderator
9847
Rodrigo Malacarne 2014.05.02 22:31  
blouf:

Yep when selecting the symbol it works like a charm.


BTW,  how to pass a param to a function ? example :

You have to better describe this function...
Icham Aidibe
9915
Icham Aidibe 2014.05.02 22:58  
Malacarne:
You have to better describe this function...
void Sell()
{
   double Bid = SymbolInfoDouble(Symbol(), SYMBOL_BID);
        Trade.PositionOpen(_Symbol, ORDER_TYPE_SELL, Lots, Bid, 0, 0, OrderComment);

}

I want to call it from another function and be allowed to pass how much lot i want : Sell(0.01);

EDIT : if no param use a default value

Rodrigo Malacarne
Moderator
9847
Rodrigo Malacarne 2014.05.02 23:01  
blouf:

I want to call it from another function and be allowed to pass how much lot i want : Sell(0.01);

EDIT : if no param use a default value

Why don't you simply use trade.Sell( ... ) with it's own parameters ?

You don't need to create a void function for that... 

/ /12
To add comments, please log in or register