ASO REVAMPED

The Average Sentiment Oscillator used to be one of my favorite indicators back when I was getting started. Today, we’re going to be rebuilding the indicator from scratch and making it more mathematically sound.

//@version=5
indicator("Average Sentiment Oscillator", "ASO")

Lens                     = input.int(200, "Lens")

BOP                      = (close - open) / (high - low)
BOP_hma                  = ta.hma(BOP, Lens)

SentimentLow             = ta.lowest(BOP_hma, Lens)
SentimentHigh            = ta.highest(BOP_hma, Lens)

SentimentRange           = SentimentHigh-SentimentLow

K1                       = SentimentRange == 0 ? 1 : SentimentRange

BullishSentiment         = (((BOP_hma - SentimentLow) + (SentimentHigh - BOP_hma[1]))/2)*100/K1
BearishSentiment         = (((SentimentHigh - BOP_hma) + (BOP_hma[1] - SentimentLow))/2)*100/K1

ASOBulls=ta.sma(BullishSentiment, Lens)
ASOBears=ta.sma(BearishSentiment, Lens)
plot(ASOBulls, color=color.blue, linewidth=2)
plot(ASOBears, color=color.red, linewidth=2)