Optimization additional timeframe as parameter to optimize

Created at 03 Aug 2022, 16: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!
BA

baton.carat_0g

Joined 03.08.2022

Optimization additional timeframe as parameter to optimize
03 Aug 2022, 16:35


Hi,

I'm quite new in programming and have problem how to set additional timeframe from moving average as optimatization parameter? I found some symillar topics on forum but don't find solution.

Below some code:

[Parameter("MA v1 ", Group = "SMA")]
public TimeFrame Timeframev1 { get; set; }

[Parameter("Period MA v1 ", DefaultValue = 20, MinValue = 1, MaxValue = 100, Group = "SMA")]
public int Smav1 { get; set; }

private MarketSeries FloweRv1;
private MovingAverage ma1 { get; set; }

FloweRv1 = MarketData.GetSeries(Timeframev1);
ma1 = Indicators.MovingAverage(FloweRv1.Close, Smav1, MAType1);

 

Could you please advise how to do it?

Thank you.


@baton.carat_0g
Replies

PanagiotisCharalampous
04 Aug 2022, 08:47

Hi there,

I am not sure what the problem is here. Can you elaborate a bit more?

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

baton.carat_0g
04 Aug 2022, 09:03 ( Updated at: 21 Dec 2023, 09:22 )

Hi,

Screen below. How to set timeframe MA v1 as parameter for optimization?

 

 


@baton.carat_0g

paolo.panicali
04 Aug 2022, 10:47 ( Updated at: 21 Dec 2023, 09:22 )

Hi this is a possible solution

// Custom Timeframe MA 

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class MA_MultiTimeframe : Indicator
    {
        public enum TimeFrame_Custom
        {
            Daily,
            One_Hour
        }

        [Parameter("TimeFrameCode", DefaultValue = TimeFrame_Custom.Daily)]
        public TimeFrame_Custom TimeFrameCode { get; set; }

        [Parameter("Fast MA period", DefaultValue = 5)]
        public int Fast_Ma_Period { get; set; }

        [Parameter("MA Type", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType MaType { get; set; }

        [Output("FastMA_Value", LineColor = "Red")]
        public IndicatorDataSeries FastMA_Value { get; set; }


        private TimeFrame MyTimeFrame;

        private Bars CustomTFSeries;

        private MovingAverage Fast_MA, Slow_MA;


        protected override void Initialize()
        {
            switch (TimeFrameCode)
            {
                case TimeFrame_Custom.Daily:
                    MyTimeFrame = TimeFrame.Daily;
                    break;

                case TimeFrame_Custom.One_Hour:
                    MyTimeFrame = TimeFrame.Hour;
                    break;

            }

            CustomTFSeries = MarketData.GetBars(MyTimeFrame);
            Fast_MA = Indicators.MovingAverage(CustomTFSeries.ClosePrices, Fast_Ma_Period, MaType);
        }

        public override void Calculate(int index)
        {
            var CustomIndex = CustomTFSeries.OpenTimes.GetIndexByTime(Bars[index].OpenTime);

            FastMA_Value[index] = Fast_MA.Result[CustomIndex - 1];
        }
    }
}

 

bye


@paolo.panicali

PanagiotisCharalampous
04 Aug 2022, 10:48

Hi again,

At the moment it is not possible to optimize timeframe fields. We will add this option in an upcoming update.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

baton.carat_0g
06 Aug 2022, 10:52 ( Updated at: 21 Dec 2023, 09:22 )

RE: Hi this is a possible solution

paolo.panicali said:

// Custom Timeframe MA 

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class MA_MultiTimeframe : Indicator
    {
        public enum TimeFrame_Custom
        {
            Daily,
            One_Hour
        }

        [Parameter("TimeFrameCode", DefaultValue = TimeFrame_Custom.Daily)]
        public TimeFrame_Custom TimeFrameCode { get; set; }

        [Parameter("Fast MA period", DefaultValue = 5)]
        public int Fast_Ma_Period { get; set; }

        [Parameter("MA Type", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType MaType { get; set; }

        [Output("FastMA_Value", LineColor = "Red")]
        public IndicatorDataSeries FastMA_Value { get; set; }


        private TimeFrame MyTimeFrame;

        private Bars CustomTFSeries;

        private MovingAverage Fast_MA, Slow_MA;


        protected override void Initialize()
        {
            switch (TimeFrameCode)
            {
                case TimeFrame_Custom.Daily:
                    MyTimeFrame = TimeFrame.Daily;
                    break;

                case TimeFrame_Custom.One_Hour:
                    MyTimeFrame = TimeFrame.Hour;
                    break;

            }

            CustomTFSeries = MarketData.GetBars(MyTimeFrame);
            Fast_MA = Indicators.MovingAverage(CustomTFSeries.ClosePrices, Fast_Ma_Period, MaType);
        }

        public override void Calculate(int index)
        {
            var CustomIndex = CustomTFSeries.OpenTimes.GetIndexByTime(Bars[index].OpenTime);

            FastMA_Value[index] = Fast_MA.Result[CustomIndex - 1];
        }
    }
}

 

bye

Hi Paolo,

Thanks a lot! It working great :D


@baton.carat_0g