mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-13 16:18: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.
38 lines
1.1 KiB
Plaintext
38 lines
1.1 KiB
Plaintext
// The MIT License (MIT)
|
|
// © mihakralj
|
|
//@version=6
|
|
indicator("Detrended Price Oscillator (DPO)", "DPO", overlay=false)
|
|
|
|
//@function Calculates Detrended Price Oscillator (DPO) by removing trend component from price
|
|
//@param source Series to calculate DPO from
|
|
//@param period Period for SMA calculation and displacement
|
|
//@returns DPO value (current price - displaced SMA)
|
|
dpo(series float source, simple int period) =>
|
|
if period <= 0
|
|
runtime.error("Period must be greater than 0")
|
|
int displacement = math.floor(period / 2) + 1
|
|
float sum = 0.0
|
|
for i = 0 to period - 1
|
|
sum += nz(source[i], source)
|
|
float sma = sum / period
|
|
float currentPrice = source
|
|
float displacedSMA = sma[displacement]
|
|
float result = na
|
|
if not na(displacedSMA)
|
|
result := currentPrice - displacedSMA
|
|
|
|
result
|
|
|
|
// ---------- Main loop ----------
|
|
|
|
// Inputs
|
|
i_source = input.source(close, "Source")
|
|
i_period = input.int(20, "Period", minval=1)
|
|
|
|
// Calculation
|
|
dpo_value = dpo(i_source, i_period)
|
|
|
|
// Plot
|
|
plot(dpo_value, "DPO", color=color.yellow, linewidth=2)
|
|
hline(0, "Zero Line", color.gray, hline.style_dotted)
|