Get ClosingPrice details immediately after ClosePosition? How?

Created at 02 Aug 2017, 20:29
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
CT

ctid320188

Joined 19.04.2017

Get ClosingPrice details immediately after ClosePosition? How?
02 Aug 2017, 20:29


Hi,

When I call ClosePosition inside my Robot I get back a TradeResult object:

TradeResult result = ClosePosition(position);

which has a Position object inside it. All good and I can get things like the SymbolCode, EntryPrice etc but how on earth do I get the ClosingPrice, ClosingTime etc etc

I can see these details in the HistoricalTrade object but if I try and find my closed position immediately after I've closed it by doing:

HistoricalTrade historic = History.FindLast("mylabel")

it does not find the Historic entry - guessing the Historic is a bit delayed in being added?

Is there a way to get these ClosingPrice, ClosingTime etc details immediately after calling T

radeResult result = ClosePosition(position);

Thanks in advance

Ro


@ctid320188
Replies

dleeeq8
03 Aug 2017, 00:37

i see there is no option for closingPrice .. but here is a way give you the close or "near" close price

Change = pips * Symbol.PipSize , so the 5pips will be 0.0005 based on symbol

if trade is sell:  reverse the Change like this: Change = ( Change - ( Change * 2 ) ) 

EntryPrice + Change = ClosePrice

Code For Test:

var entryPrice = position.EntryPrice;
var change = (position.TradeType == TradeType.Buy ? position.Pips : position.Pips - (position.Pips * 2)) * Symbol.PipSize;
var closePrice = entryPrice + change;
Print(entryPrice.ToString("0.0000") + " " + change.ToString("0.0000") + " " + closePrice.ToString("0.0000"));
     

 

GL ..


@dleeeq8

bart1
03 Aug 2017, 11:56

After ClosePosition executed, Position.Pips is updated and have actual result. So you need to calculate close price using position.EntryPrice and position.Pips:

private double GetPositionClosePrice(Position position)
{
    var symbol = MarketData.GetSymbol(position.SymbolCode);
    var closePrice = position.EntryPrice + position.Pips * symbol.PipSize * (position.TradeType == TradeType.Buy ? 1 : -1);
    return closePrice;
}

@bart1

ctid320188
03 Aug 2017, 12:34

Thank you guys for the answers.

This really helps me out loads. Top answers!

Ro


@ctid320188