PDs - MID ADVANCE DIRECTION
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © tejedawx

//@version=5

//
// Pine Script v4
// @author BigBitsIO
// Script Library: https://www.tradingview.com/u/BigBitsIO/#published-scripts
//

indicator('PDs - MID ADVANCE DIRECTION', overlay=true, timeframe="")
//len = input.int(2, minval=2, title='Length')
//SMlen = input.int(10, minval=2, title='HMA Smoothing')
//MULT = input.int(2, minval=1, title="Multiplier")

col_grow_above = input(#26A69A, "Above Grow", group="Histogram", inline="Above")
col_fall_above = input(#B2DFDB, "Fall", group="Histogram", inline="Above")
col_grow_below = input(#FFCDD2, "Below Grow", group="Histogram", inline="Below")
col_fall_below = input(#FF5252, "Fall", group="Histogram", inline="Below")

// I have consolidated some of this code from a prior example
o = open
c = close
h = high
l = low

//so = ta.hma(o, SMlen)
//sc = ta.hma(c, SMlen)
//sh = ta.hma(h, SMlen)
//sl = ta.hma(l, SMlen)

//Initial Price Average Data
//ohlcFour = ta.hma(ohlc4, len)
//ohlcFourSMT = ta.ema(ohlcFour, 4)

//Close Data
//Close = ta.hma(close, len)
//CloseSMT = ta.hma(Close, 3)

//MID OPEN-CLOSE
OC = (o+c)/2

//FIRST AVERAGES
UA_ONE= if o < c //VERDE
    (h+c)/2
else
    (h+o)/2
LA_ONE = if o > c // ROJA
    (l+c)/2
else
    (l+o)/2

MID = (UA_ONE+LA_ONE)/2
EMA1 = ta.ema(UA_ONE, 1)
EMA2 = ta.ema(LA_ONE, 1)

//SECOND AVERAGES
UA_TWO = (OC+UA_ONE)/2
LA_TWO = (OC+LA_ONE)/2


EMA10 = ta.ema(UA_TWO, 1)
EMA20 = ta.ema(LA_TWO, 1)
MID2 = (UA_TWO+LA_TWO)/2
MID3 = (MID2+MID2[1])/2
//RANGE 
//UPA = UPPER_AVE+((MID-LOWER_AVE)*MULT)
//LWA = LOWER_AVE-((UPPER_AVE-MID)*MULT)

DIFF = EMA1-EMA2 //ta.ema(((EMA1) - (EMA2)), 1)
DIFF2 = MID3-MID3[1]

LRANGE = if MID3 > MID3[1]
    MID3-(MID3 - ((l+l[1]+l[2])/3))
else
    MID3-(MID3-l)
    
URANGE = if MID3 < MID3[1]
    MID3+(((h+h[1]+h[2])/3)- MID3)
else
    MID3+(h-MID3)
    
//MIDAVE = (ta.ema(MID, SMlen) + ohlcFourSMT)/2
//DIFFMIDAVE= ta.ema(MIDAVE - (ta.ema(MID, SMlen)), 2)

//colorBody = sc > so[1] ? color.lime : color.red
//plotcandle(so, sh, sl, sc, color=colorBody, title='Hull Candles')

//plot(ohlcFourSMT, color=color.new(color.black, 0))
//plot(EMA1, color=color.blue)
//plot(EMA2, color=color.maroon)
//plot(EMA10, color=color.green)
//plot(EMA20, color=color.lime)
//plot(MID, color=color.yellow)
plot(MID3, color=color.black)

//plot(LRANGE, color=color.blue)
//plot(URANGE, color=color.purple)

//plot(UPA, color=color.blue)
//plot(LWA, color=color.maroon)

//plot(ta.ema(EMA0, 3), color=color.blue)
//plot(ta.ema(EMA01, 3), color=color.purple)

//plot(DIFF, title="Power+ Histogram", style=plot.style_columns, color=(DIFF>=0 ? (DIFF[1] < DIFF ? col_grow_above : col_fall_above) : (DIFF[1] < DIFF ? col_grow_below : col_fall_below)))
//plot(SDIFF, color=color.black)
//plot(ta.hma(DIFF, 10))

//plot(DIFF, color=color.green)
//plot(DIFF2, color=color.purple)
//plot(LAST, color=color.black)
//plot(DIFFMIDAVE, color=color.blue)
//plot(c, color=color.blue)

//plot(so, color=color.new(color.blue, 0))
//plot(sc, color=color.new(color.purple, 0))
//plot(sh, color=color.new(color.red, 0))
//plot(sl, color=color.new(color.lime, 0))

