Volume profile displaced

mbeig

New member
Does anyone know how to displace the volume profile? I am using the following code to plot monthly POC, HVA, and LVA but I would like to displace the profile by 1 month (i.e. last month's profile is plotted on the current month and current month's developing profile is plotted into the future). Would appreciate any creative helps, ideas in moving the levels forward 1 month.

Code:
#
input pricePerRowHeightMode = {default TICKSIZE, AUTOMATIC, CUSTOM};
input customRowHeight = 1.0;
input timePerProfile = {default CHART, MINUTE, HOUR, DAY, 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 = 10;

def period;
def yyyymmdd = getYyyyMmDd();
def seconds = secondsFromTime(0);
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 HOUR:
    period = floor(seconds / 3600 + day_number * 24);
case DAY:
    period = countTradingDays(min(first(yyyymmdd), yyyymmdd), yyyymmdd) - 1;
case WEEK:
    period = floor(day_number / 7);
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 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);

plot HighValue = vol.GetHighestValueArea();
plot PointControl = vol.GetPointOfControl();
plot LowValue = vol.GetLowestValueArea();

HighValue.SetDefaultColor(color.white);
PointControl.SetDefaultColor(color.white);
LowValue.SetDefaultColor(color.white);

HighValue.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PointControl.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LowValue.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
 

tradebyday

Active member
The code to put a moving average forward or backward along the time axis of the chart is
Code:
input displace = 0;
Unsure if this will accomplish what you're looking for as I have not seen this done to anything as dynamic as volume profile, but in case you hadn't tried this yet, thought I'd share
 

mbeig

New member
@tradebyday There are some functions that accept a variable with a displaced value, Volume profile doesn't have an input that I can displace. This is also confusing for me as there is clearly a price aggregation that is being used as an input but it's not explicitly called in the list of inputs for Volume Profile. TimePerProfile is used to define the number of periods to use per profile, but I am unable to wrap my head around because displacing it won't change the number of bars per profile and won't displace the bars certainly Maybe a manual plot is the only option that's why I am looking for some of the more experienced members' help here.
 

SilverSurferAI

New member
2019 Donor
Here is the one I use. I use Volume profiles on all my charts, including tick, 5 minutes, 30 minute, daily. The key is ratios 5 minute chart I use a hourly or daily profile, 30 minute chart = Weekly Profile, Daily = Month Profile. I don't know where I originally received this code, but I have done some modification. It also has Fibonacci extensions. Play around with the setting, but I think it produces the desired responses. I know that the future value area doesn't appear until close to the time of the profile. So, for a monthly profile, it will appear on my chart possibility 1 to 2 before end of month.

Code:
# Profile TPO & Volume
# Personal setting: 
# Profile Type = Volume
# price per row height mode = Ticksize
# custom row height =1.0
# time per profile = Month
# multiplier = 1 (does nothing)
# on expansion = No
# profiles = 444 ;  This is used to show home many profiles on your chart
# show point of control = Yes;  Do you want to show or not
# show value area  = Yes;  Do you want a value area
# show value area cloud = Yes; Do you want the value area shaded
# value area percents = 70;  What is the size of the value area, sometimes use 68.1
# show high low = Yes; do you want to show the high and low price of profile
# opacity = 5 ; Do you want the shading of the profile to see it or not.  I like 5 faint in background
# paint bars = Yes;  Do you want to paint the bars Green above value, Red below value or grey when in value
# show extension = No;  Do you want to show the Fibonacci extensions
# dynamic hide extension = Yes;
# show label = No;

input profileType = {default Volume, Time};
input pricePerRowHeightMode = {default Ticksize, Automatic, Custom};
input customRowHeight = 1.0;
input timePerProfile = {default Day, Week, MIN5, MIN50, DayTwo, Month, Year, Minute, Hour, Chart, "Opt Exp", Bar};
input multiplier = 1;
input onExpansion = No;
input profiles = 2;
input showPointOfControl = Yes;
input showValueArea = Yes;
input showValueAreaCloud = Yes;
input ValueAreaPercent = 70;
input ShowHighLow = Yes;
input opacity = 5;
input PaintBars = No;
input ShowExtensions = No;
input DynamicHideExtensions = Yes;
input ShowLabel = No;
def FibExt1 = 1.618;
def FibExt2 = 2.618;
def FibExt3 = 4.236;
def SE = ShowExtensions;
def ShowProfileValueAreaCloud = no;


def period;
def yyyymmdd = GetYYYYMMDD();
def seconds = SecondsFromTime(0);
def month = GetYear() * 12 + GetMonth();
def year = GetYear();
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 MIN5:
    period = Floor(seconds / 300 + day_number * 24);
case MIN50:
    period = Floor(seconds / 3000 + day_number * 24);
case Hour:
    period = Floor(seconds / 3600 + day_number * 24);
case Day:
    period = CountTradingDays(Min(First(yyyymmdd), yyyymmdd), yyyymmdd) - 1;
case DayTwo:
    period = 172800000;
#CountTradingDays(Min(First(yyyymmdd), yyyymmdd), yyyymmdd) - 2;
case Week:
    period = Floor(day_number / 7);
case Month:
    period = Floor(month - First(month));
case Year:
    period = Floor(year - First(year));
case "Opt Exp":
    period = exp_opt - First(exp_opt);
case Bar:
    period = BarNumber() - 1;
}


def CloseByPeriod = close(Period = timePerProfile)[-1];
def Openbyperiod  = open(Period = timePerProfile)[-1];
def NewDay = if !IsNaN(CloseByPeriod) then 0 else 1;

rec Count = if period != period[1] then (Count[1] + period - period[1]) % 1 else Count[1];
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 = if profileType == profileType.Volume then VolumeProfile("startNewProfile" = Cond, "onExpansion" = onExpansion, "NumberOfProfiles" = profiles, "PricePerRow" = height, "Value Area Percent" = ValueAreaPercent) else TimeProfile("startNewProfile" = Cond, "OnExpansion" = onExpansion, "NumberOfProfiles" = profiles, "PricePerRow" = height, "Value Area Percent" = ValueAreaPercent);

def con = CompoundValue(1, onExpansion, no);
rec pc = if IsNaN(VOL.GetPointOfControl()) and con then pc[1] else VOL.GetPointOfControl();
rec hVA = if IsNaN(VOL.GetHighestValueArea()) and con then hVA[1] else VOL.GetHighestValueArea();
rec lVA = if IsNaN(VOL.GetLowestValueArea()) and con then lVA[1] else VOL.GetLowestValueArea();
rec HVA_Last = if period == period[1] then HVA_Last[1] else hVA[1];
rec PC_Last  = if period == period[1] then PC_Last[1]  else pc[1];
rec LVA_Last = if period == period[1] then LVA_Last[1] else lVA[1];
rec hProfile = if IsNaN(VOL.GetHighest()) and con then hProfile[1] else VOL.GetHighest();
rec lProfile = if IsNaN(VOL.GetLowest()) and con then lProfile[1] else VOL.GetLowest();
def plotsDomain = IsNaN(close) == onExpansion;

rec hP_Last = if period == period[1] then hP_Last[1] else hProfile[1];
rec lP_Last = if period == period[1] then lP_Last[1] else lProfile[1];


plot VAH  = if !showValueArea then Double.NaN else HVA_Last[0];
plot POC  = PC_Last[0];
plot VAL  = if !showValueArea then Double.NaN else LVA_Last[0];
plot High = if !ShowHighLow then Double.NaN else hP_Last[0];
plot Low = if !ShowHighLow then Double.NaN else lP_Last[0];
#plot p = VOL.getPointOfControl();


DefineGlobalColor("Profile", GetColor(7));
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 ShowProfileValueAreaCloud then GlobalColor("Value Area") else Color.CURRENT, opacity);

POC.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
POC.SetDefaultColor(Color.DARK_GRAY);
#POC.SetDefaultColor(CreateColor(32,49,57));
POC.SetLineWeight(1);
POC.HideTitle();

VAH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VAH.SetDefaultColor(Color.DARK_GREEN);
VAH.SetLineWeight(1);
VAH.HideBubble();
VAH.HideTitle();

VAL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VAL.SetDefaultColor(Color.DARK_RED);
VAL.SetLineWeight(1);
VAL.HideBubble();
VAL.HideTitle();

High.SetPaintingStrategy(PaintingStrategy.DASHES);
High.SetDefaultColor(CreateColor(38, 38, 8));
High.SetLineWeight(1);
High.HideBubble();
High.HideTitle();

Low.SetPaintingStrategy(PaintingStrategy.DASHES);
Low.SetDefaultColor(CreateColor(38, 38, 8));
Low.SetLineWeight(1);
Low.HideBubble();
Low.HideTitle();
#################### Paint Bars #######################

AssignPriceColor(if !PaintBars then Color.CURRENT else if open >= VAH and close >= VAH then Color.GREEN else if open <= VAL and close <= VAL then Color.RED else Color.GRAY);
#################### Value Area Cloud #######################
#DefineGlobalColor("Value Area Cloud", (CreateColor(20, 20, 20)));
DefineGlobalColor("Value Area Cloud", Color.DARK_GRAY);
#DefineGlobalColor("Value Area Cloud", Color.WHITE);
def cloudhigh = if showValueAreaCloud then HVA_Last else Double.NaN;
def cloudlow  = if showValueAreaCloud then LVA_Last else Double.NaN;
AddCloud (cloudhigh, cloudlow, GlobalColor("Value Area Cloud"));
#################### Chart Label #######################

def InsideValueArea = close < HVA_Last and close > LVA_Last;
def BelowValue = close < LVA_Last;

AddLabel(ShowLabel, close, if InsideValueArea then Color.GRAY else if BelowValue then Color.RED else Color.GREEN);
#################### Fibonacci Extensions #######################

def VAWidth = High - Low;

plot E1H = if SE < 1 then Double.NaN else High + VAWidth * (FibExt1 - 1);
E1H.SetHiding(DynamicHideExtensions and close < VAH);
E1H.SetDefaultColor(CreateColor(0, 51, 0));
E1H.SetPaintingStrategy(PaintingStrategy.DASHES);
E1H.SetLineWeight(1);
E1H.HideBubble();
E1H.HideTitle();
plot E1L = if SE < 1 then Double.NaN else Low - VAWidth * (FibExt1 - 1);
E1L.SetHiding(DynamicHideExtensions and close > VAL);
E1L.SetDefaultColor(CreateColor(51, 0, 0));
E1L.SetPaintingStrategy(PaintingStrategy.DASHES);
E1L.SetLineWeight(1);
E1L.HideBubble();
E1L.HideTitle();

plot E2H = if SE < 1 then Double.NaN else High + VAWidth * (FibExt2 - 1);
E2H.SetHiding(DynamicHideExtensions and close < E1H);
E2H.SetDefaultColor(CreateColor(0, 51, 0));
E2H.SetPaintingStrategy(PaintingStrategy.DASHES);
E2H.SetLineWeight(1);
E2H.HideBubble();
E2H.HideTitle();
plot E2L = if SE < 1 then Double.NaN else Low - VAWidth * (FibExt2 - 1);
E2L.SetHiding(DynamicHideExtensions and close > E1L);
E2L.SetDefaultColor(CreateColor(51, 0, 0));
E2L.SetPaintingStrategy(PaintingStrategy.DASHES);
E2L.SetLineWeight(1);
E2L.HideBubble();
E2L.HideTitle();

plot E3H = if SE < 1 then Double.NaN else High + VAWidth * (FibExt3 - 1);
E3H.SetHiding(DynamicHideExtensions and close < E2H);
E3H.SetDefaultColor(CreateColor(0, 51, 0));
E3H.SetPaintingStrategy(PaintingStrategy.DASHES);
E3H.SetLineWeight(1);
E3H.HideBubble();
E3H.HideTitle();
plot E3L = if SE < 1 then Double.NaN else Low - VAWidth * (FibExt3 - 1);
E3L.SetHiding(DynamicHideExtensions and close > E2L);
E3L.SetDefaultColor(CreateColor(51, 0, 0));
E3L.SetPaintingStrategy(PaintingStrategy.DASHES);
E3L.SetLineWeight(1);
E3L.HideBubble();
E3L.HideTitle();
 

Similar threads

Top