Counter that count each pair-trade

Created at 15 Feb 2022, 12:12
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!
BL

BlackTrader

Joined 17.01.2020

Counter that count each pair-trade
15 Feb 2022, 12:12


Can somebody help me?

I need a counter that count each pair-trade. 

The problem that I face is the variable counter that I made it count accross all trade in one bot. Where I need is each pair has its own variable counter.

 

How do I do it?


@BlackTrader
Replies

amusleh
16 Feb 2022, 10:01

Hi

Do you mean number of each symbol trades?


@amusleh

BlackTrader
18 Feb 2022, 13:42

RE:

amusleh said:

Hi

Do you mean number of each symbol trades?

Not a number, but a counter that counts how many trade it has already been opened from this bot for each symbol. Then I will store it in comment column, so it will immediately know the running counter for this symbols.

I can imagine that it will works something like this:

Symbol.Counter += 1;

PlaceStopOrder(tradePosition, SymbolName, volumeInUnit, EntryPrice, myLabel, stopLoss, takeProfit, null, "Trade #" + Symbol.Counter);

 

The problem is I don't know how to declare the variable of "Symbol.Counter" like that?


@BlackTrader

amusleh
21 Feb 2022, 08:58

Hi,

All open positions are inside Positions collection and all open pending orders are inside PendingOrders collection.

You can execute any query on those two for filtering them or transforming them based on your needs.

To get the number of open positions or orders for a symbol you can use these methods (add using System.Linq; on top of your indicator/cBot file):

        private int GetSymbolPositionsCount(string symbolName)
        {
            return Positions.Count(position => position.SymbolName.Equals(symbolName, StringComparison.OrdinalIgnoreCase));
        }

        private int GetSymbolOrdersCount(string symbolName)
        {
            return PendingOrders.Count(order => order.SymbolName.Equals(symbolName, StringComparison.OrdinalIgnoreCase));
        }

 


@amusleh