mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-17 10:08:05 +00:00
- Updated BBWN, BBWP, CCV, CV, CVI, EWMA, GKV, HLV, HV, Jvolty, JVOLTYN, MASSI, NATR, RSV, RV, RVI, TR, UI, VOV, VR, YZV indicators with documentation links. - Added documentation links for Aberration, Acceleration Bands, Andrews' Pitchfork, Adaptive Price Zone, ATR Bands, Bollinger Bands, Center of Gravity, Donchian Channels, Decay Min-Max Channel, Detrended Synthetic Price, EACP, EBSW, HOMOD, Jurik Volatility Bands, Keltner Channel, MA Envelope, Min-Max Channel, Price Channel, Regression Channels, Standard Deviation Channel, Stoller Average Range Channel, Super Trend Bands, Ultimate Bands, Ultimate Channel, VWAP Bands, and VWAP with Standard Deviation Bands.
45 lines
1.3 KiB
Plaintext
45 lines
1.3 KiB
Plaintext
// The MIT License (MIT)
|
|
// © mihakralj
|
|
//@version=6
|
|
indicator("Balance of Power (BOP)", "BOP", overlay=false)
|
|
|
|
//@function Calculates Balance of Power with optional smoothing
|
|
//@param length Smoothing period (0 for no smoothing)
|
|
//@returns BOP value measuring buying/selling pressure
|
|
bop(simple int length) =>
|
|
if length < 0
|
|
runtime.error("Length must be non-negative")
|
|
float rawBop = high == low ? 0.0 : (close - open) / (high - low)
|
|
if length == 0
|
|
rawBop
|
|
else
|
|
float alpha = 2.0 / (length + 1.0)
|
|
var float smoothBop = na
|
|
var float e = 1.0
|
|
var bool warmupComplete = false
|
|
var float result = na
|
|
if na(smoothBop)
|
|
smoothBop := rawBop, result := rawBop
|
|
else
|
|
smoothBop := alpha * (rawBop - smoothBop) + smoothBop
|
|
if not warmupComplete
|
|
e *= (1.0 - alpha)
|
|
float c = e > 1e-10 ? 1.0 / (1.0 - e) : 1.0
|
|
result := smoothBop * c
|
|
if e <= 1e-10
|
|
warmupComplete := true
|
|
else
|
|
result := smoothBop
|
|
result
|
|
|
|
// ---------- Main loop ----------
|
|
|
|
// Inputs
|
|
i_smooth = input.int(14, "Smoothing Length", minval=0, tooltip="0 for no smoothing")
|
|
|
|
// Calculation
|
|
bop_value = bop(i_smooth)
|
|
|
|
// Plot
|
|
plot(bop_value, "BOP", color=color.yellow, linewidth=2)
|