An important bug on Multi-timeframe indicators
An important bug on Multi-timeframe indicators
17 Aug 2020, 16:26
An important bug:
I create an indicator with Daily timeframe, I insert it manually in a backtesting chart and only the timeframe equal to the chart updates the Close price and the number of bars. The other Timeframes keep the loaded bars fixed and the Close prices are not updated in the timeframes other than the chart. No multitimeframe indicator runs correctly inserting it in a backtesting chart.
Inside bot run ok.
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 multi : Indicator
{
Bars _bars2;
protected override void Initialize()
{
// Initialize and create nested indicators
_bars2 = MarketData.GetBars(TimeFrame.Daily);
}
public override void Calculate(int index)
{
// Calculate value at specified index
var idx2 = _bars2.OpenTimes.GetIndexByTime(Bars[index].OpenTime);
Chart.DrawStaticText("info",
"Bars Daily: "+_bars2.Count + ", ClosePrice: " + _bars2[idx2].Close,
VerticalAlignment.Top,
HorizontalAlignment.Right,
Color.Yellow);
}
}
}
Replies
bienve.pf
17 Aug 2020, 17:04
RE:
PanagiotisCharalampous said:
Hi bienve.pf,
I checked this and seems to work fine for me. Can you provide me with an example?
Best Regards,
Panagiotis
Hi Panagiotis,
have you inserted the indicator in a backtesting chart and hit play?
the counter Daily does not move. neither the bars nor the price "Close"
@bienve.pf
PanagiotisCharalampous
17 Aug 2020, 17:08
Hi bienve.pf,
The reason it doesn't move is because the retrieved bars are consist of completed bars. So you get the completed bar of the specific date. The price will change as soon as the date changes. There is a similar discussion about this here.
Best Regards,
Panagiotis
@PanagiotisCharalampous
bienve.pf
17 Aug 2020, 17:20
RE:
PanagiotisCharalampous said:
Hi bienve.pf,
The reason it doesn't move is because the retrieved bars are consist of completed bars. So you get the completed bar of the specific date. The price will change as soon as the date changes. There is a similar discussion about this here.
Best Regards,
Panagiotis
I understand,
But if I test multi-timeframe indicator in backtesting I need receive data like in realtime to parse all tics at the moment. Now, with all the finalized bars and finalized values the ClosePrices no moves and It is not a real stage.
@bienve.pf
bienve.pf
26 Apr 2021, 11:38
This is a test indicator. Just insert in Chart of Backtesting to see that info changes about TimeFrame bar counters
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 MTF : Indicator
{
[Parameter("Data Location", DefaultValue = VerticalAlignment.Bottom)]
public VerticalAlignment DataLocation { get; set; }
[Output("Main")]
public IndicatorDataSeries Result { get; set; }
Bars bars1;
Bars bars2;
Bars bars3;
Bars bars4;
protected override void Initialize()
{
// Initialize and create nested indicators
bars1 = MarketData.GetBars(TimeFrame.Hour);
bars2 = MarketData.GetBars(TimeFrame.Hour4);
bars3 = MarketData.GetBars(TimeFrame.Hour12);
bars4 = MarketData.GetBars(TimeFrame.Daily);
}
public override void Calculate(int index)
{
string info = bars1.TimeFrame.ToString() + " -> " + bars1.Count + "\n" + bars2.TimeFrame.ToString() + " -> " + bars2.Count + "\n" + bars3.TimeFrame.ToString() + " -> " + bars3.Count + "\n" + bars4.TimeFrame.ToString() + " -> " + bars4.Count;
Chart.DrawStaticText("info", info, DataLocation, HorizontalAlignment.Right, Color.White);
}
}
}
@bienve.pf
bienve.pf
26 Apr 2021, 11:39
This a sample bot that use the MTF indicator
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
using System.Threading;
using System.Windows.Forms;
using System.Net;
using System.IO.Compression;
using System.IO;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
public class borrar : Robot
{
[Parameter("Data Location", DefaultValue = VerticalAlignment.Bottom)]
public VerticalAlignment DataLocation { get; set; }
[Parameter("Load MTF", DefaultValue = true)]
public bool LoadMTF { get; set; }
MTF _mtf;
protected override void OnStart()
{
// Put your initialization logic here
if (LoadMTF)
_mtf = Indicators.GetIndicator<MTF>(DataLocation);
}
protected override void OnTick()
{
if (LoadMTF)
{
var last = _mtf.Result.LastValue;
}
}
}
}
@bienve.pf
firemyst
29 Apr 2021, 06:15
RE: RE:
bienve.pf said:
PanagiotisCharalampous said:
Hi bienve.pf,
The reason it doesn't move is because the retrieved bars are consist of completed bars. So you get the completed bar of the specific date. The price will change as soon as the date changes. There is a similar discussion about this here.
Best Regards,
Panagiotis
I understand,
But if I test multi-timeframe indicator in backtesting I need receive data like in realtime to parse all tics at the moment. Now, with all the finalized bars and finalized values the ClosePrices no moves and It is not a real stage.
Two questions:
1) have you chosen "tick data" from the backtesting menu option?
2) A lot of chart operations are not supported (as far as I understand) in backtesting mode. Try surrounding your indicator with
if (!IsBacktesting)
{
// ... indicator calls here
}
and see what happens.
@firemyst
PanagiotisCharalampous
17 Aug 2020, 17:01
Hi bienve.pf,
I checked this and seems to work fine for me. Can you provide me with an example?
Best Regards,
Panagiotis
Join us on Telegram
@PanagiotisCharalampous