LLV based on date

hi
I want LLV based on date. like 52week low frome todays date to last year same date, if todat date is 06/10/2021 i want to look back to 06/10/2020 . i want to find LLV from NOW date to -1 year.
thanks

/// Lowest Since last year date
/// (EOD code)
/// @link https://forum.amibroker.com/t/llv-based-on-date/27948/2
SetBarsRequired(260);
dt = DateTime();
now_dt = DateTimeConvert(2,Now(3));//LastValue(dt);
last_year_dt = DateTimeAdd(now_dt, -1, inYearly);
printf(DateTimeToStr(last_year_dt));
ll_since = LowestSince(DateTimeDiff(dt,last_year_dt) == 0, L);
Plot( C, "Price", colorDefault, styleBar );
Plot( ll_since, "ll_since", colorRed );

32

4 Likes

why we need to
SetBarsRequired(260) ??
thanks

Minimum required daily bars for one (business) year.
If you zoom in without it then you may get EMPTY results otherwise (also see QuickAFL).

1 Like

Simpler code:

OneYearBack = Now(3) - 10000; // 10000 is one year in YYYMMDD format
LowestSince( DateNum() <= OneYearBack, Low );
6 Likes

hi
After using it for couple of days. I reached to a problem. today is sunday(10/10/2021) and it does not show any LLV value.
can you put light on it please.
Thanks

because today is 10/10/201 year back 10/10/2020 have Saturday so no data on that day it show 0 . if there is year back trading halt. then again 0.

can I lock value to change when I scroll chart.

One may use Lookup function

/// Lowest/highest since last year date
/// (EOD code), version 1.1
/// @link https://forum.amibroker.com/t/llv-based-on-date/27948/8
period = 1;// look back period
tmfrm = inYearly;// ...inDaily, InMonthly, InYearly,..
SetBarsRequired(period*260);
dt = DateTime();
now_dt = DateTimeConvert(2,Now(3));//LastValue(dt);
last_year_dt = Lookup(dt, DateTimeAdd(now_dt, -period, tmfrm), 1);
is_start = DateTimeDiff(dt,last_year_dt) == 0;
ll_since = LowestSince(is_start, L);
hh_since = HighestSince(is_start, H);

Plot( C, "Price", colorDefault, styleBar );
Plot( ll_since, "ll_since", colorRed );
Plot( hh_since, "hh_since", colorGreen );
1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.