Trend Change
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ajayvarma00047

//@version=5
indicator("Trend Change", overlay=true)
body = close[0] - open[0]
bodyPrev = close[1] - open[1]
bodyAbs = body < 0 ? body *-1 : body
bodyPrevAbs = bodyPrev < 0 ? bodyPrev *-1 : bodyPrev
avgVolumeLast5 = ta.sma(volume, 5)
longSignal =  (volume[0] > avgVolumeLast5 * 2) and ta.falling(open,3)
//or (body > 0 and body < 10 and volume[0] > volume[1] * 3)
shortSignal =  (volume[0] > avgVolumeLast5 * 2) and ta.rising(close,3)
plotshape(longSignal, "Long", shape.triangleup, location.abovebar, color=color.green, size=size.tiny)
plotshape(shortSignal, "Short", shape.triangledown, location.belowbar, color=color.red, size=size.tiny)

LineLengthMult = close  / 20000
LineLength = 50 * LineLengthMult

drawVerticalLine(offset, lineColor) =>
    line.new(bar_index[offset], low-LineLength, bar_index[offset], high+LineLength, color=color.new(lineColor, 50), width=3)

if shortSignal
    drawVerticalLine(0, color.red)
else if longSignal
    drawVerticalLine(0, color.green)

//plot(longSignal, color=color.green)
//plot(shortSignal, color=color.red)

//plot(avgVolumeLast5)
//hlcVwap = ta.vwap(hlc3)

//plot(hlcVwap,"vwap")

//plotarrow(body, colorup = color.teal, colordown = color.orange, minheight=7, maxheight=7)
