Multi-Timeframe Backtesting vs Realtime Trading

Created at 11 Oct 2014, 06: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!
EM

emeeder

Joined 06.05.2014 Blocked

Multi-Timeframe Backtesting vs Realtime Trading
11 Oct 2014, 06:55


I have a few indicators and cbots that run multiple timeframes.

I run in 5 minutes and they use 30 min and 1 HR timeframes.

When i backtest the cbot, they trade terrible compared to realtime. Or compared to the Multi Timframe indicators they are based on.

WHY?

Maybe someone with some insight can confirm how the cbot looks at this:

 protected override void OnStart()
{

 var seriesH1 = MarketData.GetSeries(TimeFrame.Hour);

_hma1H = Indicators.GetIndicator<HMA>(seriesH1.Close, HMAPeriod);

}

RealTime:

The results for the 1HR HMA are updating many times within the 5 minute bar.

Backtesting:

Does the result for the 1HR HMA update as frequently or only every hour??

From my poor backtesting results i think maybe it just updates hourly??. Or am i doing something wrong.

Can someone let me know if this is the way backtesting works so that i dont have to waste more time trying to get backtesting working for a Multi timeframe Cbot or a Cbot with multi timframe indicators. Does it just look at the Close value of the last bar and the value stays the same until close of the next hourly bar?

I have tried a few different methods of adding the multiple timeframe into the cbot, but results are the same for all of them.

Thanks


Replies

Spotware
14 Oct 2014, 09:54

In both live and backtesting indicators update their values on every tick. Please make sure that it is not a problem of your custom indicator. You can replace it to one of standard indicators and check if problem persists.


@Spotware

emeeder
14 Oct 2014, 16:07

Thanks for the reply.

I think the problem may be in the HMA Indicator.

One of the parameters used to get the in the Weighted MA is calculated in the indicator.

I think maybe it is not building a correct DataSeries() or it is being built in the wrong time frame?

Here is my code, can you see why, when on a 1 minute chart, the higher time frame HMA will always level off towards the end of their time period and then at the start of their time period they adjust to the correct level again.

I am refering to the diff1, diff110M and the diff11H parameters. Any idea how it can be corrected?

Thanks

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None, ScalePrecision = 4)]
    public class HMAMultiTF : Indicator
    {


        [Parameter("Source")]
        public DataSeries Source { get; set; }

        [Parameter(DefaultValue = 14)]
        public int Period { get; set; }

        [Output("HMA", Color = Colors.Orange)]
        public IndicatorDataSeries hma { get; set; }

        [Output("HMAFast 10M", Color = Colors.Green)]
        public IndicatorDataSeries hma10M { get; set; }

        [Output("HMAFast 1Hr", Color = Colors.Blue)]
        public IndicatorDataSeries hma1H { get; set; }


        private IndicatorDataSeries diff1, diff110M, diff11H;
        private WeightedMovingAverage wma1, wma110M, wma11H;
        private WeightedMovingAverage wma2, wma210M, wma21H;
        private WeightedMovingAverage wma3, wma310M, wma31H;

        private MarketSeries series1H1, series10M1;


        protected override void Initialize()
        {
            // Chart TF

            diff1 = CreateDataSeries();
            wma1 = Indicators.WeightedMovingAverage(MarketSeries.Close, (int)Period / 2);
            wma2 = Indicators.WeightedMovingAverage(MarketSeries.Close, Period);
            wma3 = Indicators.WeightedMovingAverage(diff1, (int)Math.Sqrt(Period));

            // 10 Minute TF

            series10M1 = MarketData.GetSeries(TimeFrame.Minute10);
            diff110M = CreateDataSeries();

            wma110M = Indicators.WeightedMovingAverage(series10M1.Close, (int)Period / 2);
            wma210M = Indicators.WeightedMovingAverage(series10M1.Close, Period);
            wma310M = Indicators.WeightedMovingAverage(diff110M, (int)Math.Sqrt(Period));

            //1Hr Timeframe

            series1H1 = MarketData.GetSeries(TimeFrame.Hour);
            diff11H = CreateDataSeries();

            wma11H = Indicators.WeightedMovingAverage(series1H1.Close, (int)Period / 2);
            wma21H = Indicators.WeightedMovingAverage(series1H1.Close, Period);
            wma31H = Indicators.WeightedMovingAverage(diff11H, (int)Math.Sqrt(Period));

        }

        public override void Calculate(int index)
        {

            //Chart TimeFrame
            double var1 = 2 * wma1.Result[index];
            double var2 = wma2.Result[index];

            diff1[index] = var1 - var2;
            hma[index] = wma3.Result[index];


            //10Min Timeframe

            var index110M = series10M1.OpenTime.GetIndexByTime(MarketSeries.OpenTime[index]);

            double var110M = 2 * wma110M.Result[index110M];
            double var210M = wma210M.Result[index110M];

            diff110M[index] = var110M - var210M;
            hma10M[index] = wma310M.Result[index];


            //1Hr Timeframe

            var index1H1 = series1H1.OpenTime.GetIndexByTime(MarketSeries.OpenTime[index]);

            double var11H = 2 * wma11H.Result[index1H1];
            double var21H = wma21H.Result[index1H1];

            diff11H[index] = var11H - var21H;
            hma1H[index] = wma31H.Result[index];






        }
    }
}

 


Spotware
15 Oct 2014, 09:34

Dear Trader,

Unfortunately we do not provide engage service anymore. We can recommend you to contact one of our Partners or post a job in Development Jobs section.


@Spotware

emeeder
15 Oct 2014, 18:30 ( Updated at: 21 Dec 2023, 09:20 )

I left my m2 chart open for the day with this indicator. Opened it at around 00.00 Oct 15

The indicator above is accurate when it is being generated in real time. But the historical results are not right.

Does that mean there is something wrong with the indicator or is the problem with the way calgo/ctrader is generating the historical data?

I believe this is why it is hard to get accurate results when backtesting usng this indicator since it seems to generate historical data inaccurately or not per tick.

Do you see what i mean?

 


Spotware
16 Oct 2014, 09:19 ( Updated at: 21 Dec 2023, 09:20 )

RE:

emeeder said:

I left my m2 chart open for the day with this indicator. Opened it at around 00.00 Oct 15

The indicator above is accurate when it is being generated in real time. But the historical results are not right.

Does that mean there is something wrong with the indicator or is the problem with the way calgo/ctrader is generating the historical data?

I believe this is why it is hard to get accurate results when backtesting usng this indicator since it seems to generate historical data inaccurately or not per tick.

Do you see what i mean?

 

Most probably problem is in your indicator


@Spotware