Subsetting data according to dates

Hello, i am trying to fetch the value of lowest low of bollinger band top for a 75 min chart on any particular date. i tried to use datenum in order to reference any perticular day and use LLV function to get the value inside a valuewhen funtion but it did not work, please help.


abc = ValueWhen(DateNum()==DateNum()-2,LLV(BBandTop(C,20),4));

http://www.amibroker.com/guide/afl/datenum.html
DateNum returns an array with numbers like
1011231

for example

1011231 == (1011231 -2 )

Does make sense for you ?

2 Likes

@Nubee
Review the AFL Reference Manual, particularly the sections on Comparison Operators and the Assignment Operator.

Your code makes it look like as if you want to get LLV result of two bars ago. If that is the case then use Ref() function.

n_bars = 2;
bb_llv = LLV(BBandTop(C,20),4);
bb_llv_prev = Ref(bb_llv, -n_bars);// llv of n-bars ago

Or if you want to get LLV value by inserting particular date then use Lookup() function.

my_date = "2020-01-28"; // or "2020-01-28 12:00"; //etc...
bb_llv = LLV(BBandTop(C,20),4);// array
bb_llv_lkup = LookUp(bb_llv, _DT(my_date), mode = 0);// number
3 Likes

thank you for your reply, i used the solution you provided using Ref() function, this resolves my issue on end of day basis, but in real time as new bars are formed the reference bar changes and hence the solution does not work. I cannot use lookup as date will also change everyday.
precisely,the reason i wanted to reference the date for yesterday or day before yesterday, as it wont change with new bars being formed.

You see, here we have a problem again.
You are not precise enough (see first post).
It is unknown what you want to reference exactly. It is speculation.
Do you want to get previous days daily LLV of daily BB on intraday chart?
Or do you want to look back n-intraday bars at end of (previous) day on same intraday interval?
What is it?

That's why please read here and please provide full detail. Otherwise you make answerer wasting too much time. E.g. I do love efficiency and hate long winded back-and-forth threads leading to no where.


Other than that how to use time frame functions is laid out here
https://www.amibroker.com/guide/h_timeframe.html
(BTW, if you want to look at daily interval from 75-min interval then you should note that
86400 seconds (daily) divided by 4500 sec. (75-min) results in 19.2. So result has fraction.)
As manual says:

AFL Function Reference - TIMEFRAMESET
To get other intervals you can use multiple of pre-defined intervals, for example: ( 3*in1Minute ) gives 3 minute bars. Or you can use 3 * inDaily for 3-day bars.


Further information... If that's not what you want then

"new day" flag (on intra-day interval) is

dn = DateNum();
new_day = dn != Ref( dn, -1);

So e.g. bar before new day would be

bi = BarIndex();
prev_day_bar = ValueWhen(new_day, Ref(bi, -1));// value at end of prev. day

In similar fashion LLV at end of previous day would be

bb_llv = LLV(BBandTop(C,20),4);
prev_day_llv = ValueWhen(new_day, Ref(bb_llv, -1));// value at end of prev. day

So now from there looking back further n-bars would be

n_bars = 2;
bb_llv = LLV(BBandTop(C,20),4);
bb_llv_prev = Ref(bb_llv, -n_bars);// llv of n-bars ago
prev_day_llv = ValueWhen(new_day, Ref(bb_llv_prev, -1));// value at end of prev. day

So as you can see we are back at using Ref() all the time.
We just changed where to look from.


How to debug formula is to be found here