# AL_Profiler
# Current Version: V1.0
# Goes with Anticipated Level Indicator
# Created by: TraderZen
# Last Update: 8/21/2022
# -- Show Profile ----
#------Start Function List---------------
input pricePerRowHeightMode = {AUTOMATIC, default TICKSIZE, CUSTOM};
input customRowHeight = 1.0;
input aggregationPeriod = {default "1 min", "2 min", "3 min", "4 min", "5 min", "10 min", "15 min", "20 min", "30 min", "1 hour", "2 hours", "4 hours", "Day", "2 Days", "3 Days", "4 Days", "Week", "Month"};
input timePerProfile = {CHART, MINUTE, HOUR, DAY, WEEK, MONTH, "OPT EXP", default BAR, YEAR};
input multiplier = 6;
input onExpansion = no;
input profiles = 500;
input showMonkeyBar = yes;
input showThePlayground = yes;
input thePlaygroundPercent = 70;
input opacity = 25;
input emphasizeFirstDigit = no;
input markOpenPrice = no;
input markClosePrice = no;
input volumeShowStyle = MonkeyVolumeShowStyle.NONE;
input showVolumeVA = yes;
input showVolumePoc = yes;
input theVolumePercent = 70;
input showInitialBalance = no;
input initialBalanceRange = 1;
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);
def periodMin = Floor(seconds / 60 + day_number * 24 * 60);
def periodHour = Floor(seconds / 3600 + day_number * 24);
def periodDay = CountTradingDays(Min(First(yyyymmdd), yyyymmdd), yyyymmdd) - 1;
def periodWeek = Floor(day_number / 7);
def periodMonth = month - First(month);
switch (timePerProfile) {
case CHART:
period = 0;
case MINUTE:
period = periodMin;
case HOUR:
period = periodHour;
case DAY:
period = periodDay;
case WEEK:
period = periodWeek;
case MONTH:
period = periodMonth;
case "OPT EXP":
period = exp_opt - First(exp_opt);
case BAR:
period = BarNumber() - 1;
case YEAR:
period = GetYear() - First(GetYear());
}
input RthBegin = 0930;
input RthEnd = 1600;
#input Minutes = 6;
#input showBubbles = no;
def OpenRange = SecondsFromTime(0930) >= 0 and
SecondsFromTime(1000) >= 0;
def bar = BarNumber();
def RTHBar1 = if SecondsFromTime(RthBegin) == 0 and
SecondsTillTime(RthBegin) == 0
then bar
else RTHBar1[1];
def RTHBarEnd = if SecondsFromTime(RthEnd) == 0 and
SecondsTillTime(RthEnd) == 0
then 1
else Double.NaN;
def RTH = SecondsFromTime(RthBegin) > 0 and
SecondsTillTime(RthEnd) > 0;
def start_t = if RTH and !RTH[1]
then GetTime()
else start_t[1];
def t = if start_t == GetTime()
then 1
else GetTime() % (Multiplier * 60 * 1000) == 0;
def cond = t;
def height;
switch (pricePerRowHeightMode) {
case AUTOMATIC:
height = PricePerRow.AUTOMATIC;
case TICKSIZE:
height = PricePerRow.TICKSIZE;
case CUSTOM:
height = customRowHeight;
}
def timeInterval;
def aggMultiplier;
switch (aggregationPeriod) {
case "1 min":
timeInterval = periodMin;
aggMultiplier = 1;
case "2 min":
timeInterval = periodMin;
aggMultiplier = 2;
case "3 min":
timeInterval = periodMin;
aggMultiplier = 3;
case "4 min":
timeInterval = periodMin;
aggMultiplier = 4;
case "5 min":
timeInterval = periodMin;
aggMultiplier = 5;
case "10 min":
timeInterval = periodMin;
aggMultiplier = 10;
case "15 min":
timeInterval = periodMin;
aggMultiplier = 15;
case "20 min":
timeInterval = periodMin;
aggMultiplier = 20;
case "30 min":
timeInterval = periodMin;
aggMultiplier = 30;
case "1 hour":
timeInterval = periodHour;
aggMultiplier = 1;
case "2 hours":
timeInterval = periodHour;
aggMultiplier = 2;
case "4 hours":
timeInterval = periodHour;
aggMultiplier = 4;
case "Day":
timeInterval = periodDay;
aggMultiplier = 1;
case "2 Days":
timeInterval = periodDay;
aggMultiplier = 2;
case "3 Days":
timeInterval = periodDay;
aggMultiplier = 3;
case "4 Days":
timeInterval = periodDay;
aggMultiplier = 4;
case "Week":
timeInterval = periodWeek;
aggMultiplier = 1;
case "Month":
timeInterval = periodMonth;
aggMultiplier = 1;
}
def agg_count = CompoundValue(1, if timeInterval != timeInterval[1]
then (GetValue(agg_count, 1) + timeInterval -
timeInterval[1]) % aggMultiplier
else GetValue(agg_count, 1), 0);
def agg_cond = CompoundValue(1, agg_count < agg_count[1] + timeInterval -
timeInterval[1], yes);
def digit = CompoundValue(1, if cond
then 1
else agg_cond + GetValue(digit, 1), 1);
profile monkey = MonkeyBars(digit,
"startNewProfile" = cond,
"onExpansion" = onExpansion,
"numberOfProfiles" = profiles,
"pricePerRow" = height,
"the playground percent" = thePlaygroundPercent,
"emphasize first digit" = emphasizeFirstDigit,
"volumeProfileShowStyle" = volumeShowStyle,
"volumePercentVA" = theVolumePercent,
"show initial balance" = showInitialBalance,
"initial balance range" = initialBalanceRange);
def con = CompoundValue(1, onExpansion, no);
def mbar = CompoundValue(1, if IsNaN(monkey.GetPointOfControl()) and con then GetValue(mbar, 1) else monkey.GetPointOfControl(), monkey.GetPointOfControl());
def hPG = CompoundValue(1, if IsNaN(monkey.GetHighestValueArea()) and con then GetValue(hPG, 1) else monkey.GetHighestValueArea(), monkey.GetHighestValueArea());
def lPG = CompoundValue(1, if IsNaN(monkey.GetLowestValueArea()) and con then GetValue(lPG, 1) else monkey.GetLowestValueArea(), monkey.GetLowestValueArea());
def hProfile = CompoundValue(1, if IsNaN(monkey.GetHighest()) and con then GetValue(hProfile, 1) else monkey.GetHighest(), monkey.GetHighest());
def lProfile = CompoundValue(1, if IsNaN(monkey.GetLowest()) and con then GetValue(lProfile, 1) else monkey.GetLowest(), monkey.GetLowest());
def plotsDomain = IsNaN(close) == onExpansion;
def VWAP_Data = vwap(period = getAggregationPeriod());
profile vwap_Profile = DataProfile(data = vwap_data,
"startNewProfile" = t,
"onExpansion" = onExpansion,
"numberOfProfiles" = profiles
);
plot vwap_poc = VWAP_Profile.getPointofControl();
vwap_poc.setpaintingStrategy(paintingStrategy.LINE_Vs_Triangles);
vwap_poc.assignValueColor(color.white);
plot vWap_p = vwap_data;
vwap_p.setpaintingStrategy(paintingStrategy.LINE_Vs_points);
vwap_p.setlineWeight(2);
VWAP_p.assignValueColor(if vwap_p >= vwap_p[1] then color.cyan else color.magenta);
vWAP_P.hide();
def VWAPbar = CompoundValue(1, if IsNaN(vwap_profile.GetPointOfControl()) and con then GetValue(VWAPBAR, 1) else vwap_profile.GetPointOfControl(), vwap_profile.GetPointOfControl());
profile tpo = TimeProfile("startNewProfile" = t,
"onExpansion" = 0,
"numberOfProfiles" = profiles,
"pricePerRow" = tickSize(),
"value area percent" = 70);
def showPointOfControl = yes;
def showValueArea = no;
plot ProfileHigh = if plotsDomain then hProfile else Double.NaN;
plot ProfileLow = if plotsDomain then lProfile else Double.NaN;
plot PGHigh = if plotsDomain then hPG else Double.NaN;
plot PGLow = if plotsDomain then lPG else Double.NaN;
DefineGlobalColor("Monkey Bar", GetColor(4));
DefineGlobalColor("The Playground", GetColor(3));
DefineGlobalColor("Open Price", GetColor(1));
DefineGlobalColor("Close Price", GetColor(1));
DefineGlobalColor("Volume", GetColor(8));
DefineGlobalColor("Volume Value Area", GetColor(2));
DefineGlobalColor("Volume Point of Control", GetColor(3));
DefineGlobalColor("Initial Balance", GetColor(7));
DefineGlobalColor("Profiles", GetColor(1));
tpo.Show(GlobalColor("Profiles"), if showPointOfControl
then GlobalColor("Volume Point Of Control")
else Color.CURRENT,
if showValueArea
then GlobalColor("Volume Value Area")
else Color.CURRENT, opacity);
plot MB = if plotsDomain then mbar else Double.NaN;
MB.SetDefaultColor(GlobalColor("Monkey Bar"));
MB.SetPaintingStrategy(PaintingStrategy.Line_vs_Points);
PGHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PGLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PGHigh.SetDefaultColor(GlobalColor("The Playground"));
PGLow.SetDefaultColor(GlobalColor("The Playground"));
ProfileHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ProfileLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ProfileHigh.SetDefaultColor(GetColor(3));
ProfileLow.SetDefaultColor(GetColor(3));
ProfileHigh.Hide();
ProfileLow.Hide();
PGHigh.hide();
PGLow.hide();
#-----end function list ---------------
#--- end 8/21/2022