Files
QuanTAlib/lib/dynamics/imi/imi.pine
T
Miha Kralj 24e86d762a Add documentation links for various volatility indicators and channels
- Updated BBWN, BBWP, CCV, CV, CVI, EWMA, GKV, HLV, HV, Jvolty, JVOLTYN, MASSI, NATR, RSV, RV, RVI, TR, UI, VOV, VR, YZV indicators with documentation links.
- Added documentation links for Aberration, Acceleration Bands, Andrews' Pitchfork, Adaptive Price Zone, ATR Bands, Bollinger Bands, Center of Gravity, Donchian Channels, Decay Min-Max Channel, Detrended Synthetic Price, EACP, EBSW, HOMOD, Jurik Volatility Bands, Keltner Channel, MA Envelope, Min-Max Channel, Price Channel, Regression Channels, Standard Deviation Channel, Stoller Average Range Channel, Super Trend Bands, Ultimate Bands, Ultimate Channel, VWAP Bands, and VWAP with Standard Deviation Bands.
2026-02-18 11:55:48 -08:00

45 lines
1.4 KiB
Plaintext

// The MIT License (MIT)
// © mihakralj
//@version=6
indicator("Intraday Momentum Index (IMI)", "IMI", overlay=false)
//@function Calculates IMI using intraday price ranges (open vs close)
//@param period Number of bars used in the calculation
//@returns IMI value (0-100)
//@optimized Uses circular buffer for O(1) per-bar complexity
imi(simple int period) =>
if period <= 0
runtime.error("Period must be greater than 0")
float gain = 0.0
float loss = 0.0
if close > open
gain := close - open
else if close < open
loss := open - close
var array<float> gain_buffer = array.new_float(period, 0.0)
var array<float> loss_buffer = array.new_float(period, 0.0)
var int idx = 0
var float gain_sum = 0.0
var float loss_sum = 0.0
gain_sum -= array.get(gain_buffer, idx)
loss_sum -= array.get(loss_buffer, idx)
array.set(gain_buffer, idx, gain)
array.set(loss_buffer, idx, loss)
gain_sum += gain
loss_sum += loss
idx := (idx + 1) % period
float total = gain_sum + loss_sum
float imi_value = total != 0.0 ? 100.0 * gain_sum / total : 50.0
imi_value
// ---------- Main loop ----------
// Inputs
i_period = input.int(14, "Period", minval=1, tooltip="Number of bars used in the calculation")
// Calculate IMI
imi_value = imi(i_period)
// Plot
plot(imi_value, "IMI", color=color.yellow, linewidth=2)