Replies

dominic.penny.21
09 Jun 2023, 14:22

Thank you firemyst


@dominic.penny.21

dominic.penny.21
21 Apr 2021, 21:12

RE: RE: Screenshot attached

No worries, I found the fault


@dominic.penny.21

dominic.penny.21
21 Apr 2021, 15:06 ( Updated at: 21 Dec 2023, 09:22 )

RE: Screenshot attached

dominic.penny.21 said:

Hi Team,

Could someone help me to understand the above-mentioned error, please?
I'll post the code below - the ALGO works fine when backtesting but when I run it on the demo account with live data it throws out the error.

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 TenMovingAverage : Robot
    {
        [Parameter("Quantity (Lots)", Group = "Volume", DefaultValue = 0.01, MinValue = 0.01, Step = 0.01)]
        public double Quantity { get; set; }

        [Parameter("Enable TakeProfit?", Group = "TakeProfit", DefaultValue = true)]
        public bool useTakeProfit { get; set; }

        [Parameter("Take Profit", Group = "TakeProfit", DefaultValue = 1, MinValue = 1, Step = 1)]
        public double takeProfit { get; set; }

        [Parameter("Enable Stop Loss?", Group = "StopLoss", DefaultValue = true)]
        public bool useStopLoss { get; set; }

        [Parameter("Stop Loss", Group = "StopLoss", DefaultValue = 1, MinValue = 1, Step = 1)]
        public double stopLoss { get; set; }

        private MovingAverage tenMinimum;
        private MovingAverage tenMaximum;

        private double volumeInUnits;

        protected override void OnStart()
        {
            volumeInUnits = Symbol.QuantityToVolumeInUnits(Quantity);
            tenMinimum = Indicators.MovingAverage(Bars.LowPrices, 10, MovingAverageType.Simple);
            tenMaximum = Indicators.MovingAverage(Bars.HighPrices, 10, MovingAverageType.Simple);
        }

        protected override void OnBar()
        {
            if (Positions.Count() > 0)
            {
                if (Bars.LastBar.High >= tenMaximum.Result.LastValue && !useTakeProfit)
                {
                    foreach (var position in Positions)
                    {
                        ClosePosition(position);
                    }
                }
            }

            if (Bars.LastBar.Close <= tenMinimum.Result.LastValue)
            {
                ExecuteMarketOrder(TradeType.Buy, SymbolName, volumeInUnits, "TenMov", (useStopLoss ? stopLoss : double.MaxValue), (useTakeProfit ? takeProfit : double.MaxValue));
            }
        }
    }
}

 


@dominic.penny.21