Price Action Signals V2
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © sonnyparlin

// Chart update (8/7/2022)

// Note purple arrows denote weakness in price action and possible reversals
// red and green candles are considered to be stronger moves.

// New chart
// New chart
// removed indicator, new chart

//@version=5
indicator("Price Action Signals V2", overlay=true)

largeSpread = input.float(0.50, title="Large Spread candle if body > x", step=0.01)
irregularBody = input.float(.25, title="Mark irregular if candle spread is less than x on high volume", step=0.01)
irregularArrowColor = input(color.purple, title="Irregular Arrow Color")
volumeMA = input(12, title="Volume moving average length")
showIrregularArrows = input.bool(false)
lowerTail = 0.0
upperTail = 0.0
if (close > open)
    upperTail := (high - close)
    lowerTail := (open - low)
else
    upperTail := (high - open)
    lowerTail := (close - low)

candleBody = math.abs(close-open)
goodVolume = volume >= ta.sma(volume, volumeMA) * 2

cond2 = ((lowerTail > upperTail) and goodVolume and lowerTail > candleBody / 2 and candleBody > irregularBody)
cond3 = ((upperTail > lowerTail) and goodVolume and upperTail > candleBody / 2 and candleBody > irregularBody)
largeBodyGoodVolumeUp = close > open and candleBody > largeSpread and goodVolume
largeBodyGoodVolumeDown = close < open and candleBody > largeSpread and goodVolume

redPlot = 0.0
greenPlot = 0.0
if largeBodyGoodVolumeUp or cond2
    greenPlot := close

if largeBodyGoodVolumeDown or cond3 
    redPlot := close

irregularUp = (candleBody < irregularBody and lowerTail > upperTail and close > open and goodVolume)
irregularDown = (candleBody < irregularBody and upperTail > lowerTail and open > close and goodVolume)

if irregularUp and showIrregularArrows
    greenPlot := close

    
if irregularDown and showIrregularArrows
    redPlot := close


if redPlot and greenPlot
    if close > open
        redPlot := 0
    else
        greenPlot := 0
    
plotshape(redPlot > 0.0, style=shape.triangledown,
                 location=location.abovebar, color=irregularDown ? color.purple : color.red)

plotshape(greenPlot > 0.0, style=shape.triangleup,
                 location=location.belowbar, color=irregularUp ? color.purple : color.green) 