cTrader crash on high number of "Events"

Created at 06 Jun 2020, 06:07
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!
FI

findsameh

Joined 21.06.2015

cTrader crash on high number of "Events"
06 Jun 2020, 06:07


Hello all,

A bot I'm working on modifies stop loss and take profit on every tick. When backtesting, naturally, the number of entries under the "Events" tab can amount to more than a million, resulting in a cTrader crash.

Is there a way to limit the number of entries, or just not display any entries under the "Events" tab? If not can there be a way around this?

Thanks all.

Sameh


@findsameh
Replies

PanagiotisCharalampous
09 Jun 2020, 09:22

Hi Sameh,

Can you post a cBot that reproduces these crashes so that we can check?

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

findsameh
11 Jun 2020, 08:10

RE:

PanagiotisCharalampous said:

Hi Sameh,

Can you post a cBot that reproduces these crashes so that we can check?

Best Regards,

Panagiotis 

Join us on Telegram

 

Dear Panagiotis,

Thank you for your reply. Here's a part of the bot that generates the high number of events (under Events tab) which will eventually cause a crash or a freeze of the platform until the events list is populated, This will be reproduced best when running the default parameters for a 2 year backtest or more.

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

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class toTest : Robot
    {
        [Parameter("Volume", Group = "Trade Parameters", DefaultValue = 10000)]
        public int volume { get; set; }
        [Parameter("Max positions", Group = "Trade Parameters", DefaultValue = 1, MinValue = 0)]
        public int maxPos { get; set; }
        [Parameter("SL (pips)", Group = "Trade Parameters", DefaultValue = 20, MinValue = 0)]
        public double sl { get; set; }
        [Parameter("TP (pips)", Group = "Trade Parameters", DefaultValue = 20, MinValue = 0)]
        public double tp { get; set; }
        [Parameter("No. of evaluated bars", Group = "Trade Parameters", DefaultValue = 30, MinValue = 6)]
        public int evaluatedBars { get; set; }
        [Parameter("Modify SL & TP?", Group = "Modify Stop Loss & Take Profit", DefaultValue = true)]
        public bool modifySlTp { get; set; }
        [Parameter("ATR (14) multiplier", Group = "Modify Stop Loss & Take Profit", DefaultValue = 1)]
        public double atrMultiplier { get; set; }

        string botLabel = "Bot_test";
        private List<double> listOfResPoints = new List<double>();
        private List<double> listOfSupPoints = new List<double>();
        AverageTrueRange atr;
        SimpleMovingAverage sma;
        int countModifiedTpSl;
        double currentAskOnTick;
        double currentBidOnTick;
        double newTp;
        double newSl;

        protected override void OnStart()
        {
            atr = Indicators.AverageTrueRange(14, MovingAverageType.Exponential);
            sma = Indicators.SimpleMovingAverage(Bars.ClosePrices, 14);
        }
        protected override void OnTick()
        {
            currentAskOnTick = Symbol.Ask;
            currentBidOnTick = Symbol.Bid;
            Trades();
            // modifies sl & tp
            if (modifySlTp == true)
            {
                ModifyStopLossTakeProfit();
            }
        }
        private void ModifyStopLossTakeProfit()
        {
            foreach (var _pos in Positions)
            {
                if (_pos.TradeType == TradeType.Buy)
                {
                    newTp = currentBidOnTick + (atr.Result.LastValue * atrMultiplier);
                    newSl = currentBidOnTick - (atr.Result.LastValue * atrMultiplier);
                    _pos.ModifyTakeProfitPrice(newTp);
                    _pos.ModifyStopLossPrice(newSl);
                    countModifiedTpSl++;
                }
                else
                {
                    newTp = currentAskOnTick - (atr.Result.LastValue * atrMultiplier);
                    newSl = currentAskOnTick + (atr.Result.LastValue * atrMultiplier);
                    _pos.ModifyTakeProfitPrice(newTp);
                    _pos.ModifyStopLossPrice(newSl);
                    countModifiedTpSl++;
                }
            }
        }
        private void Trades()
        {
            if (Positions.Count >= maxPos)
                return;
            var currentResValue = ResLineValue(evaluatedBars);
            var currentSupValue = SupLineValue(evaluatedBars);
            List<double> listOfHighs = new List<double>();
            List<double> listOfLows = new List<double>();

            for (int i = 5; i <= evaluatedBars; i++)
            {
                listOfHighs.Add(Bars.HighPrices.Last(i));
                listOfLows.Add(Bars.LowPrices.Last(i));
            }
            // opens long position
            if (currentBidOnTick > currentResValue &&
                sma.Result.IsRising())
            {
                ExecuteMarketOrder(TradeType.Buy, SymbolName, volume, botLabel, sl, tp);
            }
            else
            // opens short position
            if (currentBidOnTick < currentSupValue &&
                sma.Result.IsFalling())
            {
                ExecuteMarketOrder(TradeType.Sell, SymbolName, volume, botLabel, sl, tp);
            }
            listOfHighs.Clear();
            listOfLows.Clear();
        }
        // resistance lines
        private double ResLineValue(int evaluatedBars)
        {
            listOfResPoints.Clear();
            for (int i = 5; i < evaluatedBars + 5; i++)
            {
                var resPoint = Bars.HighPrices.Last(i);
                // populates resistance points
                listOfResPoints.Add(resPoint);
            }
            var resLine = listOfResPoints.Max();
            return resLine;
        }
        // support lines
        private double SupLineValue(int evaluatedBars)
        {
            listOfSupPoints.Clear();
            for (int i = 5; i < evaluatedBars + 5; i++)
            {
                var supPoint = Bars.LowPrices.Last(i);
                // populates support points
                listOfSupPoints.Add(supPoint);
            }
            var supLine = listOfSupPoints.Min();
            return supLine;
        }
        protected override void OnStop()
        {
            Print("No. of times SL & TP modified: {0}", countModifiedTpSl);
        }
    }
}

 


@findsameh

findsameh
16 Jun 2020, 22:21

RE: RE:

findsameh said:

PanagiotisCharalampous said:

Hi Sameh,

Can you post a cBot that reproduces these crashes so that we can check?

Best Regards,

Panagiotis 

Join us on Telegram

 

Dear Panagiotis,

Thank you for your reply. Here's a part of the bot that generates the high number of events (under Events tab) which will eventually cause a crash or a freeze of the platform until the events list is populated, This will be reproduced best when running the default parameters for a 2 year backtest or more.

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

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class toTest : Robot
    {
        [Parameter("Volume", Group = "Trade Parameters", DefaultValue = 10000)]
        public int volume { get; set; }
        [Parameter("Max positions", Group = "Trade Parameters", DefaultValue = 1, MinValue = 0)]
        public int maxPos { get; set; }
        [Parameter("SL (pips)", Group = "Trade Parameters", DefaultValue = 20, MinValue = 0)]
        public double sl { get; set; }
        [Parameter("TP (pips)", Group = "Trade Parameters", DefaultValue = 20, MinValue = 0)]
        public double tp { get; set; }
        [Parameter("No. of evaluated bars", Group = "Trade Parameters", DefaultValue = 30, MinValue = 6)]
        public int evaluatedBars { get; set; }
        [Parameter("Modify SL & TP?", Group = "Modify Stop Loss & Take Profit", DefaultValue = true)]
        public bool modifySlTp { get; set; }
        [Parameter("ATR (14) multiplier", Group = "Modify Stop Loss & Take Profit", DefaultValue = 1)]
        public double atrMultiplier { get; set; }

        string botLabel = "Bot_test";
        private List<double> listOfResPoints = new List<double>();
        private List<double> listOfSupPoints = new List<double>();
        AverageTrueRange atr;
        SimpleMovingAverage sma;
        int countModifiedTpSl;
        double currentAskOnTick;
        double currentBidOnTick;
        double newTp;
        double newSl;

        protected override void OnStart()
        {
            atr = Indicators.AverageTrueRange(14, MovingAverageType.Exponential);
            sma = Indicators.SimpleMovingAverage(Bars.ClosePrices, 14);
        }
        protected override void OnTick()
        {
            currentAskOnTick = Symbol.Ask;
            currentBidOnTick = Symbol.Bid;
            Trades();
            // modifies sl & tp
            if (modifySlTp == true)
            {
                ModifyStopLossTakeProfit();
            }
        }
        private void ModifyStopLossTakeProfit()
        {
            foreach (var _pos in Positions)
            {
                if (_pos.TradeType == TradeType.Buy)
                {
                    newTp = currentBidOnTick + (atr.Result.LastValue * atrMultiplier);
                    newSl = currentBidOnTick - (atr.Result.LastValue * atrMultiplier);
                    _pos.ModifyTakeProfitPrice(newTp);
                    _pos.ModifyStopLossPrice(newSl);
                    countModifiedTpSl++;
                }
                else
                {
                    newTp = currentAskOnTick - (atr.Result.LastValue * atrMultiplier);
                    newSl = currentAskOnTick + (atr.Result.LastValue * atrMultiplier);
                    _pos.ModifyTakeProfitPrice(newTp);
                    _pos.ModifyStopLossPrice(newSl);
                    countModifiedTpSl++;
                }
            }
        }
        private void Trades()
        {
            if (Positions.Count >= maxPos)
                return;
            var currentResValue = ResLineValue(evaluatedBars);
            var currentSupValue = SupLineValue(evaluatedBars);
            List<double> listOfHighs = new List<double>();
            List<double> listOfLows = new List<double>();

            for (int i = 5; i <= evaluatedBars; i++)
            {
                listOfHighs.Add(Bars.HighPrices.Last(i));
                listOfLows.Add(Bars.LowPrices.Last(i));
            }
            // opens long position
            if (currentBidOnTick > currentResValue &&
                sma.Result.IsRising())
            {
                ExecuteMarketOrder(TradeType.Buy, SymbolName, volume, botLabel, sl, tp);
            }
            else
            // opens short position
            if (currentBidOnTick < currentSupValue &&
                sma.Result.IsFalling())
            {
                ExecuteMarketOrder(TradeType.Sell, SymbolName, volume, botLabel, sl, tp);
            }
            listOfHighs.Clear();
            listOfLows.Clear();
        }
        // resistance lines
        private double ResLineValue(int evaluatedBars)
        {
            listOfResPoints.Clear();
            for (int i = 5; i < evaluatedBars + 5; i++)
            {
                var resPoint = Bars.HighPrices.Last(i);
                // populates resistance points
                listOfResPoints.Add(resPoint);
            }
            var resLine = listOfResPoints.Max();
            return resLine;
        }
        // support lines
        private double SupLineValue(int evaluatedBars)
        {
            listOfSupPoints.Clear();
            for (int i = 5; i < evaluatedBars + 5; i++)
            {
                var supPoint = Bars.LowPrices.Last(i);
                // populates support points
                listOfSupPoints.Add(supPoint);
            }
            var supLine = listOfSupPoints.Min();
            return supLine;
        }
        protected override void OnStop()
        {
            Print("No. of times SL & TP modified: {0}", countModifiedTpSl);
        }
    }
}

 

Dear Panagiotis,

Pls let me know if there's a way to fix the above.

Thank you,

Sameh


@findsameh

PanagiotisCharalampous
17 Jun 2020, 08:57

Hi Sameh,

Unfortunately there is nothing you can do about this at the moment. I have forwarded this issue to the product team for further investigation.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

desmaster236
25 Apr 2023, 18:32

RE: Limiting events report while backtesting

PanagiotisCharalampous said:

Hi Sameh,

Unfortunately there is nothing you can do about this at the moment. I have forwarded this issue to the product team for further investigation.

Best Regards,

Panagiotis 

Join us on Telegram

Hi Panagiotis,

There are too many events log while backtesting for a mid period of time (1 year) and it causes ctrader to be very slow.

Did the product team add any thing to limit showing events or logs.

Regards


@desmaster236