Cumulative position price

 

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

 
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 ?
 
Malacarne:
Hi, did you try POSITION_PRICE_CURRENT ?
Yes it's the current price (ask/bid)
 
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 ?
 
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
 
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.
 

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. 

 
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);
 
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...
 
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

 
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... 

Reason: