daytrader023042
New member
Hello all,
Not sure if what I'm looking to accomplish is possible, but thought asking you smart folks was worth a try. I am trying to build a watchlist column (5M aggregation) that will return a signal depending on how the value area high/low has changed on a daily volume profile. The code I have found below seems to correctly return todays value area high and low, as well as the prior days value area high and low. However, I would also like to pull the value area high and low for prior days as well, such as 2 days ago, 3 days ego, etc.. I don't need help setting up the signal or anything, as I've learned enough ThinkScript from this great community to take care of that part.
Currently, the following variables appear to return the correct values:
Not sure if what I'm looking to accomplish is possible, but thought asking you smart folks was worth a try. I am trying to build a watchlist column (5M aggregation) that will return a signal depending on how the value area high/low has changed on a daily volume profile. The code I have found below seems to correctly return todays value area high and low, as well as the prior days value area high and low. However, I would also like to pull the value area high and low for prior days as well, such as 2 days ago, 3 days ego, etc.. I don't need help setting up the signal or anything, as I've learned enough ThinkScript from this great community to take care of that part.
Currently, the following variables appear to return the correct values:
- VAHigh -> Returns current day VAH
- VALow -> Returns current day VAL
- vahprev -> Returns prior day VAH
- valprev -> Returns prior day VAL
Code:
# Archive Name: Volume Profile 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 = {AUTOMATIC, default TICKSIZE, CUSTOM};
input customRowHeight = 1.0;
input timePerProfile = {CHART, MINUTE, MIN2, MIN3, MIN4, MIN5, MIN10, MIN15, MIN20, MIN30, HOUR, default DAY, WEEK, MONTH, "OPT EXP", BAR};
input multiplier = 1;
input onExpansion = no;
input profiles = 1000;
input showPointOfControl = yes;
input showValueArea = yes;
input valueAreaPercent = 68;
input opacity = 20; # 5.05.2018 JQ original was 50
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 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 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 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;
def POC = if plotsDomain then pc else Double.NaN;
def ProfileHigh = if plotsDomain then hProfile else Double.NaN;
def ProfileLow = if plotsDomain then lProfile else Double.NaN;
def VAHigh = if plotsDomain then hVA else Double.NaN; #Returns todays VA High
def VALow = if plotsDomain then lVA else Double.NaN; #Returns todays VA Low
#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();
def vahprev = GetValue(vahprior, priorperiod); #Returns yesterdays VA High
def pocprev = GetValue(pocprior, priorperiod);
def valprev = GetValue(valprior, priorperiod); #Returns yesterdays VA Low