Bug in Positions.Find

Created at 04 May 2017, 10:28
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!
GA

gareth-h-jones

Joined 03.05.2017

Bug in Positions.Find
04 May 2017, 10:28


I have an algo that creates market orders and then closes the positions when some criteria is met.

If I create the positions using the following : var result1 = ExecuteMarketOrder(TradeType.Sell, Symbol, 10000, "SellPosition");

Then close using  

Position SellPosition = Positions.Find("SellPosition", Symbol);

var result1 = ClosePosition(SellPosition);

Everything works as expected can backtest over 7 years all positions open closed as expected.

However if I create the positions using 

var result1 = ExecuteMarketOrder(TradeType.Sell, Symbol, 10000, "SellPosition",10,10); 

So the position has a stop loss and tp, everything starts ok but after the 3rd call to Positions.Fing does not find a position even though the position was succesfully created.

Just to be clear that is the only line that changes adding a tp and sl, the remainder of the code is exactly the same.

I have also tried by fully populating the method ie (TradeType.Sell, Symbol, 10000, "SellPosition",10,10,3,"some comment"); 

this also fails the only call that works is ExecuteMarketOrder(TradeType.Sell, Symbol, 10000, "SellPosition");

I would be greatfull if you could fix this rather annoying bug.


@gareth-h-jones
Replies

gareth-h-jones
06 May 2017, 11:16

I have finally got to the bottom of the behaviour I am seeing.

If i place the orders with very large SL and TP then they are still available when I call Find.Position.

So it seems their SL or TP are being hit however there is nothing in the logs to suggest the positions are being closed and the history also does not show these positions being closed.

So could someone please tell me how the SL and TP functionality work


@gareth-h-jones