Possible bug with backtesting
Possible bug with backtesting
26 Apr 2020, 23:51
Hi Spotware Team,
I think I might have found a bug in the backtesting engine. When I use this indicator with live market data:
and use a time frame - say a 6 hour set of candles ("block") - it slides up and down with market data in each 6 hour period (as expected). Please try it and see.
However, when I run this with backtesting - the candle indicator markers (H1CandleLow and H1CandleHigh in this instance) do not move at each "block".
If the backtesting engine is correct, the H1CandleLow and H1CandleHigh should move during the backtesting as it does like with live data, correct?
They don't move during backtesting. Could someone please look into that? Or is the backtesting engine acting properly and it doesn't really replay history?
Thanks
Replies
PanagiotisCharalampous
27 Apr 2020, 12:04
Hi chay,
I will fix this for you as soon as I find some time :)
Best Regards,
Panagiotis
@PanagiotisCharalampous
chay
06 May 2020, 23:23
RE:
Panagiotis, thanks - Perhaps in the meantime you might give some suggestions of your thoughts how you are planning to proceed?
I could research the topics myself and possibly write some code to assist? It would also allow me to increase my knowledge of the platform, which is always a good thing.
Thanks again,
Chay
@chay
PanagiotisCharalampous
07 May 2020, 09:21
Hi Chay,
In principle what needs to be done is to load more bars for the other timeframe you are trying to use until data is loaded for the bar under calculation. Below the solution I provided to a similar problem
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo.Indicators
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC)]
public class ematf : Indicator
{
[Parameter("MA TF")]
public TimeFrame matf { get; set; }
[Parameter("Period")]
public int emaper { get; set; }
[Output("EMA TF", Color = Colors.White)]
public IndicatorDataSeries main { get; set; }
Bars bars;
protected override void Initialize()
{
bars = MarketData.GetBars(matf);
}
public override void Calculate(int index)
{
while (double.IsNaN(bars.ClosePrices[bars.OpenTimes.GetIndexByTime(Bars.OpenTimes[index])]))
{
bars.LoadMoreHistory();
}
var ma1 = Indicators.ExponentialMovingAverage(bars.ClosePrices, emaper).Result;
//get time
var charttime = Bars.OpenTimes[index];
//get index
var idx1 = bars.OpenTimes.GetIndexByTime(charttime);
main[index] = ma1[idx1];
}
}
}
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
27 Apr 2020, 11:31
Hi chay,
This is the indicator's problem. It doesn't load enough data to display values in past dates. To work properly on backtesting the programmer has to reprogram it so that it gets enough data from the other timeframes in order to properly display values for past dates.
Best Regards,
Panagiotis
Join us on Telegram
@PanagiotisCharalampous