Yet another optimization issue, please fix

Created at 14 Feb 2020, 20:57
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!
Waxy's avatar

Waxy

Joined 12.05.2015

Yet another optimization issue, please fix
14 Feb 2020, 20:57



@Waxy
Replies

PanagiotisCharalampous
17 Feb 2020, 09:10

Hi Xavier R,

Can you please post the complete cBot code in text format so that we can use it to reproduce the issue?

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

TzvetomirTerziysky
17 Feb 2020, 11:15

RE:

Are using Multi Time Frames? Optimisation is crashing on it:

 


@TzvetomirTerziysky

SwXavi
18 Feb 2020, 20:21

RE:

PanagiotisCharalampous said:

Hi Xavier R,

Can you please post the complete cBot code in text format so that we can use it to reproduce the issue?

Best Regards,

Panagiotis 

Join us on Telegram

 

Hello Panagiotis,

Here's a sample code:
 

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

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class OptCrash : Robot
    {
        [Parameter("SMA Period", DefaultValue = 100)]
        public int InputSmaPeriod { get; set; }

        private AverageTrueRange _averageTrueRange;

        private Bars _dailySeries;

        private SimpleMovingAverage _sma;

        //private bool _moreTradesAllowed;

        protected override void OnStart()
        {
            _dailySeries = MarketData.GetBars(TimeFrame.Daily);
            _averageTrueRange = Indicators.AverageTrueRange(_dailySeries, 14, MovingAverageType.Simple);

            _sma = Indicators.SimpleMovingAverage(_dailySeries.ClosePrices, InputSmaPeriod);
        }

        protected override void OnBar()
        {
        }

        protected override void OnTick()
        {
        }

        protected override void OnStop()
        {
        }
    }
}

 


@SwXavi

SwXavi
18 Feb 2020, 21:13

I want to mention the example above just worked fine in 3.7 beta version, so I think it's fixed.

The other issue is that it stops early when it's supposed to run for a few hours, most optimizations stop at 3-15 minutes even with an absurd amount of parameters to try, I've used "Sample Trend Bot" to demonstrate, here's the code anyways.

// -------------------------------------------------------------------------------------------------
//
//    This code is a cAlgo API sample.
//
//    This cBot is intended to be used as a sample and does not guarantee any particular outcome or
//    profit of any kind. Use it at your own risk.
//
//    The "Sample Trend cBot" will buy when fast period moving average crosses the slow period moving average and sell when 
//    the fast period moving average crosses the slow period moving average. The orders are closed when an opposite signal 
//    is generated. There can only by one Buy or Sell order at any time.
//
// -------------------------------------------------------------------------------------------------

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

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class SampleTrendcBot : Robot
    {
        [Parameter("MA Type")]
        public MovingAverageType MAType { get; set; }

        [Parameter()]
        public DataSeries SourceSeries { get; set; }

        [Parameter("Slow Periods", DefaultValue = 10)]
        public int SlowPeriods { get; set; }

        [Parameter("Fast Periods", DefaultValue = 5)]
        public int FastPeriods { get; set; }

        [Parameter("Quantity (Lots)", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
        public double Quantity { get; set; }

        private MovingAverage slowMa;
        private MovingAverage fastMa;
        private const string label = "Sample Trend cBot";

        protected override void OnStart()
        {
            fastMa = Indicators.MovingAverage(SourceSeries, FastPeriods, MAType);
            slowMa = Indicators.MovingAverage(SourceSeries, SlowPeriods, MAType);
        }

        protected override void OnTick()
        {
            var longPosition = Positions.Find(label, Symbol, TradeType.Buy);
            var shortPosition = Positions.Find(label, Symbol, TradeType.Sell);

            var currentSlowMa = slowMa.Result.Last(0);
            var currentFastMa = fastMa.Result.Last(0);
            var previousSlowMa = slowMa.Result.Last(1);
            var previousFastMa = fastMa.Result.Last(1);

            if (previousSlowMa > previousFastMa && currentSlowMa <= currentFastMa && longPosition == null)
            {
                if (shortPosition != null)
                    ClosePosition(shortPosition);
                ExecuteMarketOrder(TradeType.Buy, Symbol, VolumeInUnits, label);
            }
            else if (previousSlowMa < previousFastMa && currentSlowMa >= currentFastMa && shortPosition == null)
            {
                if (longPosition != null)
                    ClosePosition(longPosition);
                ExecuteMarketOrder(TradeType.Sell, Symbol, VolumeInUnits, label);
            }
        }

        private long VolumeInUnits
        {
            get { return Symbol.QuantityToVolume(Quantity); }
        }
    }
}

Once again thanks for your support


@SwXavi

PanagiotisCharalampous
19 Feb 2020, 15:31 ( Updated at: 21 Dec 2023, 09:21 )

Hi Xavier R,

I ran the optimization today and it completed without problems

If you still have problems, please post the exact optimization settings (symbol, timeframe, cBot parameters, dates) you are using and I will check it again.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

SwXavi
19 Feb 2020, 17:46 ( Updated at: 21 Dec 2023, 09:21 )

Hello Panagiotis, I think these are the full settings, please let me know.


@SwXavi

PanagiotisCharalampous
20 Feb 2020, 08:40

Hi Xavier R,

It seems you are using the genetic algorithm optimization method so I do not see any issue here. Using GA the results will have different convergence times which cannot be predicted. If you need an exhaustive search, use the grid optimization method.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

SwXavi
25 Feb 2020, 18:45

I want to mention this issue happens to me only inside a VPS, all optimizations run for about 5 minutes, while on my own laptop it can go full for hours, I'm not sure where's the problem. But at least I can circumvent it this way.


@SwXavi