OPEN-SOURCE SCRIPT
Updated

MAHAR K Stochastic Indicator

168
What It Does

%K line calculates fast stochastic of _src over length, then re-smoothed twice: sk (smoothK), %D (smoothD), and slower %F (smoothF).
Plots the three lines, draws 80/50/20 bands, and highlights extreme values by drawing red circles when sk hits 100 and green when it hits 0.
Notable Details

sma_signal chooses the smoothing kernel (SMA, EMA, WMA, DEMA). ma() delegates to the selected function and contains a VWMA branch even though VWMA is not listed in the input options.
A custom dema() helper implements the classic double EMA.
stOBOS is always true, so the ternary wrappers around the circle plots can be simplified.
Risk / Edge Cases

If highestHigh == lowestLow (flat price over the window) the %K calculation divides by zero, yielding na. Consider guarding against that or defaulting to previous values.
To actually expose VWMA, add it to the input options; otherwise remove the dead code branch.
Next Steps

Decide whether to safeguard the denominator before plotting.
Align the smoothing options with the available choices and prune the redundant conditionals if desired.
Release Notes
add custom alerts

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.