Topics
08 Aug 2021, 20:29
 1052
 3
08 Aug 2021, 20:09
 0
 1084
 2
Replies

Abstract
31 Aug 2021, 00:34 ( Updated at: 21 Dec 2023, 09:22 )

RE: RE: RE:

Hello,

I've had the following error message trying to find the bug:

The last version of my robot is "naked" -shown below- but still with the same problem: an error is thrown for high steps in parameters. Maybe my Ctrader is corrupted... I would appreciate an answer to resolve this problem. 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.FullAccess)]
    public class TAGLAXerrr : Robot
    {
        [Parameter("Dx", Group = "Ind21", DefaultValue = 10, MinValue = 0)]
        public double Dx { get; set; }

        protected override void OnStart()
        {
        }

        //se ejecuta cada inicio de vela
        protected override void OnBar()
        {

        }

    }
}

 

 


@Abstract

Abstract
29 Aug 2021, 03:03

RE: RE:

The last version is still with the same error. If Dx Step is 5 works fine. It DX Step is 10 works wrong:

 

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.FullAccess)]
    public class TAGLAXerrr : Robot
    {
        [Parameter("Bot Name", Group = "Configuration", DefaultValue = "TAGLAX")]
        public String BotName { get; set; }
        [Parameter("Label Suffix", Group = "Configuration", DefaultValue = DEFAULT_LABEL)]
        public String Label { get; set; }
        [Parameter("Config File", Group = "Configuration", DefaultValue = DEFAULT_CONFIGFILENAME)]
        public String ConfigFile { get; set; }
        [Parameter("Stop Loss VUD", Group = "Finance", DefaultValue = 2.8)]
        public double StopLossFactor { get; set; }
        [Parameter("Profit/Risk Factor", Group = "Finance", DefaultValue = 1.0)]
        public double ProfitRiskFactor { get; set; }
        [Parameter("Max Spread", Group = "Finance", DefaultValue = 1.0)]
        public double MaxSpread { get; set; }
        //------------------Params. Indicadores-----------------------
        [Parameter("Ax", Group = "Ind", DefaultValue = 0.6, MinValue = 0)]
        public double Ax { get; set; }
        [Parameter("Bx", Group = "Ind", DefaultValue = 0.2, MinValue = 0)]
        public double Bx { get; set; }
        [Parameter("Cx", Group = "Ind", DefaultValue = 1.0, MinValue = 0)]
        public double Cx { get; set; }
        [Parameter("Dx", Group = "Ind21", DefaultValue = 10, MinValue = 0)]
        public double Dx { get; set; }
        [Parameter("Ex", Group = "Ind21", DefaultValue = 0.1, MinValue = 0)]
        public double Ex { get; set; }
        //--------------------Time Indicadores------------------------
        [Parameter("Start Hour", Group = "Time", DefaultValue = 0, MinValue = 0, MaxValue = 24)]
        public int StartHour { get; set; }
        [Parameter("End Hour", Group = "Time", DefaultValue = 24, MinValue = 0, MaxValue = 24)]
        public int EndHour { get; set; }

        private const string DEFAULT_LABEL = "Default";
        private const string DEFAULT_CONFIGFILENAME = "config";
        private const int VUD_PERIOD = 50;

        private AverageTrueRange atr;
        private SimpleMovingAverage smaATR;

        protected override void OnStart()
        {
            atr = Indicators.AverageTrueRange(14, MovingAverageType.Exponential);
            smaATR = Indicators.SimpleMovingAverage(atr.Result, VUD_PERIOD);
        }

        //se ejecuta cada inicio de vela
        protected override void OnBar()
        {

        }

    }
}

 


@Abstract

Abstract
28 Aug 2021, 15:41 ( Updated at: 29 Aug 2021, 03:06 )

RE:

I've deleted many lines in order to find the bug, even I've replaced my class TradeException -using only the class Exception- but nothing changes. I've found the solution but it's so strange: when the value of the step in the parameter Dx is 5 then the bot works fine. I cannot understand this behaviour, maybe my Ctrader is corrupted and I need to install it again...

I show the last version of my bot -with the same problem-

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

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public class TAGLAXerrr : Robot
    {
        [Parameter("Bot Name", Group = "Configuration", DefaultValue = "TAGLAX")]
        public String BotName { get; set; }
        [Parameter("Label Suffix", Group = "Configuration", DefaultValue = DEFAULT_LABEL)]
        public String Label { get; set; }
        [Parameter("Config File", Group = "Configuration", DefaultValue = DEFAULT_CONFIGFILENAME)]
        public String ConfigFile { get; set; }
        [Parameter("Stop Loss VUD", Group = "Finance", DefaultValue = 2.8)]
        public double StopLossFactor { get; set; }
        [Parameter("Profit/Risk Factor", Group = "Finance", DefaultValue = 1.0)]
        public double ProfitRiskFactor { get; set; }
        [Parameter("Max Spread", Group = "Finance", DefaultValue = 1.0)]
        public double MaxSpread { get; set; }
        //------------------Params. Indicadores-----------------------
        [Parameter("Ax", Group = "Ind", DefaultValue = 0.6, MinValue = 0)]
        public double Ax { get; set; }
        [Parameter("Bx", Group = "Ind", DefaultValue = 0.2, MinValue = 0)]
        public double Bx { get; set; }
        [Parameter("Cx", Group = "Ind", DefaultValue = 1.0, MinValue = 0)]
        public double Cx { get; set; }
        [Parameter("Dx", Group = "Ind21", DefaultValue = 10, MinValue = 0)]
        public double Dx { get; set; }
        [Parameter("Ex", Group = "Ind21", DefaultValue = 0.1, MinValue = 0)]
        public double Ex { get; set; }
        //--------------------Time Indicadores------------------------
        [Parameter("Start Hour", Group = "Time", DefaultValue = 0, MinValue = 0, MaxValue = 24)]
        public int StartHour { get; set; }
        [Parameter("End Hour", Group = "Time", DefaultValue = 24, MinValue = 0, MaxValue = 24)]
        public int EndHour { get; set; }

        private const string PATH = "c:\\Trading\\";
        private const string DEFAULT_LABEL = "Default";
        private const string DEFAULT_CONFIGFILENAME = "config";
        private const int VUD_PERIOD = 50;

        private string label;
        private string configFile = "";

        private AverageTrueRange atr;
        private SimpleMovingAverage smaATR;

        protected override void OnStart()
        {
            try
            {
                if (StopLossFactor == 0)
                    closeBot();

                atr = Indicators.AverageTrueRange(14, MovingAverageType.Exponential);
                smaATR = Indicators.SimpleMovingAverage(atr.Result, VUD_PERIOD);
                initialize();
            } catch (Exception e)
            {
                log(e);
            }
        }

        //se ejecuta cada inicio de vela
        protected override void OnBar()
        {

        }

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

        //==========================================================================
        //                               UTILIDADES
        //==========================================================================

        private void initialize()
        {
            try
            {
                if ((Label == null) || (string.Compare(Label, "Default") == 0) || (Label.Length == 0))
                {
                    label = BotName + Symbol.Name + TimeFrame.ToString();
                }
                else
                    label = Label;

                configFile = PATH + ConfigFile + ".txt";
            } catch (Exception e)
            {
                throw new Exception("Error al inicializar variables", e);
            }
        }

        private void log(Exception ex)
        {
            string message = "";
            if (ex.InnerException != null)
                message = ex.Message + ". " + ex.InnerException.Message;
            else
                message = ex.Message;

            using (StreamWriter w = File.AppendText(PATH + "log.txt"))
            {
                w.Write("\r\n" + BotName + ";" + Label + ";" + Symbol.Name + ";" + TimeFrame.ToString() + ";" + DateTime.Now.ToLongDateString() + ";" + DateTime.Now.ToLongTimeString() + ";" + "" + ";" + message);
            }
        }

        private void closeBot()
        {
            Stop();
        }

        private bool isOperationAllowed()
        {
            bool ret = false;
            try
            {
                int h = Bars.OpenTimes.LastValue.Hour;

                if (isNumber(h))
                {
                    if ((h >= StartHour) && (h <= EndHour))
                        ret = true;
                }
            } catch (Exception e)
            {
                throw new Exception("Error en la lectura de fecha y hora de las barras", e);
            }
            return ret;
        }

        private bool isNumber(double val)
        {
            return !double.IsNaN(val);
        }
    }
}

Any advice would be appreciated. Thank you.


@Abstract

Abstract
12 Aug 2021, 16:02

RE:

PanagiotisCharalampous said:

Hi Abstract,

Can you please provide us with the cBot source code and the optimization settings so that we are able to reproduce this problem?

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

Hello, Panagiotis.

It was my fault. There were some divisions by zero in some situations. I've fixed this issue and now it's working fine.

Thanks a lot.


@Abstract

Abstract
09 Aug 2021, 13:47

RE:

PanagiotisCharalampous said:

Hi Abstract,

cBots are built without source code by default. For the cBots to include the source code, you need to explicitly select the Build with Source Code option.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

I was mistaken.

Thanks a lot.


@Abstract