feat: add new indicators (Decay, Edecay, MinusDi, MinusDm, PlusDi, PlusDm, Maxindex, Minindex, Sarext) and update pine scripts, core libs, validation tests, and python bindings
2026-03-09 13:45:46 -07:00
|
|
|
// Licensed under the Apache License, Version 2.0
|
2026-01-18 19:02:03 -08:00
|
|
|
// © mihakralj
|
|
|
|
|
//@version=6
|
|
|
|
|
indicator("Ease of Movement (EOM)", "EOM", overlay=false)
|
|
|
|
|
|
|
|
|
|
//@function Calculate Ease of Movement Volume
|
|
|
|
|
//@param i_length integer Length for box ratio calculation
|
|
|
|
|
//@param i_smoothing integer Smoothing length for EOM
|
|
|
|
|
//@returns float Ease of Movement value
|
|
|
|
|
//@optimized for performance and dirty data
|
|
|
|
|
eom(i_smoothing, i_vol_scale, i_high=high, i_low=low, i_volume=volume) =>
|
|
|
|
|
var float oldMidPoint = na
|
|
|
|
|
midPoint = (i_high + i_low) * 0.5
|
|
|
|
|
midPointChange = midPoint - nz(oldMidPoint, midPoint)
|
|
|
|
|
oldMidPoint := midPoint
|
|
|
|
|
priceRange = i_high - i_low
|
|
|
|
|
boxRatio = priceRange > 0 and i_volume > 0 ? (i_volume / i_vol_scale) / priceRange : na
|
|
|
|
|
rawEom = not na(boxRatio) and boxRatio != 0 ? midPointChange / boxRatio : 0.0
|
|
|
|
|
var array<float> buffer = array.new_float(i_smoothing, 0.0)
|
|
|
|
|
var int head = 0
|
|
|
|
|
var float sum = 0.0
|
|
|
|
|
float oldest = array.get(buffer, head)
|
|
|
|
|
if bar_index >= i_smoothing
|
|
|
|
|
sum -= oldest
|
|
|
|
|
currentValue = nz(rawEom)
|
|
|
|
|
sum += currentValue
|
|
|
|
|
array.set(buffer, head, currentValue)
|
|
|
|
|
head := (head + 1) % i_smoothing
|
|
|
|
|
average = bar_index < i_smoothing ? sum / (bar_index + 1) : sum / i_smoothing
|
|
|
|
|
average
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ---------- Main loop ----------
|
|
|
|
|
|
|
|
|
|
// Inputs
|
|
|
|
|
i_length = input.int(14, "Period", minval=1)
|
|
|
|
|
i_smoothing = input.int(14, "Smoothing", minval=1)
|
|
|
|
|
|
|
|
|
|
// Calculation
|
|
|
|
|
eomValue = eom(i_length, i_smoothing)
|
|
|
|
|
|
|
|
|
|
// Plot
|
|
|
|
|
plot(eomValue, "EOM", color=color.yellow, linewidth=2)
|