# Average Price Movements
# Assembled by BenTen at useThinkScript.com
# Converted from https://www.tradingview.com/script/eHhGyI6R-CD-Average-Daily-Range-Zones-highs-and-lows-of-the-day/
input aggregationPeriod = AggregationPeriod.DAY;
def open = open(period = aggregationPeriod);
def high = high(period = aggregationPeriod);
def low = low(period = aggregationPeriod);
def dayrange = (high - low);
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 = (open + (adr_10 / 2));
def ll1 = (open - (adr_10 / 2));
def hl2 = (open + (adr_5 / 2));
def ll2 = (open - (adr_5 / 2));
def h1 = hl1;
def l1 = ll1;
def h2 = hl2;
def l2 = ll2;
AddCloud(h1, h2, Color.RED, Color.RED);
AddCloud(l1, l2, Color.GREEN, Color.GREEN);
#h1.SetDefaultColor(Color.dark_red);
#h2.SetDefaultColor(Color.DARK_RED);
#l1.SetDefaultColor(Color.dark_green);
#l2.SetDefaultColor(Color.dark_green);
#Edited By Playstation 23.05.2020
#You can set whether to show the bubbles. Change or add the h1,h2,l1,l2 values to your preference.
input showBubble = yes;
def SR = showBubble and !IsNaN(close) and IsNaN(close [-1] ) && HighestAll(BarNumber());
#This will show the price at the support and resistance levels.
#AddChartBubble(SR,h2,Concat("R: ",Round(h2)),Color.RED);
#AddChartBubble(SR,l2,Concat("S: ",Round(l2)),Color.GREEN);
#Swap hashtags if you want just the Resistance/Support words.
#AddChartBubble(SR, h2, "DAILY RESISTANCE", Color.RED);
#AddChartBubble(SR, l2, "DAILY SUPPORT", Color.GREEN);
#Edited By Playstation 26.05.2020
#Added Labels to indicate request of adding labels to show price when breakabove resistance or below support.
AddLabel(yes, if close > h1 == yes then "Prior Daily Resistance May Become Support" else "", color.YELLOW);
AddLabel(yes, if close < l1 == yes then "Prior Daily Support May Become Resistance" else "", color.YELLOW);