Max open trades - Code not working

Created at 29 Nov 2022, 00:50
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!
VV

vvictord

Joined 10.11.2022

Max open trades - Code not working
29 Nov 2022, 00:50


At the moment I have a code working perfectly but the code only opens one trade at a time. Even if the pattern is recognized after a trade is open, it will not take the trade because of the open trade, and I would like the bot to open those trades as well...

I have a pseudo code but I do not know how to implement it in my code.

IF TradesOpen > x
Open New Trade
ELSE
Do Nothing

 

 

I believe this part of  my code is making it open only one trade though
        protected override void OnPositionOpened(Position openedPosition)
        {
            position = openedPosition;
            counter = 1;
            Trade.ModifyPosition(openedPosition, GetAbsoluteStopLoss(openedPosition, StopLoss), GetAbsoluteTakeProfit(openedPosition, TakeProfit));
        }
        
        protected override void OnPositionClosed(Position position)
        {    
            counter=0;
        }
        
        private double GetAbsoluteStopLoss(Position position, int stopLossInPips)
        {
            return position.TradeType == TradeType.Buy
                ? position.EntryPrice - Symbol.PipSize * stopLossInPips
                : position.EntryPrice + Symbol.PipSize * stopLossInPips;
        }
        
        private double GetAbsoluteTakeProfit(Position position, int takeProfitInPips)
        {
            return position.TradeType == TradeType.Buy
                ? position.EntryPrice + Symbol.PipSize * takeProfitInPips
                : position.EntryPrice - Symbol.PipSize * takeProfitInPips;
        }


@vvictord
Replies

PanagiotisChar
29 Nov 2022, 09:02

Hi there,

The code you posted does not handle any position opening logic.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 


@PanagiotisChar

Shares4us
23 Aug 2024, 11:38

if(Positions.Count > 0) 
{
}
else
{
}

@Shares4us