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("Elder's Force Index (EFI)", "EFI", overlay=false)
|
|
|
|
|
|
|
|
|
|
//@function Calculates Elder's Force Index (EFI), measuring buying and selling pressure through price change and volume
|
|
|
|
|
//@param len Lookback period for EMA smoothing (default: 13)
|
|
|
|
|
//@param src Source price for calculation (default: built-in close)
|
|
|
|
|
//@param src_vol The volume (default: built-in volume)
|
|
|
|
|
//@returns float The smoothed Force Index value
|
|
|
|
|
efi(len = 13, src = close, src_vol = volume) =>
|
|
|
|
|
var float prev_src = src
|
|
|
|
|
float raw_force = (nz(src) - nz(prev_src)) * nz(src_vol)
|
|
|
|
|
prev_src := src
|
|
|
|
|
float a = 2.0 / (len + 1.0)
|
|
|
|
|
float beta = 1.0 - a
|
|
|
|
|
var float ema = na
|
|
|
|
|
var float result = na
|
|
|
|
|
var float e = 1.0
|
|
|
|
|
var bool warmup = true
|
|
|
|
|
if na(ema)
|
|
|
|
|
ema := 0
|
|
|
|
|
result := raw_force
|
|
|
|
|
else
|
|
|
|
|
ema := a * (raw_force - ema) + ema
|
|
|
|
|
if warmup
|
|
|
|
|
e *= beta
|
|
|
|
|
float c = 1.0 / (1.0 - e)
|
|
|
|
|
result := c * ema
|
|
|
|
|
if e <= 1e-10
|
|
|
|
|
warmup := false
|
|
|
|
|
else
|
|
|
|
|
result := ema
|
|
|
|
|
result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ---------- Inputs ----------
|
|
|
|
|
i_length = input.int(13, "Length", minval=1)
|
|
|
|
|
|
|
|
|
|
// ---------- Calculations ----------
|
|
|
|
|
efi_val = efi(i_length)
|
|
|
|
|
|
|
|
|
|
// ---------- Plotting ----------
|
|
|
|
|
plot(efi_val, "EFI", color=color.yellow, linewidth=2)
|