More filtering than just day/night sessions


In Hong Kong, the Futures market runs at 9:15-12:00, 13:00-16:30 and 17:15-01:00 next day. I need to filter out the noisy data in those inactive gaps (such as time between 12:00-13:00 and so on) so as not to affect the Indicators. Only the Day & Night sessions in Intraday/Database settings are not sufficient. Is there a way to add more Filtering sessions, either by configuration or AFL? Thanks.

You may use Sparse functions.

I'm not going to spoon feed how to get to sample output of 2nd chart pane.
Try yourself first and post here (no matter if getting stuck or not).
(I am going to show my version if you show some own efforts first.)


Upper picture shows 24h trading.

But in your case you may do like so as seen below (plus including Sparse AFL functions). So in second case you would have to exclude only time window from 16:30:00 to 17:14:59 via Sparse AFL functions.


1 Like

Thanks. This is useful.

I would use sar() in my trading program but this function doesn't accept array as its parameter. How can I fit the compressed array into it?

If an inbuilt indicator function (such as ATR, SAR, MACD, ...) does not have function arguments for inserting source array then simply override inbuilt OHLC, V, OI, AUX1, AUX2 arrays via Sparse.. before. SAR() depends on H and L. So you would only need to override those two arrays.

H = SparseCompress( condition, H );

And at the end after sparse array has been finished use RestorePriceArrays() function for restoring inbuilt arrays to original state.

With 24h enabled (so all sessions being defined via Sparse.. in 2nd pane)

Or just Day and Night session set in Database settings plus 16:30 to 17:15 excluded via Sparse.
Same results in 2nd pane compared to 1st picture.


@sunparts09 apart from many other examples which you can find on this forum (lots of them provided by @fxshrat), you can study the example codes wrote by Tomasz in this thread (a similar issue).

@sunparts09 another hint (showing how to restrict trading to certain time of the day):

After reading this article and studying SparseCompress()/SparseExpand() functions, you should be able to accomplish your goal...

Good reference. Thanks. I'll test it tomorrow.