Empty "Positions" collection

Created at 25 Feb 2016, 22:37
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!
SV

svobod8

Joined 25.02.2016

Empty "Positions" collection
25 Feb 2016, 22:37


Hi,

apparently  I don't get how the Positions collection work. Running this robot on EURUSD pair prints "Positions: 0" even though the order was fullfiled and neither its TakeProfit nor its StopLoss was reached (thus the position exists).

public class Tutorial : Robot
    {
        private int orders = 0;

        protected override void OnTick()
        {
            if (orders == 0)
            {
                PlaceLimitOrder(TradeType.Buy, Symbol, 1000, 0.5, "buy order", 1000, 1000);
                orders++;
            }
            else
            {
                Print("Positions: ", Positions.Count); // always prints out "Positions: 0"
            }
        }
    }

Could you explain or point me towards an explanation?

Thank you,

Jaromir


@svobod8
Replies

svobod8
28 Feb 2016, 22:21

RE:

Bump :), anybody?

Hi,

apparently  I don't get how the Positions collection work. Running this robot on EURUSD pair prints "Positions: 0" even though the order was fullfiled and neither its TakeProfit nor its StopLoss was reached (thus the position exists).

public class Tutorial : Robot
    {
        private int orders = 0;

        protected override void OnTick()
        {
            if (orders == 0)
            {
                PlaceLimitOrder(TradeType.Buy, Symbol, 1000, 0.5, "buy order", 1000, 1000);
                orders++;
            }
            else
            {
                Print("Positions: ", Positions.Count); // always prints out "Positions: 0"
            }
        }
    }

Could you explain or point me towards an explanation?

Thank you,

Jaromir

 


@svobod8

Spotware
29 Feb 2016, 17:52

Dear Trader,

The Positions.Count prints zero positions because you have no open positions. 

You open limit orders in the previous line. A limit order is an Order and when it's filled a Position opens.

Please have a look at the ExecuteMarketOrder,  API Reference, API Programmers Guides sections of cTDN.


@Spotware

Waxy
29 Feb 2016, 20:06

as Spotware said,

you should check PendingOrders.Count instead


@Waxy