AdamantBidoof
New member
Hi, I found this code
https://usethinkscript.com/threads/volume-profile-poc-plotted-forward-thinkorswim.8217/
Tweaked it a bit with my limited knowledge of copy pasta and trail and error in different time profiles. Is there a way I can add the Actual histogram of volume profile of the previous timed session?
If someone can help to achieve this or tell me its not possible thats fine too haha.
Thanks for your help
@samer800 @chewie76
https://usethinkscript.com/threads/volume-profile-poc-plotted-forward-thinkorswim.8217/
Tweaked it a bit with my limited knowledge of copy pasta and trail and error in different time profiles. Is there a way I can add the Actual histogram of volume profile of the previous timed session?
Code:
#VolumeProfile_PreviousDay_displayed_NextDay
#20190426 Sleepyz
#20210712 Sleepyz - revised to add option for pricePerRowHeightMode rather than just automatic
input pricePerRowHeightMode = {default AUTOMATIC, TICKSIZE, CUSTOM};
input customRowHeight = 1.0;
input bubblemover = 4.0;
def height;
switch (pricePerRowHeightMode) {
case AUTOMATIC:
height = PricePerRow.AUTOMATIC;
case TICKSIZE:
height = PricePerRow.TICKSIZE;
case CUSTOM:
height = customRowHeight;
}
input timePerProfile = {CHART, MINUTE, THIRTY_MINUTES, HOUR, TWO_HOURS, FOUR_HOURS, default DAY, WEEK, MONTH, "OPT EXP", BAR};
input multiplier = 1;
input profiles = 1000;
input showPreviousPointOfControl = yes;
input showPreviousValueArea = yes;
input valueAreaPercent = 70;
input opacity = 50;
input onExpansion = yes;
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 THIRTY_MINUTES:
period = Floor(seconds / 1800 + day_number * 24 * 60);
case HOUR:
period = Floor(seconds / 3600 + day_number * 24);
case TWO_HOURS:
period = Floor(seconds / 7200 + day_number * 24);
case FOUR_HOURS:
period = Floor(seconds / 14400 + 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];
profile vol = VolumeProfile("startNewProfile" = cond, "numberOfProfiles" = profiles, "pricePerRow" = height, "value area percent" = valueAreaPercent, onExpansion = no);
#Prior Day High/Low ValueAreas
def HVA = if IsNaN(vol.GetHighestValueArea()) then HVA[1] else vol.GetHighestValueArea();
def pHVA = CompoundValue(1, if cond then HVA[1] else pHVA[1], Double.NaN);
def LVA = if IsNaN(vol.GetLowestValueArea()) then LVA[1] else vol.GetLowestValueArea();
def pLVA = CompoundValue(1, if cond then LVA[1] else pLVA[1], Double.NaN);
def plotsDomain = IsNaN(close) == onExpansion;
plot PrevHVA = pHVA;
plot PrevLVA = pLVA;
PrevHVA.SetDefaultColor(Color.YELLOW);
PrevLVA.SetDefaultColor(Color.YELLOW);
PrevHVA.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PrevLVA.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
AddCloud(PrevHVA , PrevLVA , Color.LIGHT_GRAY);
#Prior Day POC Calculated
def POC = if IsNaN(vol.GetPointOfControl()) and cond then POC[1] else vol.GetPointOfControl();
def pPOC = CompoundValue (1, if cond then POC[1] else pPOC[1], Double.NaN);
plot PrevPOC = pPOC;
PrevPOC.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PrevPOC.SetDefaultColor(Color.MAGENTA);
profile volume = VolumeProfile("startNewProfile" = cond, "onExpansion" = onExpansion, "numberOfProfiles" = profiles, "pricePerRow" = height, "value area percent" = valueAreaPercent);
def con = CompoundValue(1, onExpansion, no);
#Prior Day highProfile/LowProfile
def hProfile = if IsNaN(vol.GetHighest()) and con then hProfile[1] else vol.GetHighest();
def php = CompoundValue(1, if cond then hProfile[1] else php[1], Double.NaN);
def lProfile = if IsNaN(vol.GetLowest()) and con then lProfile[1] else vol.GetLowest();
def plP = CompoundValue(1, if cond then lProfile[1] else plP[1], Double.NaN);
plot prevHProfile = php;
plot prevLProfile = plP;
prevHProfile.SetDefaultColor(Color.YELLOW);
prevLProfile.SetDefaultColor(Color.YELLOW);
prevHProfile.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
prevLProfile.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DefineGlobalColor("Profile", GetColor(1));
DefineGlobalColor("Point Of Control", GetColor(5));
DefineGlobalColor("Value Area", GetColor(8));
vol.Show(GlobalColor("Profile"), if showPreviousPointOfControl then GlobalColor("Point Of Control") else Color.CURRENT, if showPreviousValueArea then GlobalColor("Value Area") else Color.CURRENT, opacity);
prevPOC.SetDefaultColor(GlobalColor("Point Of Control"));
prevPOC.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PrevHVA.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PrevLVA.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PrevHVA.SetDefaultColor(GlobalColor("Value Area"));
PrevLVA.SetDefaultColor(GlobalColor("Value Area"));
prevHProfile.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
prevLProfile.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
prevHProfile.SetDefaultColor(GetColor(3));
prevLProfile.SetDefaultColor(GetColor(3));
prevHProfile.Hide();
prevLProfile.Hide();
If someone can help to achieve this or tell me its not possible thats fine too haha.
Thanks for your help
@samer800 @chewie76
Last edited by a moderator: