Optimization behaviour in non MultiSymbol Robot

Created at 12 Feb 2020, 15: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!
GE

gennimatas

Joined 19.09.2018

Optimization behaviour in non MultiSymbol Robot
12 Feb 2020, 15:57


Here is code and instructions to reproduce
Create the robot and add an instance to EURUSD
We have four cases

Case 1.
    remove // from this line in code //wlNames = cLib.GetListSymbolNames(WatchListName);
    compile
    on Optimization Parameters check Timeframe and set to any timeframe
    and set WatchListName to a list
    run
    this throws exception:
    | Crashed in OnStart with NotSupportedException: Watchlists are not supported in optimization

Case 2.
    restore // in code
    compile
    on Optimization Parameters set SymbolName to empty string
    set SymbolIndex Min:0 Max:0
    run
    this works with the instance symbol EURUSD as it should

Case 3.
a.    on Optimization Parameters set SymbolName to instance symbol EURUSD
    set SymbolIndex Min:0 Max:0
    this works

b.    set SymbolIndex Min:0 Max:1
    set SymbolName to EURUSD,GBPAUD
    run
    this will throw exception for GBPAUD (not instance symbol)

The code:
 

using System;
using System.Collections;
using System.Collections.Generic;
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 OptBehaviour : Robot
    {
        [Parameter("WatchListName", DefaultValue = "Forex Cluster")]
        public string WatchListName { get; set; }

        [Parameter("SymbolNames", DefaultValue = "")]
        public string SymbolNames { get; set; }

        [Parameter("SymbolIndex", DefaultValue = 0, MinValue = 0, MaxValue = 27)]
        public int SymbolIndex { get; set; }

        public Symbol sym;
        public Bars bars;
        List<string> wlNames;
        string[] paramNames = null;

        protected override void OnStart()
        {
            // Case 1
            // this line fires excpetion | Crashed in OnStart with NotSupportedException: Watchlists are not supported in optimization
            //wlNames = GetListSymbolNames(WatchListName);

            paramNames = null;

            // from watchlist symbols
            if (wlNames != null)
            {
                sym = Symbols.GetSymbol(wlNames[SymbolIndex]);
                bars = MarketData.GetBars(Bars.TimeFrame, sym.Name);
                Print(SymbolIndex, " ", sym.Name, " from watchlist");
            }
            else
            {
                // Case 2
                // from instance symbol
                if (SymbolNames == "")
                {
                    if (SymbolIndex > 0)
                        Stop();
                    sym = Symbol;
                    bars = Bars;
                    Print(SymbolIndex, " ", sym.Name, " from instance");
                }
                // Case 3
                // from param symbols
                // fires exceptions | Crashed in OnStart with NotSupportedException: MultiSymbol is temporarily not supported in optimization
                else
                {
                    paramNames = SymbolNames.Split(",".ToCharArray());
                    if (SymbolIndex > paramNames.Length - 1)
                        Stop();
                    sym = Symbols.GetSymbol(paramNames[SymbolIndex]);
                    bars = MarketData.GetBars(Bars.TimeFrame, sym.Name);
                    Print(SymbolIndex, " ", sym.Name, " from parameter");
                }
            }
        }

        protected override void OnTick()
        {
            // Put your core logic here
        }

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

        public List<string> GetListSymbolNames(string listName)
        {
            List<string> names = new List<string>();
            foreach (Watchlist wlist in Watchlists)
                if (wlist.Name.Replace(" ", "").ToUpper() == listName.Replace(" ", "").ToUpper())
                    foreach (string symbolName in wlist.SymbolNames)
                        names.Add(symbolName);
            return names;
        }

    }
}

 


@gennimatas
Replies

PanagiotisCharalampous
13 Feb 2020, 09:44

Hi Takis,

Symbols.GetSymbol() doesn't work in optimization. You will need to replace the references to symbol with strings.

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

sascha.dawe
04 Mar 2020, 00:59

RE:

PanagiotisCharalampous said:

Hi Takis,

Symbols.GetSymbol() doesn't work in optimization. You will need to replace the references to symbol with strings.

Best Regards,

Panagiotis 

Join us on Telegram

 

Hi Panagiotis, 

Could you provide a little more information on this:

Such as what I would replace this line with?

Symbol symbol = Symbols.GetSymbol("AUD" + quoteCurrency);

Thanks,

Sascha


@sascha.dawe

PanagiotisCharalampous
04 Mar 2020, 08:50

Hi Sascha,

Where do you want to replace it? Can you provide the complete code?

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous