Positions.Count for different Symbol

Created at 26 Mar 2014, 10:58
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!
Forex19's avatar

Forex19

Joined 13.06.2013

Positions.Count for different Symbol
26 Mar 2014, 10:58


I need a command that counts only the positions of a specific Symbol. 

Positions.Count But, as I understand it, counts "Total number of open positions". 

There is another method that I can use for my needs?


@Forex19
Replies

Spotware
26 Mar 2014, 11:20

Please look at the following example:

var eurUsdPositionsCount = Positions.Count(p => p.SymbolCode == "EURUSD");

 


@Spotware

Forex19
26 Mar 2014, 11:32

RE:

Spotware said:

Please look at the following example:

var eurUsdPositionsCount = Positions.Count(p => p.SymbolCode == "EURUSD");

 

So if I want to have separate count for two Symbol, should I use:

var eurUsdPositionsCount = Positions.Count(p => p.SymbolCode == "EURUSD");

and

var eurGbpPositionsCount = Positions.Count(p => p.SymbolCode == "EURGBP");

is correct?


@Forex19

Spotware
26 Mar 2014, 11:47

RE: RE:

Forex19 said:

Spotware said:

Please look at the following example:

var eurUsdPositionsCount = Positions.Count(p => p.SymbolCode == "EURUSD");

 

So if I want to have separate count for two Symbol, should I use:

var eurUsdPositionsCount = Positions.Count(p => p.SymbolCode == "EURUSD");

and

var eurGbpPositionsCount = Positions.Count(p => p.SymbolCode == "EURGBP");

is correct?

Yes, it is correct.


@Spotware

Forex19
26 Mar 2014, 18:22

RE:

Spotware said:

Please look at the following example:

var eurUsdPositionsCount = Positions.Count(p => p.SymbolCode == "EURUSD");

 

Why gives me this error?:

Error CS1955: Non-invocable member 'cAlgo.API.Positions.Count' cannot be used like a method.

 


@Forex19

Spotware
27 Mar 2014, 09:09

RE: RE:

Forex19 said:

Spotware said:

Please look at the following example:

var eurUsdPositionsCount = Positions.Count(p => p.SymbolCode == "EURUSD");

 

Why gives me this error?:

Error CS1955: Non-invocable member 'cAlgo.API.Positions.Count' cannot be used like a method.

 

You need to add using System.Linq;


@Spotware

Forex19
27 Mar 2014, 11:38

RE: RE: RE:

Spotware said:

You need to add using System.Linq;

I did not use System.Linq, now does not give me more error.

Can be used in Positions.Count a filter on the label instead of the Symbol?

 


@Forex19

Spotware
27 Mar 2014, 12:08

Yes, you can:

var myLabelCount = Positions.Count(p => p.Label == "some label");

Another way to calculate positions with specific label:

var myLabelCount = Positions.FindAll("some label").Length;

 


@Spotware