Drawing a character per candle in a cBot backtest resulted multiple characters drawn on a higher timeframe candle

Created at 23 Aug 2024, 10:57
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!
KA

karatedog

Joined 09.07.2024

Drawing a character per candle in a cBot backtest resulted multiple characters drawn on a higher timeframe candle
23 Aug 2024, 10:57


I have created a simple cBot code, it draws an character above a candle, on every candle.

Through some setting change on the interface I was able to create this when running a Backtest:

That is, the Backtest runs on 1m data, and somehow triggers the OnBar() method even the selected timeframe for the chart is 5m. This is why (I think) 5 characters are drawn (and they are automatically correct in their position I haven't done anything to achieve that).

I was not able to recreate this state when I have created a new cBot and copied the code over.

I'm using cTrader Desktop (Pepperstone) 4.8.30.23181 (also, why isn't the version number not allowed to be copied on the About page?)

The code:

protected override void OnBar()
{
	int currentIndex = Bars.OpenTimes.GetIndexByTime(Bars.OpenTimes.LastValue);
	void plotchar(bool series, int indexPosition, string drawchar = "*", string location = "abovebar")
		{
			if (series)
			{
				double charLocation;
				switch (location)
					case "abovebar":
					abovebar:
						charLocation = Bars.HighPrices.Last(0) * 1.0002;
						break;
					case "belowbar":
						charLocation = Bars.LowPrices.Last(0) * 0.9998;
						break;
					default:
						goto abovebar;
	var text = Chart.DrawText("position" + indexPosition, drawchar, indexPosition, charLocation, Color.Red);
	text.IsBold = true;
	text.VerticalAlignment = VerticalAlignment.Center;
	text.HorizontalAlignment = HorizontalAlignment.Center;
	text.IsInteractive = true;

	plotchar(series : true, indexPosition : currentIndex, drawchar: "*");
}

update: I have found a way to recreate the issue.

Select a timeframe that is NOT 1m, and apply the cBot and run the backtest. Up until you do not select 1m timeframe, you can select any timeframe, run the backtest again and it will be fine.
As soon as you select the 1m timeframe (run the backtest, ofcourse it will be okay) then select a different (say, 5m) timeframe and run the backtest, you will encounter the problem, and from the on it will be impossible to get back to the original state. 

Removing the instance and adding it back sometimes helps, but other times it just creates a new kind of issue which I'm unable to describe, it is entirely nondeterministic, click around and experiment.

I have removed the instance and added it back (it is default 1h), it looked okay. Then I switched to 5m, it still looked okay. Then I switched to 15 minutes, and I got 3 characters on each candle with (3 * 5 minutes). Going back to 1H resulted 12 characters on each candle width.

When the issue has surfaced, it does not matter if I change data source (like 1m from the server, 15m from the server or tick data).

 


@karatedog
Replies

karatedog
23 Aug 2024, 11:14

I was able to achieve a mixed state where certain candles have multiple characters, but others do not:


@karatedog

PanagiotisCharalampous
23 Aug 2024, 15:09

Hi there,

Thank you for reporting this issue. We managed to reproduce it and it will be fixed in an upcoming update.

Best regards,

Panagiotis


@PanagiotisCharalampous

karatedog
26 Aug 2024, 14:45

RE: Drawing a character per candle in a cBot backtest resulted multiple characters drawn on a higher timeframe candle

PanagiotisCharalampous said: 

Hi there,

Thank you for reporting this issue. We managed to reproduce it and it will be fixed in an upcoming update.

Best regards,

Panagiotis

Thank you. Any workaround until it is fixed?


@karatedog

karatedog
26 Aug 2024, 14:55

RE: RE: Drawing a character per candle in a cBot backtest resulted multiple characters drawn on a higher timeframe candle

karatedog said: 

PanagiotisCharalampous said: 

Hi there,

Thank you for reporting this issue. We managed to reproduce it and it will be fixed in an upcoming update.

Best regards,

Panagiotis

Thank you. Any workaround until it is fixed?

I found a workaround:

  • duplicate the cBot
  • delete original cBot
  • attach symbol to the new cBot

So it looks like the issue is tied to the cBot file/cache.


@karatedog