Current Backtest Time in an Indicator

Created at 09 Jan 2022, 21:46
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!
heinrich.munz's avatar

heinrich.munz

Joined 21.11.2020

Current Backtest Time in an Indicator
09 Jan 2022, 21:46


For the development of an Indicator I need the current time when OnCalculate(index) is getting called. I mean the time which corresponds to Bars.ClosePrices[index]

The only thing I can find is Bars.OpenTimes[index] what, however, is the time when the bar was opened. So what I need is something like Bars.CloseTimes[index].

The variable "Time" would do the job but other then in a cBot, in an Indicator, "Time" holds the current computer time, not the current backtest time :-(

Any ideas?

 

 


@heinrich.munz
Replies

amusleh
10 Jan 2022, 08:24

Hi,

You can always get the current time by using Server.Time: cAlgo API Reference - IServer Interface (ctrader.com)


@amusleh

heinrich.munz
10 Jan 2022, 14:10 ( Updated at: 21 Dec 2023, 09:22 )

amusleh said:

Hi,

You can always get the current time by using Server.Time: cAlgo API Reference - IServer Interface (ctrader.com)

 

Sorry, no, this does not work either! As you can see from the appended screen shot "Time", Server.Time and Server.TimeInUtc all return the current PC's time in UTC (10.01.2022...)
However, back testing Datetime is something after 08.12.2021 00:00:00 which is the current bar's open time.
So this seems to be a bug! How do I report bugs?

Btw: The easiest way to fix this problem would be to add Bars.CloseTimes[index]. When index points to the last bar (IsLastBar == true), Bars.CloseTimes[index] would hold the current back test time as it also holds the corresponding Bars.ClosePrices[index]


@heinrich.munz

amusleh
10 Jan 2022, 15:00

Hi,

Sorry, I misunderstood you, I thought you want to get the current back test time on a cBot.

The close time of a bar is the open time of next bar, so there is no need for an extra data collection.

For indicators, the calculate method is called once for each historical bar, and then it's called for each tick.

So for indicators if you call the Server.Time during historical bars it should return the current time not the time of that bar, and that's the correct behavior not a bug.


@amusleh

heinrich.munz
10 Jan 2022, 15:02 ( Updated at: 10 Jan 2022, 15:12 )

RE:

amusleh said:

Hi,

Sorry, I misunderstood you, I thought you want to get the current back test time on a cBot.

The close time of a bar is the open time of next bar, so there is no need for an extra data collection.

For indicators, the calculate method is called once for each historical bar, and then it's called for each tick.

So for indicators if you call the Server.Time during historical bars it should return the current time not the time of that bar, and that's the correct behavior not a bug.

>>>"The close time of a bar is the open time of next bar" 
Yes, this is true for historical bars, but not for the Last Bar (when IsLastBar == true). If I have set a time frame of lets say 1 hour, there is a time delay of max. 1 hour until I get the current time.  

>>>and then it's called for each tick.
Exactly! And I just need the accurate time of this "each tick". 

So again my question:
How do I get the accurate current back test time on an indicator for each tick after IsLastBar == true which is Corresponding to Bars.ClosePrices[index]???

 


@heinrich.munz

amusleh
10 Jan 2022, 16:57

RE: RE:

heinrich.munz said:

amusleh said:

Hi,

Sorry, I misunderstood you, I thought you want to get the current back test time on a cBot.

The close time of a bar is the open time of next bar, so there is no need for an extra data collection.

For indicators, the calculate method is called once for each historical bar, and then it's called for each tick.

So for indicators if you call the Server.Time during historical bars it should return the current time not the time of that bar, and that's the correct behavior not a bug.

>>>"The close time of a bar is the open time of next bar" 
Yes, this is true for historical bars, but not for the Last Bar (when IsLastBar == true). If I have set a time frame of lets say 1 hour, there is a time delay of max. 1 hour until I get the current time.  

>>>and then it's called for each tick.
Exactly! And I just need the accurate time of this "each tick". 

So again my question:
How do I get the accurate current back test time on an indicator for each tick after IsLastBar == true which is Corresponding to Bars.ClosePrices[index]???

 

Hi,

This issue will be resolved in cTrader 4.2.


@amusleh

heinrich.munz
19 Jan 2022, 12:34

amusleh said:

heinrich.munz said:

amusleh said:

Hi,

Sorry, I misunderstood you, I thought you want to get the current back test time on a cBot.

The close time of a bar is the open time of next bar, so there is no need for an extra data collection.

For indicators, the calculate method is called once for each historical bar, and then it's called for each tick.

So for indicators if you call the Server.Time during historical bars it should return the current time not the time of that bar, and that's the correct behavior not a bug.

>>>"The close time of a bar is the open time of next bar" 
Yes, this is true for historical bars, but not for the Last Bar (when IsLastBar == true). If I have set a time frame of lets say 1 hour, there is a time delay of max. 1 hour until I get the current time.  

>>>and then it's called for each tick.
Exactly! And I just need the accurate time of this "each tick". 

So again my question:
How do I get the accurate current back test time on an indicator for each tick after IsLastBar == true which is Corresponding to Bars.ClosePrices[index]???

 

Hi,

This issue will be resolved in cTrader 4.2.

Hi
I recognized that cTrader 4.2 is released now.
How is the current backtest time in an indicator realized?
Does "Time" contain the current backtest time? Or is there Bars.CloseTime[index]? Or both?

 


@heinrich.munz

amusleh
19 Jan 2022, 14:50

Hi,

In version 4.2 if you call Server.Time inside an indicator that is being used on back tester it will give you the back test time not current time.


@amusleh

heinrich.munz
03 Feb 2022, 10:36

RE:

amusleh said:

Hi,

In version 4.2 if you call Server.Time inside an indicator that is being used on back tester it will give you the back test time not current time.

When will version 4.2 be available from the brokers? Pepperstone and IC Markets still are on 4.1

 


@heinrich.munz

amusleh
03 Feb 2022, 10:38

RE: RE:

heinrich.munz said:

When will version 4.2 be available from the brokers? Pepperstone and IC Markets still are on 4.1

Hi,

Version 4.2 is a major release with lots of changes, we move from .NET framework to .NET 6.

It will be released this year but I can't give you an exact ETA.


@amusleh