Point Of Control
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © vebhainvesting 

//https://invest.webspacio.com, location to track momentum stocks 

//@version=5
indicator('Point Of Control', overlay=true, max_bars_back=252)
length = input.int(title='Near volume length', defval=21, group='POC')
multi = input.int(title='Multiplier', defval=2, group='POC')
momentum_candle = input.float(title='ATR', defval=1.5, step=0.05, group='POC')
vLength = input.int(title='Volume Weighted', defval=63, group='POC')

//Volume Weighted Average
// if timeframe.isweekly vLength := 13
// else if timeframe.ismonthly vLength := 6
vWeight = ta.vwma(close, timeframe.isdaily ? vLength : 26)
vwColor = vWeight > close ? color.red : color.green
plot(vWeight, color=vwColor, linewidth=2, title='Volume Weighted', display=display.none)


//NEAR VOLUME
avg = ta.sma(volume, length)
std = ta.stdev(volume, length)

condition = volume - avg > multi * std
todaysAction = close > hlc3
change = ta.change(close, 1) > 0 and todaysAction ? 1 : -1

support_line = 0.0
resistance_line = 0.0
support_line := condition and change > 0 ? low : support_line[1]
resistance_line := condition and change < 0 ? high : resistance_line[1]
plotshape(support_line, title='Support', style=shape.cross, location=location.absolute, color=color.new(#8191dd, 0))
plotshape(resistance_line, title='Resistance', style=shape.diamond, location=location.absolute, color=color.new(#c18c81, 0))


//Marking Momentum Candle
hiLow = high - low
closeOpen = close - open
chg = math.abs(close / close[1] - 1)
atr = momentum_candle * ta.atr(length)
momentumCandle = math.abs(closeOpen) / hiLow
momentumBull = closeOpen > atr and closeOpen > 0 or hiLow > atr and momentumCandle > 0.55 and closeOpen > 0 and momentumCandle[1] < 0.50 ? 1 : -1
momentumBear = closeOpen > atr and closeOpen < 0 or hiLow > atr and momentumCandle > 0.55 and closeOpen < 0 and momentumCandle[1] < 0.50 ? 1 : -1
barColour = momentumBull > 0 ? color.green : momentumBear > 0 ? color.red : color.rgb(175, 175, 175, 50)
barcolor(color=barColour)

//Fair Value/Price
[macdLine, signalLine, histLine] = ta.macd(close, 21, 63, 11)
dailyPeakValue = 0.07
macdPeak = timeframe.isdaily ? dailyPeakValue : timeframe.isweekly ? dailyPeakValue * 2.2 : timeframe.ismonthly ? dailyPeakValue * 4.2 : 0.035
fairValue = macdLine < close * macdPeak and macdLine > 0 ? 1 : -1


//Momentum Check
cciVal = ta.cci(hlc3, 34)
cciLong = cciVal > 100 ? 1 : -1
cciShort = cciVal < -50 ? 1 : -1
plotshape(series=cciShort > 0, title='Bearish', style=shape.triangledown, color=color.new(color.red, 0), location=location.abovebar, display=display.all)

plotshape(series=cciLong > 0 and macdLine > 0, title='Bullish', style=shape.triangleup, color=color.new(color.green, 0), location=location.belowbar, display=display.all)

//Above Fair Value then display Orange
plotshape(series=fairValue < 0 and macdLine > 0, title='Overvalued', style=shape.cross, color=color.new(color.orange, 0), location=location.abovebar, display=display.all)

//Momentum Check with KC
multiKC = input.int(1, title='Multiplier', group='KC')
exp = input.bool(true, title='Use Exponential MA', group='KC')
BandsStyle = input.string('Average True Range', title='Bands Style', options=['Average True Range', 'True Range', 'Range'], group='KC')
atrlength = input.int(11, 'ATR Length', group='KC')
esma(source, length) =>
    s = ta.sma(source, length)
    e = ta.ema(source, length)
    exp ? e : s
ma = esma(close, length)
rangema = BandsStyle == 'True Range' ? ta.tr(true) : BandsStyle == 'Average True Range' ? ta.atr(atrlength) : ta.rma(high - low, length)
upper = ma + rangema * multiKC
lower = ma - rangema * multiKC
uPlot = plot(upper, color=color.new(color.gray, 0), title='Upper', display=display.all)
lPlot = plot(lower, color=color.new(color.gray, 0), title='Lower', display=display.none)
atrSma = ta.sma(upper / lower, atrlength)
fillBool = atrSma > upper / lower ? 1 : atrSma > upper / lower ? -1 : 0  //good
plot(ma, color=close > ma ? color.green : color.red, title='Basis', style=plot.style_cross, display=display.none)



// Ichimoku Cloud

conversionPeriods = input.int(11, minval=1, title='Conversion Line Length', group='Ichimoku')
basePeriods = input.int(21, minval=1, title='Base Line Length', group='Ichimoku')
laggingSpan2Periods = input.int(63, minval=1, title='Leading Span B Length', group='Ichimoku')
//displacement = input(21, type=input.integer, minval=1, title="Lagging Span",group="Ichimoku")
donchian(len) =>
    math.avg(ta.lowest(len), ta.highest(len))
conversionLine = donchian(conversionPeriods)
baseLine = donchian(basePeriods)
leadLine1 = math.avg(conversionLine, baseLine)
leadLine2 = donchian(laggingSpan2Periods)
plot(baseLine, color=color.new(#B71C1C, 0), title='Base Line', linewidth=2, display=display.all)
//plot(close, offset = -basePeriods + 1, color=#43A047, title="Lagging Span",display=display.none)
p1 = plot(leadLine1, offset=basePeriods - 1, color=color.new(#A5D6A7, 0), title='Leading Span A', display=display.none)
p2 = plot(leadLine2, offset=basePeriods - 1, color=color.new(#EF9A9A, 0), title='Leading Span B', display=display.none)
fill(p1, p2, color=leadLine1 > leadLine2 ? color.rgb(75, 225, 75, 80) : color.rgb(225, 75, 75, 80))

// The END



