Positions.Find Return Null after the first couple of calls

Created at 03 May 2017, 10:26
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

Positions.Find Return Null after the first couple of calls
03 May 2017, 10:26


I have a simple algo that I am working on at the moment where a call is made to open or close a position and righ at the start 2 variables are set up containing a buy or Sell position.

If a buy position is open and a opposite signal is received the position should close and vice versa

The problem is after the first couple of call the Positions.Find method is returning null even though there is a position open.

So to be clear at the start it is populating my variables with the open positions and then stops.

When a new buy position is created it is always created with the label "BuyPosition" and Sells are created with"SellPosition"

Is there some behaviour that I need to be aware off ?

 

private void OpenClosePosition(char b_type, double current_high, double current_low)
        {
            var BuyPosition = Positions.Find("BuyPosition");
            var SellPosition = Positions.Find("SellPosition");

 

 


@gareth-h-jones
Replies

gareth-h-jones
03 May 2017, 11:11

RE:

gareth-h-jones said:

I have a simple algo that I am working on at the moment where a call is made to open or close a position and righ at the start 2 variables are set up containing a buy or Sell position.

If a buy position is open and a opposite signal is received the position should close and vice versa

The problem is after the first couple of call the Positions.Find method is returning null even though there is a position open.

So to be clear at the start it is populating my variables with the open positions and then stops.

When a new buy position is created it is always created with the label "BuyPosition" and Sells are created with"SellPosition"

Is there some behaviour that I need to be aware off ?

 

private void OpenClosePosition(char b_type, double current_high, double current_low)
        {
            var BuyPosition = Positions.Find("BuyPosition");
            var SellPosition = Positions.Find("SellPosition");

 

I have identified what the issue is 

when I open the position using

var result1 = ExecuteMarketOrder(TradeType.Buy, Symbol, 10000, "BuyPosition", ((Symbol.Ask - stoplossprice_sell) / Symbol.PipSize), ((Symbol.Ask - stoplossprice_sell) / Symbol.PipSize));

But then I try and find the position using  var BuyPosition = Positions.Find("BuyPosition");

For some reason this does not work even though I only have 1 position open with the label "BuyPosition"

If I open using  ExecuteMarketOrder(TradeType.Buy, Symbol, 10000, "BuyPosition");

Then it works I would appreciate it if somone could explain why this doesn't work

 


@gareth-h-jones