mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-24 13:38:05 +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("Mass Index (MASSI)", "MASSI", overlay=false)
|
||||
|
||||
//@function Calculates the Mass Index indicator
|
||||
//@param ema_length Period for EMA smoothing of high-low range
|
||||
//@param sum_length Period for summing the EMA ratio
|
||||
//@returns float Mass Index value
|
||||
//@optimized for performance and dirty data
|
||||
massi(simple int ema_length, simple int sum_length) =>
|
||||
if ema_length <= 0 or sum_length <= 0
|
||||
runtime.error("Periods must be greater than 0")
|
||||
float a = 2.0 / (ema_length + 1)
|
||||
float beta = 1.0 - a
|
||||
var bool warmup = true, var float e = 1.0
|
||||
var float ema1_raw = 0.0, var float ema2_raw = 0.0
|
||||
float span = nz(high - low)
|
||||
ema1_raw := a * (span - ema1_raw) + ema1_raw
|
||||
ema2_raw := a * (ema1_raw - ema2_raw) + ema2_raw
|
||||
if warmup
|
||||
e *= beta
|
||||
warmup := e > 1e-10
|
||||
float c = warmup ? 1.0 / (1.0 - e) : 1.0
|
||||
float ema1 = c * ema1_raw
|
||||
float ema2 = c * ema2_raw
|
||||
math.sum(ema2 != 0 ? ema1 / ema2 : 0, sum_length)
|
||||
|
||||
// ---------- Main loop ----------
|
||||
// Inputs
|
||||
i_ema_length = input.int(9, "EMA Length", minval=1, tooltip="Period for EMA smoothing of high-low range")
|
||||
i_sum_length = input.int(25, "Sum Length", minval=1, tooltip="Period for summing the EMA ratio")
|
||||
|
||||
// Calculation
|
||||
massi_value = massi(i_ema_length, i_sum_length)
|
||||
|
||||
// Plot
|
||||
plot(massi_value, "MASSI", color=color.yellow, linewidth=2)
|
||||
Reference in New Issue
Block a user