CT 4.2 - Reverse Order Bug

ClickAlgo's avatar

ClickAlgo since: 05 Feb 2015;

  17 May 2022, 11:34
CT 4.2 - Reverse Order Bug

Hi,

There seems to be an issue with reversing a trade direction using cTrader beta 4.2, I ran this basic test.

namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.None)]
    public class ReverseTest : Robot
    {
        [Parameter(DefaultValue = "Hello world!")]
        public string Message { get; set; }

        protected override void OnStart()
        {
            ExecuteMarketOrderAsync(TradeType.Buy, SymbolName, 50);
        }
        
         protected override void OnBar()
        {
            foreach (var position in Positions.Where(x => (x.SymbolName == Symbol.Name)).Where(x => x.TradeType == TradeType.Buy))
            {
                position.Reverse();
            }
        }
    }
}

What happens is that the order opens for BTCUSD with 50 lots, but when the candle closes (1-min TF) and the position is reversed, a notification states that the order was abnormal and attempted to reverse with double the original trade size.

I also tried ReversePosition(position), and had the same issue.

This works ok with 1 lot

~ Contact us for all your cBot & Indicator development ~
amusleh's avatar

amusleh since: 01 Mar 2021;

  17 May 2022, 14:48

Hi,

It's because your order request volume is higher than symbol maximum allowed volume, in your case the reverse order request volume is 100 while the symbol maximum allowed volume is 50.

It's a bug, thanks for reporting.

Community Developer | Spotware | Telegram: @algodeveloper
amusleh's avatar

amusleh since: 01 Mar 2021;

  18 May 2022, 10:20

Hi,

After discussing this with our team we found that it's not a bug but the expected behavior, when you reverse a position platform opens an opposite direction position with double the volume of original position, if this doubled volume was larger than symbol maximum allowed volume then you will receive an error message and the operation will fail.

In your case as you are using Automate API, you can manually first close the position and then open a new position with same exact volume, this will avoid the issue you are facing.

Community Developer | Spotware | Telegram: @algodeveloper