Can anyone help with exploration code to for Highest Previous Week and Previous Month Daily Volume?
Thank you
You need to read here about how to create proper post! Your post is still too ambiguously worded.
If you look for highest previous week's daily bar volume and highest previous month's daily bar volume then one may do like so:
/// AmiBroker forum code to get
/// highest previous week's daily bar volume
/// and highest previous month's daily bar volume
/// @link https://forum.amibroker.com/t/volume-exploration-afl-needed/11326/2
Version(6.20);
mth = Month();
dow = DayOfWeek();
new_week = dow < Ref(dow, -1);
new_mth = mth != Ref(mth, -1);
prev_week_hhvol = ValueWhen(new_week, HighestSince(new_week, V, 2));
prev_mth_hhvol = ValueWhen(new_mth, HighestSince(new_mth, V, 2));
Filter = 1;
AddMultiTextColumn(new_week, "\nNew Week", "New Week?", 1);
AddmultitextColumn(new_mth, "\nNew Month", "New Month?", 1);
AddColumn(V, "Volume", 1);
AddColumn(prev_week_hhvol, "prev_week_hhvol", 1);
AddColumn(prev_mth_hhvol, "prev_mth_hhvol", 1);
@raahularya you have an answer now from @fxshrat who posted a minute before I could, but since I tried a solution that is different I thought I would post it too. In AmiBroker there are often many different paths to a solution.
/// @link https://forum.amibroker.com/t/volume-exploration-afl-needed/11326
WeeklyMaxVolume = TimeFrameCompress( V, inWeekly, compressHigh );
PrevWeekMaxVolume = TimeFrameExpand( Ref( WeeklyMaxVolume , -1 ), inWeekly, expandFirst );
MonthlyMaxVolume = TimeFrameCompress( V, inMonthly, compressHigh );
PrevMonthMaxVolume = TimeFrameExpand( Ref( MonthlyMaxVolume , -1 ), inMonthly, expandFirst );
Filter = 1;
AddColumn( V, "Volume", 1.0 );
AddColumn( PrevWeekMaxVolume, "Previous Week Max V", 1.0 );
AddColumn( PrevMonthMaxVolume, "Previous Month Max V", 1.0 );
FWIW, using TimeframeCompress and TimeframeExpand is 30%-40% slower than what has been posted in second post.
@fxshrat @portfoliobuilder - Thank you very much. Is there a way even highest 5 minute volume for last weekl and month can be added to same exploration
Also, is it possible to plot lines on High Low Value of corresponding volume. I tried using ValueWhen function but that doesnt help as it plots on latest candle instead of corresponding Highest weekly volume or Highest monthly volume candle
There is always a way!
You have to run on 5-minute TF then. And for daily volume using Time Frame function.
/// AmiBroker forum code to get
/// highest previous week's intraday+EOD bar volume
/// and highest previous month's intraday+EOD bar volume
/// @link https://forum.amibroker.com/t/volume-exploration-afl-needed/11326/7
Version(6.20);
/// one month has 20 to 23 business days
/// so to be save we use 50 (two months)
SetBarsRequired(50*inDaily/Max(1,Interval()));
mth = Month();
dow = DayOfWeek();
new_week = dow < Ref(dow, -1);
new_mth = mth != Ref(mth, -1);
prev_week_hhvol = ValueWhen(new_week, HighestSince(new_week, V, 2));
prev_mth_hhvol = ValueWhen(new_mth, HighestSince(new_mth, V, 2));
Daily_Vol = TimeFrameGetPrice( "V", inDaily, 0 );
prev_week_dhhvol = ValueWhen(new_week, HighestSince(new_week, Daily_Vol, 2));
prev_mth_dhhvol = ValueWhen(new_mth, HighestSince(new_mth, Daily_Vol, 2));
Filter = 1;
AddTextColumn( Interval(2), "Interval", 1 );
AddMultiTextColumn(new_week, "\nNew Week", "New Week?", 1);
AddmultitextColumn(new_mth, "\nNew Month", "New Month?", 1);
AddColumn(V, "Volume", 1);
AddColumn(prev_week_hhvol, StrFormat("prev week highest %s Volume", Interval(2)), 1);
AddColumn(prev_mth_hhvol, StrFormat("prev month highest %s Volume", Interval(2)), 1);
AddColumn(prev_week_dhhvol, "prev week highest EOD Volume", 1);
AddColumn(prev_mth_dhhvol, "prevn month highest EOD Volume", 1);
Awesome. But I want to get price levels (high Low) as well for the corresponding Volume as well. would that be possible?. I tried using Valuewhen but that doesnt help. Can you guide?
"Everything" is possible.
But the thing is you ask for handing over full code all the time and say you have tried.
But what have you tried? No one here can see anything you have tried.
Yes, you can get High/Low by using ValueWhen.
If it does not work for you then you have written incorrect code.
You need to use 'Code Tags' for your code.
See How to ask a good question.
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
Version(6.20);
mth = Month();
dow = DayOfWeek();
new_week = dow < Ref(dow, -1);
new_mth = mth != Ref(mth, -1);
prev_week_hhvol = ValueWhen(new_week, HighestSince(new_week, V, 2));
prev_mth_hhvol = ValueWhen(new_mth, HighestSince(new_mth, V, 2));
weekPrice=prev_week_hhvol ;
weeklow1=ValueWhen(Volume==weekPrice,Low);
weekhigh1=ValueWhen(Volume==weekPrice,High);
Filter = 1;
AddMultiTextColumn(new_week, "\nNew Week", "New Week?", 1);
AddmultitextColumn(new_mth, "\nNew Month", "New Month?", 1);
AddColumn(V, "Volume", 1);
AddColumn(prev_week_hhvol, "prev_week_hhvol", 1);
AddColumn(prev_mth_hhvol, "prev_mth_hhvol", 1);
AddColumn(weekLow1, "Week Low Price", 1);
AddColumn(weekHigh1, "Week High Price", 1);
Plot(weeklow1,"Highest Vol low",colorBlue,styleThick);
Plot(weekhigh1,"Highest Vol high",colorBlue,styleThick);
I am using Valuewhen function in above code to find High/Low values for the Exploration Candle with highest weekly volume, buts its not giving me correct results. Please help. Also I need to Plot lines re High/Low of the candle on Chart