mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-07-28 01:37:43 +00:00
35a6702b06
Deep review of all indicator categories verified .md headers against .cs WarmupPeriod, parameters, inputs, and outputs. Fixes include warmup corrections, parameter documentation, output type accuracy, and Pine Script alignment.
45 lines
1.3 KiB
Plaintext
45 lines
1.3 KiB
Plaintext
// Licensed under the Apache License, Version 2.0
|
|
// © 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)
|