Did not proceed BadVolume

Created at 01 Nov 2023, 11:33
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!
BK

bksirrah

Joined 01.11.2023

Did not proceed BadVolume
01 Nov 2023, 11:33


Hello,

I am getting this issue in my cBot. Please can you assist? 

using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public class EmaCrossoverRobot : Robot
    {
        [Parameter("MA1 Period", DefaultValue = 9)]
        public int MA1Period { get; set; }

        [Parameter("MA2 Period", DefaultValue = 13)]
        public int MA2Period { get; set; }

        [Parameter("MA3 Period", DefaultValue = 21)]
        public int MA3Period { get; set; }

        [Parameter("MA4 Period", DefaultValue = 55)]
        public int MA4Period { get; set; }

        [Parameter("Leverage (as a decimal)", DefaultValue = 0.10)]
        public double Leverage { get; set; }

        public bool TradeInProgress = false;
        private ExponentialMovingAverage ma1;
        private ExponentialMovingAverage ma2;
        private ExponentialMovingAverage ma3;
        private ExponentialMovingAverage ma4;

        protected override void OnStart()
        {
            Print("Started Bot");
            ma1 = Indicators.ExponentialMovingAverage(MarketSeries.Close, MA1Period);
            ma2 = Indicators.ExponentialMovingAverage(MarketSeries.Close, MA2Period);
            ma3 = Indicators.ExponentialMovingAverage(MarketSeries.Close, MA3Period);
            ma4 = Indicators.ExponentialMovingAverage(MarketSeries.Close, MA4Period);
        }

        protected override void OnTick()
        {
            Print("Tick called");
            Buy();
            Sell();
        }

        protected void Buy()
        {
            double leverage = Leverage;

            double totalEquity = Account.Equity;
            double volumeInUnits = (totalEquity * leverage) / MarketSeries.Close.LastValue;

            Print("Buy test check = " + (ma4.Result.HasCrossedBelow(ma1.Result, 1) &&
                ma4.Result.HasCrossedBelow(ma3.Result, 1) &&
                ma4.Result.HasCrossedBelow(ma2.Result, 1)));
            Print("Trade in progress = " + TradeInProgress);
            Print("MA1 = " + ma1.Result.LastValue + " Crossed " + ma4.Result.HasCrossedBelow(ma1.Result, 1));
            Print("MA2 = " + ma2.Result.LastValue + " Crossed " + ma4.Result.HasCrossedBelow(ma2.Result, 1));
            Print("MA3 = " + ma3.Result.LastValue + " Crossed " + ma4.Result.HasCrossedBelow(ma3.Result, 1));
            Print("MA4 = " + ma4.Result.LastValue);

            if (ma4.Result.HasCrossedBelow(ma1.Result, 1) &&
                ma4.Result.HasCrossedBelow(ma3.Result, 1) &&
                ma4.Result.HasCrossedBelow(ma2.Result, 1) &&
                !TradeInProgress)
            {
                Print("Execute Buy for Symbol = " + Symbol.Code + " Volume = " + volumeInUnits + " EMA Cross UP");
                var result = ExecuteMarketOrder(TradeType.Buy, Symbol, 500, "Buy Order", null, null, null, "EMA Cross UP");

                if (result.IsSuccessful)
                {
                    var position = result.Position;
                    Print("Position entry price is {0}", position.EntryPrice);
                    TradeInProgress = true;
                }
                else
                {
                    Print("Execute Buy for Symbol = " + Symbol.Code + " Volume = " + volumeInUnits + " Did not proceed " + result.Error.Value);
                    TradeInProgress = false;
                }
            }
        }

        protected void Sell()
        {
            double leverage = Leverage;

            double totalEquity = Account.Equity;
            double volumeInUnits = (totalEquity * leverage) / MarketSeries.Close.LastValue;

            Print("Sell test check = " + volumeInUnits);
            Print("Trade in progress = " + TradeInProgress);
            Print("MA1 = " + ma1.Result.LastValue);
            Print("MA2 = " + ma2.Result.LastValue);
            Print("MA3 = " + ma3.Result.LastValue);
            Print("MA4 = " + ma4.Result.LastValue);

            if (ma4.Result.HasCrossedAbove(ma1.Result, 1) &&
                ma4.Result.HasCrossedAbove(ma3.Result, 1) &&
                ma4.Result.HasCrossedAbove(ma2.Result, 1))
            {
                // Close all open positions for the current symbol
                foreach (var position in Positions)
                {
                    if (position.SymbolCode == Symbol.Code)
                        ClosePosition(position);
                }
                TradeInProgress = false;
            }
        }
    }
}


@bksirrah
Replies

PanagiotisCharalampous
02 Nov 2023, 07:10

Hi there,

This means that the volume you are using is not valid for the traded symbol e.g. you cannot trade 500 units on EURUSD. Usually the minimum is 1000.

Best regards,

Panagiotis


@PanagiotisCharalampous