Using Multiple Timeframes For Backtest - Future Peaking?

Hello,

I am backtesting a strategy on a 5min intraday bars.

I have this code that checks, if today's volume (on daily) is higher than 10-Day average, then go long at 10:25:00 AM bar's close, sell either at session close or 1% stop loss.

My question is, if I am using this formula code:

tn = TimeNum();

opentn = TimeNum();
opencondition = 102500 <=opentn AND  opentn <= 102959;
closetn = TimeNum();
closecondition = 155500 <=opentn AND  opentn <= 155559;

TimeFrameSet(inDaily);
AverageVolume = MA(V,10);
TodayV 	= V;
TimeFrameRestore();
TodayV 					= TimeFrameExpand(TodayV , inDaily, expandFirst);
AverageVolume			= TimeFrameExpand(AverageVolume , inDaily, expandFirst);

Buycondition = TodayV > AverageVolume AND opencondition;

Does this code checks the total daily volume value at 10:25AM bar(volume so far into the session) or at the session close(therefore, it peaks into the future)?

Thanks

I assume it would peak. What if you compare current day for each new bar with average of previous 10 days?

// option 1:
TimeFrameSet(inDaily);
AverageVolume = Ref( MA(V,10), -1);
// TodayV 	= V;   // not required
TimeFrameRestore();

// Option 2: can re-write TimeFrameSet() block with TimeFrameGetPrice() and shift = -1
AverageVolume   = MA( TimeFrameGetPrice( "V", inDaily, -1, expandFirst), 10);

// then,
AverageVolume	= TimeFrameExpand(AverageVolume , inDaily, expandFirst);
newDay          = Day() != Ref( Day(), -1 );
TodayV 			= SumSince( newDay, V);

Thanks,

When I checked manually by plotting the volume on my chart I saw, that trades were taken when I had an increased volume between 9:30 AM and 10:30 AM bars, so I assume it does check volume so far and then compares to the previous 10-Day, 9:30-10:30 AM periods.

@Tomasz can u please clarify?

Thanks

No, it's not like that. If you want total daily volume in 5m, you will need to sum. SumSince() will give you a running incremental for every successive 5m bar.

You can plot all the variables or even better search, how to debug my formula, and you Analysis Explore to table all the variables at each bar.
It will help you understand easily.

Thanks @nsm51

but appears that SumSince() is undefined, I can't seemed to figure out.

I used your code and here down below mine.

I tried this way

// Define the start and end times
StartTime = 093000; // 9:30 AM in HHMMSS format
EndTime = 102959;   // 10:29:59 AM in HHMMSS format

// Time period
InTimeRange = TimeNum() >= StartTime AND TimeNum() <= EndTime;

// Calculate the total volume between 9:30 AM and 10:29:59 AM
TotalVolume = SumSince(V, InTimeRange);

// Display the total volume
Plot(TotalVolume, "Total Volume 9:30 AM - 10:29:59 AM", colorBlue, styleHistogram);

yes, I tried with exploration

if I use

TotalVolume =  Sum(V, TimeNum() >= 093000 AND TimeNum() <= 102500);

It only displays volume for each 5min volume bar, but not as one.

Which version of Amibroker do you have ?

Anyway in help file there is an example how to use Sum as SumSince

https://www.amibroker.com/guide/afl/sumsince.html

Thanks,

I did find too, just can't figure out why it doesn't work.

I have 6.00.2

That might be the case.

Thanks

Two things wrong,
First is syntax, condition is 1st Paramter

2nd, inTimeRange will not work because it is not the same as new day.
'Since' In AB should be true once and then false for subsequent bars

What you want is SUM-IF, which can be done with CUM. See this thread

Now, it's not clear what your logic exactly is. Kindly explain in detail. Are you trying to add volume in range or beginning of day.

1 Like

I am trying to compare volume that occurs between 9:30 and 10:29:59, if its higher than 10-Day average, I enter the trade.

You have been shown the way to go. just read thread again.
Even if you have older version (which you should really upgrade) but there Tomasz has put an alternate way to calculate SumSince() using Sum() which @awilson has circled.

It worked, as planned

Thanks