Login Page - Create Account

Support Board


Date/Time: Mon, 25 Nov 2024 20:42:52 +0000



Post From: Renko Chart Bar Based Backtesting Flattening Issue

[2024-02-17 16:32:06]
User43 - Posts: 101
Sorry, I could have saved the detail about time based checking.
I'm aware that bars on a renko charts don't close on specific time.

User61168 made a great suggestion, which I'll try eventually.
Not 100% sure though if it will manage closing precisely when doing bar based back test, or replay with acceleration.

In my scripting I use the following to close my position based on passing a specific time.

int BarTime = sc.BaseDateTimeIn[sc.Index].GetTime();
bool TradingAllowed =
(
!Input_TradingUseTimes.GetYesNo()
||
(BarTime >= Input_TradingStartTime1.GetTime() &&
BarTime < Input_TradingEndTime1.GetTime())
||
(BarTime >= Input_TradingStartTime2.GetTime() &&
BarTime < Input_TradingEndTime2.GetTime())
);

bool CloseAll =
(Input_TradingUseTimes.GetYesNo()
&&
BarTime >= Input_CloseOpenPositionTime.GetTime()
);

When CloseAll becomes true I'll exit all open positions.
In the past when I compared using equal
BarTime == Input_CloseOpenPositionTime.GetTime()
my positions would not close as expected when trading on a volume chart or having a misaligned time base and exit time.

So I changed it to compare >= (equal or greater) which works fine for me.
Since I don't want to hold my positions into the close I use a close time of 15:55 (5 minutes before close). That probably can be pushed closer to 16:00.
I think something like 15:59:50 (10 seconds before market close) might still work.

If you want to exit precisely at a specific time in your script, you need to take several details into account.
ACSIL Interface Members - Variables and Arrays: sc.CurrentDateTimeForReplay only works on replay and recommends to turn on ACSIL Interface Members - Variables and Arrays: sc.UpdateAlways . The description also states that during accelerated replay not each second might be triggered.

However, when there is an accelerated replay, a study function will not necessarily be called at the interval specified by the Chart Update Interval relative to the replay times. For example, if the chart is set to update every 1000 milliseconds, during an accelerated replay it will not necessarily be called every theoretical second when using sc.UpdateAlways = 1.

Also internally time values are floating point variables.
Therefore they suffer from precision issues when comparing them.
see ACSIL Programming Concepts: Floating Point Value Error