Multisymbols Optimisation

Created at 05 Apr 2022, 13:35
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!
KI

Kisses

Joined 05.04.2022

Multisymbols Optimisation
05 Apr 2022, 13:35


Hi, 

Been playing around with multisymbols feature. It worked on 'Backtesting', but didnt work on 'Optimisation', with errors as follow:

04/03/2022 00:00:00.105 | Backtesting was stopped
04/03/2022 00:00:00.105 | Crashed in OnStart with NullReferenceException: Object reference not set to an instance of an object.
04/03/2022 00:00:00.105 | Failed to get symbol 'EURGBP': symbol not found.
04/03/2022 00:00:00.105 | Failed to get symbol 'EURJPY': symbol not found.
04/03/2022 00:00:00.105 | Backtesting started
 

Wondering if this is expected (yet to extend this feature for optimisation), or I might have made some coding mistakes? Here's the code sample:

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 NewcBot : Robot
    {
        [Parameter("First Pair", DefaultValue = "EURUSD", Group = "Pair")]
        public string Symbol1 { get; set; }

        [Parameter("Second Pair", DefaultValue = "EURJPY", Group = "Pair")]
        public string Symbol2 { get; set; }

        [Parameter("Third Pair", DefaultValue = "EURGBP", Group = "Pair")]
        public string Symbol3 { get; set; }

        [Parameter("Entry 1 Volume (Lots)", Group = "Position Entry - Market Order")]
        public double VolumeInLots_1 { get; set; }

        [Parameter("Entry 2 Volume (Lots)", Group = "Position Entry - Market Order")]
        public double VolumeInLots_2 { get; set; }

        [Parameter("Entry 3 Volume (Lots)", Group = "Position Entry - Market Order")]
        public double VolumeInLots_3 { get; set; }

        private double _volumeInUnits1;
        private double _volumeInUnits2;
        private double _volumeInUnits3;
        private Symbol symbol1, symbol2, symbol3;
        private Bars series1;
        private Bars series2;
        private Bars series3;

        protected override void OnStart()
        {
            symbol1 = Symbols.GetSymbol(Symbol1);
            symbol2 = Symbols.GetSymbol(Symbol2);
            symbol3 = Symbols.GetSymbol(Symbol3);
            _volumeInUnits1 = symbol1.QuantityToVolumeInUnits(VolumeInLots_1);
            _volumeInUnits2 = symbol2.QuantityToVolumeInUnits(VolumeInLots_2);
            _volumeInUnits3 = symbol3.QuantityToVolumeInUnits(VolumeInLots_3);
            series1 = MarketData.GetBars(TimeFrame, Symbol1);
            series2 = MarketData.GetBars(TimeFrame, Symbol2);
            series3 = MarketData.GetBars(TimeFrame, Symbol3);
        }

        protected override void OnBar()
        {
            if (series1.HighPrices.Last(1) - series1.LowPrices.Last(1) > series2.HighPrices.Last(1) - series2.LowPrices.Last(1) && Positions.Find("BUY") == null)
            {
                ExecuteMarketOrder(TradeType.Buy, Symbol2, _volumeInUnits2, "BUY");
                if (Positions.Find("SELL") != null)
                {
                    foreach (var openedPosition in Positions.FindAll("SELL"))
                    {
                        ClosePosition(openedPosition);
                    }
                }
            }
            else if (series1.HighPrices.Last(1) - series1.LowPrices.Last(1) < series3.HighPrices.Last(1) - series3.LowPrices.Last(1) && Positions.Find("SELL") == null)
            {
                ExecuteMarketOrder(TradeType.Sell, Symbol3, _volumeInUnits3, "SELL");
                if (Positions.Find("BUY") != null)
                {
                    foreach (var openedPosition in Positions.FindAll("BUY"))
                    {
                        ClosePosition(openedPosition);
                    }
                }
            }
        }

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

Thanks!


@Kisses
Replies

galafrin
05 Apr 2022, 23:12

RE:

Multi-symbols already works under Backtest. 4.1, so no Backtest regression under 4.2, is a thing

 


@galafrin

amusleh
06 Apr 2022, 09:56 ( Updated at: 06 Apr 2022, 09:58 )

Hi,

Multi symbol optimization is added on version 4.2 of cTrader, it's on beta and it will be released for brokers very soon.

You can use multi symbol optimization on Spotware cTrader Beta 4.2.


@amusleh