BTCUSD Order Volume Failure

Created at 04 Dec 2017, 20:23
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!
nobulart's avatar

nobulart

Joined 03.09.2013

BTCUSD Order Volume Failure
04 Dec 2017, 20:23


I'm running cAlgo 2.01 on BTCUSD.
My broker is FXPro.

It would seem that there is some issue with the execution of both market and limit orders in backtesting on BTCUSD.

I've stripped this down to the bare minimum code to demonstrate this:

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class BTCUSDTest : Robot
    {
        protected override void OnStart()
        {
            ExecuteMarketOrder(TradeType.Buy, Symbol, 1, "BTC Test", 100000, 5000, 2000, "BTCUSD Test Trade");
        }
    }
}

The minimum order volume for BTCUSD on FXPro is 0.01BTC. If I attempt to execute a market order with a volume from 1 to 5, I get the following result...

27/11/2017 02:00:00.000 | Backtesting started
27/11/2017 02:00:00.000 | Executing Market Order to Buy 1 BTCUSD (SL: 100000, TP: 5000, MR: 2000)
27/11/2017 02:00:00.000 | Crashed in OnStart with DivideByZeroException: Attempted to divide by zero.
27/11/2017 02:00:00.000 | Backtesting was stopped

Any volume greater than 5 exceeds FXPro's 5 BTC maximum and is rejected as it should be.
Any volume less than 1 also fails because the volume parameter is of type long.


@nobulart
Replies

nobulart
06 Dec 2017, 08:32

I see that most queries on this forum are responded to within 2-24 hours by a Spotware representative. This seems like a relatively straightforward query - is this a bug in the cAlgo code or am I doing something incorrectly? Have I posted this in the wrong place? A response would be very much appreciated. Thank you.


@nobulart

nobulart
06 Dec 2017, 09:47

I'm experiencing the same problem when attempting to place orders on ETHUSD. Placing an order with a volume between 1ETH and 99ETH crashes with a division by zero error as above. Orders for 100ETH or greater don't result in a crash, but the orders aren't executed, resulting in no trades being placed.


@nobulart

ap11
06 Dec 2017, 12:15

RE:

Hi Nobulart,

The problem is that cAlgo does not support decimal volumes. It causes following issues with BTCUSD and ETHUSD:

  • You can't open positions or create pending orders with decimal part via cAlgo APIs
  • You won't get correct value for existing Position, PendingOrder or HistoricalTrade if volume has decimal part
  • Backtesting for this symbols is not working as Symbol.VolumeStep is equal to 0 after casting from double to long. That's why you get DivideByZeroException

We are fixing this issues. But this fixes will be in the next release of cTrader.

Kind Regards,
Andrey

 

nobulart said:

I'm running cAlgo 2.01 on BTCUSD.
My broker is FXPro.

It would seem that there is some issue with the execution of both market and limit orders in backtesting on BTCUSD.

I've stripped this down to the bare minimum code to demonstrate this:

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class BTCUSDTest : Robot
    {
        protected override void OnStart()
        {
            ExecuteMarketOrder(TradeType.Buy, Symbol, 1, "BTC Test", 100000, 5000, 2000, "BTCUSD Test Trade");
        }
    }
}

The minimum order volume for BTCUSD on FXPro is 0.01BTC. If I attempt to execute a market order with a volume from 1 to 5, I get the following result...

27/11/2017 02:00:00.000 | Backtesting started
27/11/2017 02:00:00.000 | Executing Market Order to Buy 1 BTCUSD (SL: 100000, TP: 5000, MR: 2000)
27/11/2017 02:00:00.000 | Crashed in OnStart with DivideByZeroException: Attempted to divide by zero.
27/11/2017 02:00:00.000 | Backtesting was stopped

Any volume greater than 5 exceeds FXPro's 5 BTC maximum and is rejected as it should be.
Any volume less than 1 also fails because the volume parameter is of type long.

 


@ap11

nobulart
06 Dec 2017, 12:29

RE: RE:

Thank you Andrey. I suspected that this might be the case. I look forward to the next update :-)

Andrey Pisarev said:

Hi Nobulart,

The problem is that cAlgo does not support decimal volumes. It causes following issues with BTCUSD and ETHUSD:

  • You can't open positions or create pending orders with decimal part via cAlgo APIs
  • You won't get correct value for existing Position, PendingOrder or HistoricalTrade if volume has decimal part
  • Backtesting for this symbols is not working as Symbol.VolumeStep is equal to 0 after casting from double to long. That's why you get DivideByZeroException

We are fixing this issues. But this fixes will be in the next release of cTrader.

Kind Regards,
Andrey


@nobulart