# ADX_Smoothed_Line_Agg
#
#
declare lower;
input showonexpansion = no;
input showlabels = yes;
input showbubble = yes;
input showverticals = yes;
input vertical_plot_limiter = 2;
input agg = AggregationPeriod.FIFTEEN_MIN;
input length = 14;
input averageType = AverageType.WILDERS;
def hiDiff = high(period = agg) - high(period = agg)[1];
def loDiff = low(period = agg)[1] - low(period = agg);
def plusDM = if hiDiff > loDiff and hiDiff > 0 then hiDiff else 0;
def minusDM = if loDiff > hiDiff and loDiff > 0 then loDiff else 0;
def ATR = MovingAverage(averageType, TrueRange(high(period = agg), close(period = agg), low(period = agg)), length);
def "DI+" = 100 * MovingAverage(averageType, plusDM, length) / ATR;
def "DI-" = 100 * MovingAverage(averageType, minusDM, length) / ATR;
def DX = if ("DI+" + "DI-" > 0) then 100 * AbsValue("DI+" - "DI-") / ("DI+" + "DI-") else 0;
def ADX15 = MovingAverage(averageType, DX, length);
#Smoothed Higher Agg ADX
def minutes = agg / 60000;
def bar = BarNumber();
def o = if bar == 1 or bar[1] % ((Ceil(minutes) ) / (GetAggregationPeriod() / 60000)) == 0
then ADX15
else o[1];
def x = (if o != o[1] then x[1] + 1 else x[1]);
def cc = if x != x[1] then o else Double.NaN;
def ccextend = if IsNaN(close) then ccextend[1] else if x != x[1] then o else ccextend[1];
def last = HighestAll(if IsNaN(cc[-1]) and !IsNaN(cc) then BarNumber() else Double.NaN);
def count = if x != x[1] then count[1] + 1 else count[1];
def cond = HighestAll(count) - count + 1;
plot dd = if showonexpansion then if !IsNaN(close) then Double.NaN else ccextend else cc;
dd.EnableApproximation();
#Labels
AddLabel(showlabels, agg / 60000 + "m ADX: " + ADX15, dd.TakeValueColor());
#Bubbles
AddChartBubble(showbubble and
#cond[1] == 2 and cond == 1
cond == 1, cc, ADX15, Color.GRAY, no);
#Verticals
input begin = 0930;
def chartAgg = GetAggregationPeriod();
def barSeq = if SecondsTillTime(begin) == 0 and
SecondsFromTime(begin) == 0
then 0
else barSeq[1] + 1;
def barvertical = barSeq;
def hour = Floor(((9 * 60 + 30) + (GetTime() - RegularTradingStart(GetYYYYMMDD())) / 60000) / 60);
def min = (GetTime() - RegularTradingStart(GetYYYYMMDD())) / 60000 - ((hour - 9) * 60 + 30) + 60;
AddVerticalLine(showverticals and BarNumber() >= HighestAll(last) - vertical_plot_limiter and (barvertical) % (minutes / (GetAggregationPeriod() / 60000)) == 0, hour + ":" + min , color = Color.WHITE, stroke = Curve.FIRM);