Max Position Limit

Created at 12 Oct 2022, 07: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!
KU

kurtisnauss

Joined 08.06.2022

Max Position Limit
12 Oct 2022, 07:12


Hi,

I currently have a parameter that limits the number of positions the bot will open at a time. However, I am unable to use it the way it is written to run the bot on multiple pairs. 

This is the code I currently have:

        [Parameter("Position Limit", MinValue = 1, MaxValue = 5, Step = 1, Group = "Risk Management")]
        public int PositionLimit { get; set; }


        if (Positions.Count < PositionLimit && ...)

Is there a way to write this so it looks strictly at the SymbolName instead and counts the position it has open rather than the account as a whole?

Thank you


@kurtisnauss
Replies

Waxy
12 Oct 2022, 08:14

Assign a label to the positions, it should be an unique label per instance, so there's no risk of conflict.

Example

private string _label;

protected override void OnStart()
{
  _label = "BotName" + Server.Time.Ticks;
}

//Then everytime you trade use this label, i.e. and check for positions with that label

protected override void OnBar()
{
  if (Positions.Count(x => x.Label == _label) < 5)
    ExecuteMarketOrder(TradeType.Buy, SymbolName, 10000, _label, InputStopLoss, InputTakeProfit);
}

 


@Waxy

PanagiotisChar
12 Oct 2022, 08:22

Hi there, 

An easier option is the below

Positions.Count(x => x.SymbolName == SymbolName)

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 


@PanagiotisChar

kurtisnauss
13 Oct 2022, 04:29

RE:

PanagiotisChar said:

Hi there, 

An easier option is the below

Positions.Count(x => x.SymbolName == SymbolName)

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 

 

Works like a charm... Thank you!


@kurtisnauss