Replies

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

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