BTCUSD Bitcoin with API

Created at 14 Sep 2017, 14:53
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!
ClickAlgo's avatar

ClickAlgo

Joined 05.02.2015

BTCUSD Bitcoin with API
14 Sep 2017, 14:53


Hi Spotware,

I am attempting to submit an order through the API with the ExecuteMarketOrder method, an error is occurring which is coming from your compiled code.

Crashed in OnTick with DivideByZeroException: Attempted to divide by zero.

ExecuteMarketOrder (TradeType.Buy, Symbol, 2, String.Empty, null, null);

Please, can you help me out here.

Paul Hayes
Sales & Marketing
Emailcontact@clickalgo.com
Phone: (44) 203 289 6573
Websitehttps://clickalgo.com


@ClickAlgo
Replies

Spotware
14 Sep 2017, 15:02

Hi Paul,

Thanks for reporting this. Could you please share a cBot that reproduces this issue, as well as the broker on which this happens?

Best Regards,

cTrader Team


@Spotware

ClickAlgo
14 Sep 2017, 15:14

ok, after creating a basic cBot and attempting to execute the code it worked ok, the exception is occurring on the ExecuteMarketOrder line of code in the main cBot project, so I apologise it is not in your assemblies where the problem lies. Looks like the debugging is throwing a wobbly. I should have done the basic test first before posting, sorry about that. :-)


@ClickAlgo

ClickAlgo
14 Sep 2017, 15:23

Hello Again,

Actually, there is a bug, I was correct, it only happens when you attempt a backtest, the sample code is below:

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 NewcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        protected override void OnStart()
        {
            TradeResult result = ExecuteMarketOrder(TradeType.Buy, Symbol, 2, String.Empty, null, null);
        }

        protected override void OnTick()
        {
            // Put your core logic here
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

 


@ClickAlgo

ClickAlgo
14 Sep 2017, 15:26

Broker: IC Markets

Platform: IC Markets cAlgo 2.01


@ClickAlgo

Spotware
14 Sep 2017, 15:33

Hi Paul,

Thanks for the information. We will investigate this and come back to you.

Best Regards,

cTrader Team


@Spotware

ClickAlgo
21 Sep 2017, 17:00 ( Updated at: 21 Dec 2023, 09:20 )

Hi,

Another issue that could be related is that the live spread was 1500 pips, but your maximum in the backtest settings is only 30.


@ClickAlgo

PanagiotisCharalampous
21 Sep 2017, 17:12

Hi Paul,

Thanks for spotting this. We will change this to accept more pips. 

Best Regards,

Panagiotis


@PanagiotisCharalampous

ClickAlgo
21 Sep 2017, 17:16

Hi, Panagiotis,

Thank you :-)


@ClickAlgo

nohejl027@gmail.com
07 Dec 2017, 18:26 ( Updated at: 21 Dec 2023, 09:20 )

RE:

Paul_Hayes said:

Hi Spotware,

I am attempting to submit an order through the API with the ExecuteMarketOrder method, an error is occurring which is coming from your compiled code.

Crashed in OnTick with DivideByZeroException: Attempted to divide by zero.

ExecuteMarketOrder (TradeType.Buy, Symbol, 2, String.Empty, null, null);

Please, can you help me out here.

Paul Hayes
Sales & Marketing
Emailcontact@clickalgo.com
Phone: (44) 203 289 6573
Websitehttps://clickalgo.com

I am getting the same error. Is there any news about this issue?


@nohejl027@gmail.com

ap11
08 Dec 2017, 10:00 ( Updated at: 21 Dec 2023, 09:20 )

RE: RE:

Hi,

The problem is that cAlgo does not support decimal volumes. All volumes in cAlgo API has type long. It causes following issues with BTCUSD:

  • 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.

 

nohejl027@gmail.com said:

Paul_Hayes said:

Hi Spotware,

I am attempting to submit an order through the API with the ExecuteMarketOrder method, an error is occurring which is coming from your compiled code.

Crashed in OnTick with DivideByZeroException: Attempted to divide by zero.

ExecuteMarketOrder (TradeType.Buy, Symbol, 2, String.Empty, null, null);

Please, can you help me out here.

Paul Hayes
Sales & Marketing
Emailcontact@clickalgo.com
Phone: (44) 203 289 6573
Websitehttps://clickalgo.com

I am getting the same error. Is there any news about this issue?

 


@ap11