Getting the error bad volume.

Created at 30 Mar 2021, 17: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!
DO

Dom29600

Joined 05.08.2020

Getting the error bad volume.
30 Mar 2021, 17:12


Hi ,

Trying to make a cBot to place a trade at a chosen price , with risk of 1 percent of my account.

I keep getting an error saying "BadVolume"

Here is the code i am using:-

Thank you.

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

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

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double sellPrice { get; set; }

        [Parameter(DefaultValue = 0.0)]
        public double stopLevel { get; set; }

        [Parameter(DefaultValue = 0.0)]
        public double target { get; set; }

        [Parameter("Account Risk", DefaultValue = 1.0)]
        public double percentRisk { get; set; }

        private double riskPerTrade;

        private double sellLotSize;

        private double distanceInpPipsToStoploss;


 

        protected override void OnStart()
        {

            //----Calculate distance to stop loss in pips------//
            distanceInpPipsToStoploss = stopLevel - sellPrice;

            //----Calculate amount of money to risk on trade----//
            riskPerTrade = Account.Balance * (percentRisk / 100);


            //----Calculate risk about per pip move----//
            sellLotSize = riskPerTrade / distanceInpPipsToStoploss;
        }

 


        protected override void OnTick()
        {
                       PlaceLimitOrder(TradeType.Sell, Symbol, sellLotSize, target, "selltrade");
        }


        protected override void OnStop()
        {
           
        }


    }
}

 

 


@Dom29600
Replies

PanagiotisCharalampous
31 Mar 2021, 08:24

Hi Dom29600,

Try this instead

PlaceLimitOrder(TradeType.Sell, Symbol, Symbol.NormalizeVolumeInUnits(sellLotSize, RoundingMode.Down), targetP, "selltrade");

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous