mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-25 05:48:06 +00:00
SIMD Refactor: Merge simd-dev into dev (#55)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: aider (openrouter/anthropic/claude-sonnet-4) <aider@aider.chat> Co-authored-by: Warp <agent@warp.dev>
This commit is contained in:
co-authored by
Claude Opus 4.5
aider
Warp
parent
5bcdf8d614
commit
86fe32a682
@@ -0,0 +1,38 @@
|
||||
// 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
|
||||
//@doc https://github.com/mihakralj/pinescript/blob/main/indicators/oscillators/dpo.md
|
||||
//@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)
|
||||
Reference in New Issue
Block a user