Is there a way to add a Custom timeframe in a value area- that shows trailing Days/Hours rather then starting at fix time/day.
Meaning in the attached code, Value area for week starts on Monday on only. But on Tuesday if I want to see the volume of last 5 trading days I cant see. Similarly 4 hours starts on start time I put but not trailing 4 hours.
Thanks in advance
Meaning in the attached code, Value area for week starts on Monday on only. But on Tuesday if I want to see the volume of last 5 trading days I cant see. Similarly 4 hours starts on start time I put but not trailing 4 hours.
Thanks in advance
Code:
# Archive Name: VolumeProfile with Expanded Intraday Period Selections plus the Prior Day's Value Areas
# Archive Section: Volume
# Suggested Tos Name: VolumeProfileIntradayPeriods_Unknown
# Archive Date: 5.05.2018
# Archive Notes: found in stanL's treebase but that crashed. Mobius found this one.
#VolumeProfile with Expanded Intraday Period Selections plus the Prior Day's Value Areas
input pricePerRowHeightMode = {default AUTOMATIC, TICKSIZE, CUSTOM};
input customRowHeight = 1.01;
input timePerProfile = {CHART, MINUTE, MIN2, MIN3, MIN4, MIN5, MIN10, MIN15, MIN20, default MIN30, HOUR, FOURHOURS, SIXHOURS, EIGHTHOURS, TWELVEHOURS, DAY, tendays, fivedays, WEEK, MONTH, "OPT EXP", BAR};
input multiplier = 1;
input onExpansion = no;
input profiles = 1000;
input showPointOfControl = yes;
input showValueArea = yes;
input valueAreaPercent = 70;
input opacity = 20; # 5.05.2018 JQ original was 50
INPUT TIME = 2300;
def period;
def yyyymmdd = GetYYYYMMDD();
def seconds = SecondsFromTime(TIME);
def month = GetYear() * 12 + GetMonth();
def day_number = DaysFromDate(First(yyyymmdd)) + GetDayOfWeek(First(yyyymmdd));
def dom = GetDayOfMonth(yyyymmdd);
def dow = GetDayOfWeek(yyyymmdd - dom + 1);
def expthismonth = (if dow > 5 then 27 else 20) - dow;
def exp_opt = month + (dom > expthismonth);
switch (timePerProfile) {
case CHART:
period = 0;
case MINUTE:
period = Floor(seconds / 60 + day_number * 24 * 60);
case MIN2:
period = Floor(seconds / 120 + day_number * 24);
case MIN3:
period = Floor(seconds / 180 + day_number * 24);
case MIN4:
period = Floor(seconds / 240 + day_number * 24);
case MIN5:
period = Floor(seconds / 300 + day_number * 24);
case MIN10:
period = Floor(seconds / 600 + day_number * 24);
case MIN15:
period = Floor(seconds / 900 + day_number * 24);
case MIN20:
period = Floor(seconds / 1200 + day_number * 24);
case MIN30:
period = Floor(seconds / 1800 + day_number * 24);
case HOUR:
period = Floor(seconds / 3600 + day_number * 24);
case EIGHTHOURS:
period = Floor(seconds / 30600 + day_number * 24);
case SIXHOURS:
period = Floor(seconds / 21600 + day_number * 24);
case FOURHOURS:
period = Floor(seconds / 14400 + day_number * 24);
case TWELVEHOURS:
period = Floor(seconds / 43200 + day_number * 24);
case DAY:
period = CountTradingDays(Min(First(yyyymmdd), yyyymmdd), yyyymmdd) - 1;
case WEEK:
period = Floor(day_number / 7);
case fivedays:
period = Floor(day_number / 10);
case tendays:
period = Floor(day_number / 15);
case MONTH:
period = Floor(month - First(month));
case "OPT EXP":
period = exp_opt - First(exp_opt);
case BAR:
period = BarNumber() - 1;
}
def count = CompoundValue(1, if period != period[1] then (count[1] + period - period[1]) % multiplier else count[1], 0);
#def volcount = if period != period[1] then volume else volcount[1]+volume;
#addlabel(yes,volcount,color.white);
def cond = count < count[1] + period - period[1];
def height;
switch (pricePerRowHeightMode) {
case AUTOMATIC:
height = PricePerRow.AUTOMATIC;
case TICKSIZE:
height = PricePerRow.TICKSIZE;
case CUSTOM:
height = customRowHeight;
}
profile vol = VolumeProfile("startNewProfile" = cond, "onExpansion" = onExpansion, "numberOfProfiles" = profiles, "pricePerRow" = height, "value area percent" = valueAreaPercent);
def con = CompoundValue(1, onExpansion, no);
def pc = if IsNaN(vol.GetPointOfControl()) and con then pc[1] else vol.GetPointOfControl();
def hVA = if IsNaN(vol.GetHighestValueArea()) and con then hVA[1] else vol.GetHighestValueArea();
def lVA = if IsNaN(vol.GetLowestValueArea()) and con then lVA[1] else vol.GetLowestValueArea();
def hProfile = if IsNaN(vol.GetHighest()) and con then hProfile[1] else vol.GetHighest();
def lProfile = if IsNaN(vol.GetLowest()) and con then lProfile[1] else vol.GetLowest();
def plotsDomain = IsNaN(close) == onExpansion;
plot POC = if plotsDomain then pc else Double.NaN;
plot ProfileHigh = if plotsDomain then hProfile else Double.NaN;
plot ProfileLow = if plotsDomain then lProfile else Double.NaN;
plot VAHigh = if plotsDomain then hVA else Double.NaN;
plot VALow = if plotsDomain then lVA else Double.NaN;
DefineGlobalColor("Profile", GetColor(1));
DefineGlobalColor("Point Of Control", GetColor(5));
DefineGlobalColor("Value Area", GetColor(8));
vol.Show(GlobalColor("Profile"), if showPointOfControl then GlobalColor("Point Of Control") else Color.CURRENT, if showValueArea then GlobalColor("Value Area") else Color.CURRENT, opacity);
POC.SetDefaultColor(GlobalColor("Point Of Control"));
POC.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VAHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VALow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VAHigh.SetDefaultColor(GlobalColor("Value Area"));
VALow.SetDefaultColor(GlobalColor("Value Area"));
ProfileHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ProfileLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ProfileHigh.SetDefaultColor(GetColor(3));
ProfileLow.SetDefaultColor(GetColor(3));
ProfileHigh.Hide();
ProfileLow.Hide();
#Prior Day Profile - counting formula by functionform
rec count1 = CompoundValue(1, if !(GetDay() != GetDay()[1]) then count1[1] + 1 else 1, 1);
def priorperiod = if IsNaN(count1[1]) then 1 else Max(count1, count1[1]);
profile vol1 = VolumeProfile("startNewProfile" = GetDay() != GetDay()[1], "onExpansion" = no);
def vahprior = vol1.GetHighestValueArea();
def pocprior = vol1.GetPointOfControl();
def valprior = vol1.GetLowestValueArea();
plot vahprev = GetValue(vahprior, priorperiod);
vahprev.SetDefaultColor(Color.MAGENTA);
vahprev.SetPaintingStrategy(paintingStrategy = PaintingStrategy.HORIZONTAL);
vahprev.SetLineWeight(1);
vahprev.HideBubble();
plot pocprev = GetValue(pocprior, priorperiod);
pocprev.SetDefaultColor(Color.MAGENTA);
pocprev.SetPaintingStrategy(PaintingStrategy.POINTS);
pocprev.SetLineWeight(1);
pocprev.HideBubble();
plot valprev = GetValue(valprior, priorperiod);
valprev.SetDefaultColor(Color.MAGENTA);
valprev.SetPaintingStrategy(paintingStrategy = PaintingStrategy.HORIZONTAL);
valprev.SetLineWeight(1);
valprev.HideBubble();
Last edited by a moderator: