Highest Aux1 in previous day

how to get highest Aux1 in previous day.
from this forum i get the intraday Highest of Aux1 by

NewDay = Day() != Ref(Day(), -1);
Bars_so_far_today = 1 + BarsSince( NewDay);
Intra DayH Aux1= HHV( a1, Bars_so_far_today );

It is not clear what you are looking for because of upper quote.

The code you posted (cleaned up):

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

array = H;// or Aux1 etc...
Bars_so_far_today = BarsSince( newday ) + 1;
Today_Highest_Since = HHV( array, Bars_so_far_today );

does output highest since day start for entire array already.
That's how array processing works. So if you plot it then you will see that it outputs "today" and "in previous day(s)".

218


Now, if you mean to output highest of yesterday on today's date then
you do not need BarsSince and HHV.

Just use HighestSince function.

/// @link https://forum.amibroker.com/t/highest-aux1-in-previous-day/12945/2
daysback = 1;
SetBarsRequired(daysback*inDaily/Max(1,Interval()));

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

array = H; // or Aux1 etc...

Today_Highest_Since = HighestSince(newday, array);
Yesterday_Highest_Since = HighestSince(newday, array, 2); // Output "yesterday's" highest array on "today's" date.

Plot( C, "Price", colorDefault, styleBar );

Plot( Today_Highest_Since, "Today_Highest_Since", colorGreen, styleStaircase );
Plot( Yesterday_Highest_Since, "Yesterday_Highest_Since", colorPaleGreen, styleStaircase );

52


Alternatively to HighestSince you may use TimeFrame functions.
Read about it here.

5 Likes

One adjustment (not a fix) to upper 2nd code...
Since it may happen that today's high may be higher than yesterday's highest high value then
this line

Yesterday_Highest_Since = HighestSince(newday, array, 2); // Output "yesterday's" highest array on "today's" date.

would not keep steady at yesterday's highest but would adjust to today's highest then.

So in order to prevent that we simply add Valuewhen function (to keep it steady).

/// @link https://forum.amibroker.com/t/highest-aux1-in-previous-day/12945/3
daysback = 2;
SetBarsRequired(daysback*inDaily/Max(1,Interval()));

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

array = H; // or Aux1 etc...

Today_Highest_Since = HighestSince(newday, array);
Yesterday_Highest_Since = ValueWhen(newday, HighestSince(newday, array, 2)); // Output "yesterday's" highest array on "today's" date.

Plot( C, "Price", colorDefault, styleBar );
Plot( Today_Highest_Since, "Today_Highest_Since", colorGreen, styleStaircase );
Plot( Yesterday_Highest_Since, "Yesterday_Highest_Since", colorPaleGreen, styleStaircase );

Now we could also use TimeFrame functions to get highest yesterday's highest array

/// @link https://forum.amibroker.com/t/highest-aux1-in-previous-day/12945/3
dn = DateNum();
newday = dn != Ref( dn, -1);

array = H; // or Aux1 etc...

Today_Highest_Since = HighestSince(newday, array);

tmfrm = inDaily;
yesterday_highest = TimeFrameCompress(array, tmfrm, compressHigh);
yesterday_highest = TimeFrameExpand(yesterday_highest, tmfrm, expandLast);

Plot( C, "Price", colorDefault, styleBar );
Plot( Today_Highest_Since, "Today_Highest_Since", colorGreen, styleStaircase );
Plot( yesterday_highest, "yesterday_highest", colorPaleGreen, styleStaircase );

/// reducing bars loaded by TimeFrameCompress
daysback = 2;
SetBarsRequired(daysback*inDaily/Max(1,Interval()));

As aside, if you use Volume data in Aux fields and want to use time frame functions then read following one also

5 Likes