Get ClosingPrice details immediately after ClosePosition? How?
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
Replies
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
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:
GL ..
@dleeeq8