OnPositionsOpened cannot retrieve position information

Created at 05 Dec 2013, 00:51
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!
Hyperloop's avatar

Hyperloop

Joined 23.10.2013

OnPositionsOpened cannot retrieve position information
05 Dec 2013, 00:51


protected override void OnStart()
{
    Positions.Opened += OnPositionsOpened;
}

protected override void OnBar()
{
    Symbol XXXYYY = MarketData.GetSymbol("GBPUSD"); 
    ExecuteMarketOrder(TradeType.Buy, XXXYYY, 10000, "Test", 30, 30, 1, "Test1");
}

private void OnPositionsOpened(PositionOpenedEventArgs obj)
{
    string PositionOpened = "Position opened. Label: " + obj.Position.Label + ". ID: " + obj.Position.Id + ". Direction: " + obj.Position.TradeType + ". Volume: " + obj.Position.Volume + ". Entry: " + obj.Position.EntryPrice + ". T/P: " + obj.Position.TakeProfit + ". S/L: " + obj.Position.StopLoss + ". Margin Level: " + Math.Round(Account.Equity / Account.Margin * 100) + "%.";

    Print(PositionOpened);
}

When I run this code, the output is: 

Position opened. Label: Test. ID: 264177. Direction: Buy. Volume: 10000. Entry: 1.50000. T/P: . S/L: . Margin Level: Infinity%.

My question is how come the T/P, S/P and Margin Level information of a position cannot be retrieved while the others can?


@Hyperloop
Replies

Spotware
05 Dec 2013, 11:55

We've checked your code and got the following result:

05/12/2013 04:44:18.686 | Robot "TestOpenPosition" was started successfully for GBPUSD, m1.
05/12/2013 04:45:00.256 | Executing Market Order to Buy 10k GBPUSD (SL: 30, TP: 30, MR: 1)
05/12/2013 04:45:00.490 | → Executing Market Order to Buy 10k GBPUSD (SL: 30, TP: 30, MR: 1) SUCCEEDED, Position PID676961
05/12/2013 04:45:00.490 | Position opened. Label: Test. ID: 676961. Direction: Buy. Volume: 10000. Entry: 1.6351. T/P: 1.6381. S/L: 1.6321. Margin Level: 10396%.

 

For now we can not figure out the reason of the behavior you have.


@Spotware

Hyperloop
05 Dec 2013, 20:24

RE:

Spotware said:

We've checked your code and got the following result:

05/12/2013 04:44:18.686 | Robot "TestOpenPosition" was started successfully for GBPUSD, m1.
05/12/2013 04:45:00.256 | Executing Market Order to Buy 10k GBPUSD (SL: 30, TP: 30, MR: 1)
05/12/2013 04:45:00.490 | → Executing Market Order to Buy 10k GBPUSD (SL: 30, TP: 30, MR: 1) SUCCEEDED, Position PID676961
05/12/2013 04:45:00.490 | Position opened. Label: Test. ID: 676961. Direction: Buy. Volume: 10000. Entry: 1.6351. T/P: 1.6381. S/L: 1.6321. Margin Level: 10396%.

 

For now we can not figure out the reason of the behavior you have.

It is working on your end?


@Hyperloop

Spotware
06 Dec 2013, 17:32

Yes it is. We have not been able to reproduce this. We will let you know if we can identify the reason. 


@Spotware