Cwparker23
Member
Code:
##########################################################
# Original script by TD AMERITRADE MODIfied BY Cwparker23#
##########################################################
#-----------------
#DISCLAIMER
#-----------------
#I am not a certified financial advisor. The content of this page/site and tools are for informational purposes only and does not constitute financial or legal advice. Under no circumstances will the author be responsible for errors or use of this tool and site. User assumes all risks.
input pricePerRowHeightMode = {default AUTOMATIC, TICKSIZE, CUSTOM};
input customRowHeight = 1.0;
input timePerProfile = {default CHART, MINUTE, HOUR, DAY, WEEK, MONTH, "OPT EXP", BAR};
input multiplier = 1;
input onExpansion = yes;
input profiles = 1000;
input showPointOfControl = yes;
input showValueArea = yes;
input valueAreaPercent = 70;
input opacity = 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 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);
def con = compoundValue(1, onExpansion, no);
def pc_VOLUME = if IsNaN(vol.getPointOfControl()) and con then pc_VOLUME[1] else vol.getPointOfControl();
def hVA_VOLUME = if IsNaN(vol.getHighestValueArea()) and con then hVA_VOLUME[1] else vol.getHighestValueArea();
def lVA_VOLUME = if IsNaN(vol.getLowestValueArea()) and con then lVA_VOLUME[1] else vol.getLowestValueArea();
def hProfile_VOLUME = if IsNaN(vol.getHighest()) and con then hProfile_VOLUME[1] else vol.getHighest();
def lProfile_VOLUME = if IsNaN(vol.getLowest()) and con then lProfile_VOLUME[1] else vol.getLowest();
def plotsDomain = IsNaN(close) == onExpansion;
plot POC_VOLUME = if plotsDomain then pc_VOLUME else Double.NaN;
plot ProfileHigh_VOLUME = if plotsDomain then hProfile_VOLUME else Double.NaN;
plot ProfileLow_VOLUME = if plotsDomain then lProfile_VOLUME else Double.NaN;
plot VAHigh_VOLUME = if plotsDomain then hVA_VOLUME else Double.NaN;
plot VALow_VOLUME = if plotsDomain then lVA_VOLUME else Double.NaN;
DefineGlobalColor("Profile_VOLUME", GetColor(1));
DefineGlobalColor("Point Of Control_VOLUME", GetColor(5));
DefineGlobalColor("Value Area_VOLUME", GetColor(8));
vol.show(globalColor("Profile_VOLUME"), if showPointOfControl then globalColor("Point Of Control_VOLUME") else color.current, if showValueArea then globalColor("Value Area_VOLUME") else color.current, opacity);
POC_VOLUME.SetDefaultColor(globalColor("Point Of Control_VOLUME"));
POC_VOLUME.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VAHigh_VOLUME.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VALow_VOLUME.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VAHigh_VOLUME.SetDefaultColor(globalColor("Value Area_VOLUME"));
VALow_VOLUME.SetDefaultColor(globalColor("Value Area_VOLUME"));
ProfileHigh_VOLUME.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ProfileLow_VOLUME.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ProfileHigh_VOLUME.SetDefaultColor(GetColor(3));
ProfileLow_VOLUME.SetDefaultColor(GetColor(3));
ProfileHigh_VOLUME.hide();
ProfileLow_VOLUME.hide();
################################## TPOProfile #############################
profile tpo = timeProfile("startNewProfile" = cond, "onExpansion" = onExpansion, "numberOfProfiles" = profiles, "pricePerRow" = height, "value area percent" = valueAreaPercent);
def pc_PRICE = if IsNaN(tpo.getPointOfControl()) and con then pc_PRICE[1] else tpo.getPointOfControl();
def hVA_PRICE = if IsNaN(tpo.getHighestValueArea()) and con then hVA_PRICE[1] else tpo.getHighestValueArea();
def lVA_PRICE = if IsNaN(tpo.getLowestValueArea()) and con then lVA_PRICE[1] else tpo.getLowestValueArea();
def hProfile_PRICE = if IsNaN(tpo.getHighest()) and con then hProfile_PRICE[1] else tpo.getHighest();
def lProfile_PRICE = if IsNaN(tpo.getLowest()) and con then lProfile_PRICE[1] else tpo.getLowest();
plot POC_PRICE = if plotsDomain then pc_PRICE else Double.NaN;
plot ProfileHigh_PRICE = if plotsDomain then hProfile_PRICE else Double.NaN;
plot ProfileLow_PRICE = if plotsDomain then lProfile_PRICE else Double.NaN;
plot VAHigh_PRICE = if plotsDomain then hVA_PRICE else Double.NaN;
plot VALow_PRICE = if plotsDomain then lVA_PRICE else Double.NaN;
DefineGlobalColor("Profile_PRICE", GetColor(1));
DefineGlobalColor("Point Of Control_PRICE", GetColor(5));
DefineGlobalColor("Value Area_PRICE", GetColor(8));
tpo.show(globalColor("Profile_PRICE"), if showPointOfControl then globalColor("Point Of Control_PRICE") else color.current, if showValueArea then globalColor("Value Area_PRICE") else color.current, opacity);
POC_PRICE.SetDefaultColor(globalColor("Point Of Control_PRICE"));
POC_PRICE.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VAHigh_PRICE.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VALow_PRICE.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VAHigh_PRICE.SetDefaultColor(globalColor("Value Area_PRICE"));
VALow_PRICE.SetDefaultColor(globalColor("Value Area_PRICE"));
ProfileHigh_PRICE.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ProfileLow_PRICE.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ProfileHigh_PRICE.SetDefaultColor(GetColor(3));
ProfileLow_PRICE.SetDefaultColor(GetColor(3));
ProfileHigh_PRICE.hide();
ProfileLow_PRICE.hide();
PLOT VPPOCXX = (POC_VOLUME + POC_PRICE)/2;
PLOT VPVAHXX = (VAHigh_VOLUME + VAHigh_PRICE)/2;
PLOT VPVALXX = (VALow_VOLUME + VALow_PRICE)/2;
VPPOCXX.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VPVAHXX.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VPVALXX.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);