HI @BenTen , Can I request for a small update? This script gives the high and low range of average ADR.
Based on current price value, I would like to show the following in the label. The current price and how much percentage of average ADR it has moved so far. If the price is above open, then the label can be green and vice versa. Thank you in advance
Label: the current price and how much percentage of average ADR it has moved so far.
Ruby:
# Average Price Movements
# Assembled by BenTen at useThinkScript.com
# Converted from TradingView version
input ShowTodayOnly = yes;
def Today = if GetDay() == GetLastDay() then 1 else 0;
input aggregationPeriod = AggregationPeriod.DAY;
def o = open(period = aggregationPeriod);
def h = high(period = aggregationPeriod);
def l = low(period = aggregationPeriod);
def dayrange = (h - l);
def r1 = dayrange[1];
def r2 = dayrange[2];
def r3 = dayrange[3];
def r4 = dayrange[4];
def r5 = dayrange[5];
def r6 = dayrange[6];
def r7 = dayrange[7];
def r8 = dayrange[8];
def r9 = dayrange[9];
def r10 = dayrange[10];
def adr_10 = (r1 + r2 + r3 + r4 + r5 + r6 + r7 + r8 + r9 + r10) / 10;
def adr_5 = (r1 + r2 + r3 + r4 + r5) / 5;
def hl1 = (o + (adr_10 / 2));
def ll1 = (o - (adr_10 / 2));
def hl2 = (o + (adr_5 / 2));
def ll2 = (o - (adr_5 / 2));
plot upper2 = if ShowTodayOnly and !Today then Double.NaN else hl1;
plot lower1 = if ShowTodayOnly and !Today then Double.NaN else ll2;
plot upper1 = if ShowTodayOnly and !Today then Double.NaN else hl2;
plot lower2 = if ShowTodayOnly and !Today then Double.NaN else ll1;
addCloud(if ShowTodayOnly == yes then upper2 else double.nan, upper1, Color.RED, Color.RED);
addCloud(if ShowTodayOnly == yes then lower1 else double.nan, lower2, Color.GREEN, Color.GREEN);
upper1.SetDefaultColor(Color.DARK_RED);
upper2.SetDefaultColor(Color.DARK_RED);
lower1.SetDefaultColor(Color.DARK_GREEN);
lower2.SetDefaultColor(Color.DARK_GREEN);
# ----------------------------------------------------------
# Label showing current price + % of ADR moved
# ----------------------------------------------------------
def price = close;
def moved = AbsValue(price - o);
def adrPercent = if adr_10 != 0 then (moved / adr_10) else 0;
AddLabel(
yes,
"Price: " + AsDollars(price) +
" | ADR: " + AsPercent(adrPercent),
if price > o then Color.GREEN else Color.RED
);