Timeframe as Parameters in Optimization

Created at 15 Jul 2023, 12:55
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!
FX

fx.pro

Joined 08.03.2016

Timeframe as Parameters in Optimization
15 Jul 2023, 12:55


Hi,

there is short example how to make Timeframe as Parameters in optimization:

Declaration:

public enum TF_List { MN1, W1, D1, H4, H3, H2, H1, m20, m15, m10, m5, m4, m3, m2, m1, t1000, t500 }

[Parameter("Timeframe Ma1", Group = "MA", DefaultValue = TF_List.D1)]
public TF_List Tf_ma { get; set; }

Usage example:

var barHigh = MarketData.GetBars(Tf_convert(Tf_ma), SymbolName);

static TimeFrame Tf_convert(TF_List tflist)
        {
            TimeFrame tf = TimeFrame.Daily;

            switch (tflist)
            {
                case TF_List.MN1: tf = TimeFrame.Monthly; break;
                case TF_List.W1: tf = TimeFrame.Weekly; break;
                case TF_List.D1: tf = TimeFrame.Daily; break;
                case TF_List.H4: tf = TimeFrame.Hour4; break;
                case TF_List.H3: tf = TimeFrame.Hour3; break;
                case TF_List.H2: tf = TimeFrame.Hour2; break;
                case TF_List.H1: tf = TimeFrame.Hour; break;
                case TF_List.m20: tf = TimeFrame.Minute20; break;
                case TF_List.m15: tf = TimeFrame.Minute15; break;
                case TF_List.m10: tf = TimeFrame.Minute10; break;
                case TF_List.m5: tf = TimeFrame.Minute5; break;
                case TF_List.m4: tf = TimeFrame.Minute4; break;
                case TF_List.m3: tf = TimeFrame.Minute3; break;
                case TF_List.m2: tf = TimeFrame.Minute2; break;
                case TF_List.m1: tf = TimeFrame.Minute; break;
                case TF_List.t1000: tf = TimeFrame.Tick1000; break;
                case TF_List.t500: tf = TimeFrame.Tick500; break;
            }
            return tf;
        }

 

PN

 

 

 


@fx.pro
Replies

Best.Algo.Trader
16 Jul 2023, 12:06

Hi,

not sure what you want to achieve with this, but in my case there is a timeframe parameter available out of the box for optimization. No need to add one. 

If you just need an additional time frame parameter for a second timeframe in your bot, you can simply use the type TimeFrame for your parameter (see example below). Unfortunately I cannot set a default using DefaultValue = TimeFrame.Minute15. This does not compile. And secondly when you use my example the TimeFrame parameter is not available for optimization. Only the one provided by cTrader Desktop works for me. 

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

namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.None)]
    public class Test : Robot
    {
        [Parameter("My Time Frame")]
        public TimeFrame InpTimeFrame { get; set; }

        protected override void OnStart()
        {
        }

        protected override void OnTick()
        {
        }

        protected override void OnStop()
        {
        }
    }
}

 


@Best.Algo.Trader

fx.pro
16 Jul 2023, 12:24

RE:

Kaspricci said:

Hi,

not sure what you want to achieve with this, but in my case there is a timeframe parameter available out of the box for optimization. No need to add one. 

If you just need an additional time frame parameter for a second timeframe in your bot, you can simply use the type TimeFrame for your parameter (see example below). Unfortunately I cannot set a default using DefaultValue = TimeFrame.Minute15. This does not compile. And secondly when you use my example the TimeFrame parameter is not available for optimization. Only the one provided by cTrader Desktop works for me. 

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

namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.None)]
    public class Test : Robot
    {
        [Parameter("My Time Frame")]
        public TimeFrame InpTimeFrame { get; set; }

        protected override void OnStart()
        {
        }

        protected override void OnTick()
        {
        }

        protected override void OnStop()
        {
        }
    }
}

 

Do You see difference ?


@fx.pro

Best.Algo.Trader
16 Jul 2023, 12:28 ( Updated at: 21 Dec 2023, 09:23 )

RE: RE:

fx.pro said:

Kaspricci said:

Hi,

not sure what you want to achieve with this, but in my case there is a timeframe parameter available out of the box for optimization. No need to add one. 

If you just need an additional time frame parameter for a second timeframe in your bot, you can simply use the type TimeFrame for your parameter (see example below). Unfortunately I cannot set a default using DefaultValue = TimeFrame.Minute15. This does not compile. And secondly when you use my example the TimeFrame parameter is not available for optimization. Only the one provided by cTrader Desktop works for me. 

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

namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.None)]
    public class Test : Robot
    {
        [Parameter("My Time Frame")]
        public TimeFrame InpTimeFrame { get; set; }

        protected override void OnStart()
        {
        }

        protected override void OnTick()
        {
        }

        protected override void OnStop()
        {
        }
    }
}

 

Do You see difference ?

Unfortunately no. I still don't get it


@Best.Algo.Trader

fx.pro
16 Jul 2023, 12:55

RE: RE: RE:

This is for optimization of custom Timeframe , not a main  (on which Your cbot is running).

P.


@fx.pro

Best.Algo.Trader
16 Jul 2023, 13:15

RE: RE: RE: RE:

fx.pro said:

This is for optimization of custom Timeframe , not a main  (on which Your cbot is running).

P.

I see. 


@Best.Algo.Trader