Perfected FlowScript
Ease Of Movement (EoM)
Ease of Movement V2 is indexed as 310_ease_of_movement.flowscript. The exact FlowScript is viewable here; chart observe and trading automation use the current mmflow chart/recipe signal proxy until FlowScript v2 transpilation is available.
This exact FlowScript uses the v2 source dialect. It is viewable and connected to the chart/automation proxy, but direct editor execution needs the FlowScript v2 transpiler.
Dialect
flowscript-v2
Compatibility
flowscript-v2-needs-transpile
Position
offchart
Axis
true
Size
17.0 KB
Lines
561
Native Signal Candidates
6 source-level chart marker triggers extracted from guarded FlowScript v2 blocks.
Cross Up
line 465:9
Trigger
(showShapes) && (crossUp)
Value
signal
Deps
crossUp:var, showShapes:input
Cross Down
line 475:9
Trigger
(showShapes) && (crossDown)
Value
signal
Deps
crossDown:var, showShapes:input
Zero Cross Up
line 485:9
Trigger
(showShapes) && (zeroCrossUp)
Value
0
Deps
showShapes:input, zeroCrossUp:var
Zero Cross Down
line 495:9
Trigger
(showShapes) && (zeroCrossDown)
Value
0
Deps
showShapes:input, zeroCrossDown:var
OB Penetrate
line 505:9
Trigger
(showShapes) && (obPenetrate)
Value
dynOb
Deps
obPenetrate:var, showShapes:input
OS Penetrate
line 515:9
Trigger
(showShapes) && (osPenetrate)
Value
dynOs
Deps
osPenetrate:var, showShapes:input
310_ease_of_movement.flowscript
source path: kscripts/perfected/310_ease_of_movement.flowscript · sha256:bc2455133e8f716373d56a9dfaf7351d3baefd53a8b52d32f25fd18c0ee35292
//@version=2
// ============================================================================
// Ease of Movement V2 — Production-Quality Momentum + Liquidity Fusion
// Author: Crypto Catipal | Perfected by: kScript Perfection Engineer
// Tags: CORE, #eom, #momentum, #liquidity, #volume, #regime
//
// Production-quality Ease of Movement with z-score normalization, signal-line
// regime detection, color-coded histogram, and comprehensive shape / fill
// visualization. Measures how easily prices move by combining midpoint
// displacement with volume normalization (box ratio).
//
// FORMULA FOUNDATION:
// 1. Ease of Movement (EoM): EoM = MidpointMove / BoxRatio
// where MidpointMove = [(High + Low)/2 − (High[1] + Low[1])/2] / scale
// and BoxRatio = Volume / (High − Low).
// 2. Per Richard W. Arms Jr. (equivolume concept): price movement relative to
// volume produces cleaner momentum signals than raw volume or raw price change.
// 3. Z-Score Normalization: z = (EoM − μ_EoM) / σ_EoM over rolling window,
// standardizing momentum for cross-asset comparison and threshold calibration.
// 4. Signal Line Regime: EoM > Signal AND EoM > 0 → bullish momentum;
// EoM < Signal AND EoM < 0 → bearish momentum.
// 5. Dynamic thresholds per Poterba & Summers (1988): mean-reversion intensity
// varies with volatility; rolling EoM std dev adjusts overbought/oversold bands.
//
// RESEARCH BASIS:
// • Arms, R.W. (1971), "Profits in Volume" — Ease of Movement original concept.
// Price movement relative to volume (the "box") produces a pure momentum
// measure independent of absolute price level.
// • Poterba & Summers (1988), J. Finance 43(1), 27–41. Mean reversion in stock
// prices; negative autocorrelation at medium horizons supports dynamic
// overbought/oversold thresholds calibrated to rolling volatility.
// • Jegadeesh & Titman (1993), J. Finance 48(1), 65–91. Momentum anomaly
// validates the use of smoothed momentum indicators for trend detection.
// • Cont, Kukanov & Stoikov (2014), J. Financial Econometrics 12(1), 47–88.
// Price impact slope is inversely proportional to depth; EoM captures
// the "ease" of movement through liquidity conditions.
// • Chordia, Roll & Subrahmanyam (2002), J. Financial Economics 65(1), 111–130.
// Order imbalance and liquidity drive returns; volume-normalized momentum
// isolates the directional pressure component.
// ============================================================================
define(
title="Ease of Movement V2",
position="offchart",
axis=true
)
// ------------------------------------------------------------------------------
// User Inputs — grouped and constrained per production spec
// ------------------------------------------------------------------------------
// --- EoM Settings ---
var len = input(
name="len",
type="number",
defaultValue=14,
label="EoM Smoothing Length",
constraints={min: 2, max: 50, step: 1},
group="EoM Settings"
)
var div = input(
name="div",
type="number",
defaultValue=10000,
label="Scale Divisor",
constraints={min: 1, max: 1000000, step: 1000},
group="EoM Settings"
)
var useArms = input(
name="useArms",
type="boolean",
defaultValue=true,
label="Use Arms-style Midpoint (H+L)/2",
group="EoM Settings"
)
// --- Signal Line ---
var sigLen = input(
name="sigLen",
type="number",
defaultValue=9,
label="Signal SMA Length",
constraints={min: 2, max: 50, step: 1},
group="Signal"
)
var smoothLen = input(
name="smoothLen",
type="number",
defaultValue=3,
label="EMA Pre-Smoothing Length",
constraints={min: 1, max: 20, step: 1},
group="Signal"
)
// --- Z-Score ---
var zScoreLen = input(
name="zScoreLen",
type="number",
defaultValue=50,
label="Z-Score Lookback",
constraints={min: 10, max: 500, step: 5},
group="Z-Score"
)
var useZScore = input(
name="useZScore",
type="boolean",
defaultValue=true,
label="Enable Z-Score Normalization",
group="Z-Score"
)
// --- Thresholds & Regime ---
var obLevel = input(
name="obLevel",
type="number",
defaultValue=0.15,
label="Overbought Threshold",
constraints={min: 0.01, max: 2.0, step: 0.01},
group="Thresholds"
)
var osLevel = input(
name="osLevel",
type="number",
defaultValue=-0.15,
label="Oversold Threshold",
constraints={min: -2.0, max: -0.01, step: 0.01},
group="Thresholds"
)
var useDynamic = input(
name="useDynamic",
type="boolean",
defaultValue=false,
label="Dynamic Thresholds (volatility-adjusted)",
group="Thresholds"
)
var volLookback = input(
name="volLookback",
type="number",
defaultValue=20,
label="Volatility Lookback",
constraints={min: 5, max: 100, step: 1},
group="Thresholds"
)
var volMultiplier = input(
name="volMultiplier",
type="number",
defaultValue=1.5,
label="Volatility Multiplier",
constraints={min: 0.5, max: 5.0, step: 0.1},
group="Thresholds"
)
// --- Display ---
var showZero = input(
name="showZero",
type="boolean",
defaultValue=true,
label="Show Zero Line",
group="Display"
)
var showSignal = input(
name="showSignal",
type="boolean",
defaultValue=true,
label="Show Signal Line",
group="Display"
)
var showHistogram = input(
name="showHistogram",
type="boolean",
defaultValue=true,
label="Show Momentum Histogram",
group="Display"
)
var showSignalFill = input(
name="showSignalFill",
type="boolean",
defaultValue=true,
label="Show Signal Fill (EoM/signal fill)",
group="Display"
)
var showZScoreLine = input(
name="showZScoreLine",
type="boolean",
defaultValue=true,
label="Show Z-Score Line",
group="Display"
)
var showShapes = input(
name="showShapes",
type="boolean",
defaultValue=true,
label="Show Alert Shapes",
group="Display"
)
var showGuides = input(
name="showGuides",
type="boolean",
defaultValue=true,
label="Show OB/OS Guide Lines",
group="Display"
)
// --- Colors ---
var bullColor = input(
name="bullColor",
type="color",
defaultValue="#26a69a",
label="Bull Color",
group="Colors"
)
var bearColor = input(
name="bearColor",
type="color",
defaultValue="#ef5350",
label="Bear Color",
group="Colors"
)
var signalColor = input(
name="signalColor",
type="color",
defaultValue="#2962ff",
label="Signal Line Color",
group="Colors"
)
var histBullColor = input(
name="histBullColor",
type="color",
defaultValue="#00e676",
label="Histogram Bull Color",
group="Colors"
)
var histBearColor = input(
name="histBearColor",
type="color",
defaultValue="#ff1744",
label="Histogram Bear Color",
group="Colors"
)
var neutralColor = input(
name="neutralColor",
type="color",
defaultValue="#9e9e9e",
label="Neutral Color",
group="Colors"
)
// ------------------------------------------------------------------------------
// Data Sources & NaN Guard
// ------------------------------------------------------------------------------
timeseries bars = ohlcv(symbol=currentSymbol, exchange=currentExchange)
timeseries vol = bars.volume
timeseries px = bars.close
if (isnan(px[0])) {
return
}
// ------------------------------------------------------------------------------
// Ease of Movement — canonical implementation (Arms-style)
// ------------------------------------------------------------------------------
// EoM = MidpointMove / BoxRatio
// MidpointMove = [(H+L)/2 − (H[1]+L[1])/2] / scale
// BoxRatio = Volume / (H − L)
timeseries mid = useArms ? (bars.high + bars.low) / 2.0 : px
timeseries midPm = (mid - mid[1]) / div
// Box ratio: volume / range (guard against zero range)
timeseries range = bars.high - bars.low
timeseries box = range > 0 ? vol / range : 0.0
// Raw EoM with zero-division guard
timeseries eomRaw = box > 0 ? midPm / box : 0.0
// Smoothed EoM (SMA per canonical Arms)
timeseries eomSma = sma(eomRaw, len)
// Pre-smoothing with EMA for noise reduction (optional)
timeseries eom = ema(eomSma, smoothLen)
// ------------------------------------------------------------------------------
// Signal Line
// ------------------------------------------------------------------------------
timeseries signal = sma(eom, sigLen)
// Momentum histogram (EoM minus signal)
timeseries hist = eom - signal
// ------------------------------------------------------------------------------
// Z-Score Normalization
// ------------------------------------------------------------------------------
var eomMean = sma(source=eom, period=zScoreLen)
var eomStd = stddev(source=eom, period=zScoreLen)
var eomZ = (eomStd > 0 && useZScore) ? (eom - eomMean) / eomStd : 0.0
// ------------------------------------------------------------------------------
// Regime Detection
// ------------------------------------------------------------------------------
// Regime classification:
// Bullish: EoM > signal AND EoM > 0 (positive momentum, above signal)
// Bearish: EoM < signal AND EoM < 0 (negative momentum, below signal)
// Neutral: everything else (chop zone / transition)
var regimeBull = eom > signal && eom > 0
var regimeBear = eom < signal && eom < 0
var regimeNeutral = !regimeBull && !regimeBear
var regimeColor = regimeBull ? bullColor : (regimeBear ? bearColor : "#9e9e9e")
// ------------------------------------------------------------------------------
// Dynamic Thresholds (Poterba & Summers 1988 volatility-adjusted)
// ------------------------------------------------------------------------------
var eomVol = stddev(source=eom, period=volLookback)
var dynOb = useDynamic ? math.min(2.0, obLevel + eomVol * volMultiplier) : obLevel
var dynOs = useDynamic ? math.max(-2.0, osLevel - eomVol * volMultiplier) : osLevel
// Guard: ensure dynamic bands never cross
if (dynOb <= dynOs) {
dynOb = 0.15
dynOs = -0.15
}
// ------------------------------------------------------------------------------
// Static State Tracking (Session-level persistence)
// ------------------------------------------------------------------------------
static sessionHighEOM = -999999.0
static sessionLowEOM = 999999.0
static regimeChangeCount = 0
static lastRegime = 0 // 0 = neutral, 1 = bull, -1 = bear
static extremeBullCount = 0
static extremeBearCount = 0
static crossAboveCount = 0
static crossBelowCount = 0
static lastBarIndex = 0
var currentBarIndex = bar_index[0]
if (!isnan(currentBarIndex) && currentBarIndex != lastBarIndex) {
lastBarIndex = currentBarIndex
// Update session extremes
if (eom > sessionHighEOM) {
sessionHighEOM = eom
}
if (eom < sessionLowEOM) {
sessionLowEOM = eom
}
// Track regime changes
var currentRegime = regimeBull ? 1 : (regimeBear ? -1 : 0)
if (lastRegime != currentRegime) {
lastRegime = currentRegime
regimeChangeCount = regimeChangeCount + 1
}
// Track extreme counts
if (eom > dynOb) {
extremeBullCount = extremeBullCount + 1
}
if (eom < dynOs) {
extremeBearCount = extremeBearCount + 1
}
// Track signal crosses
if (eom > signal && !isnan(eom[1]) && eom[1] <= signal[1]) {
crossAboveCount = crossAboveCount + 1
}
if (eom < signal && !isnan(eom[1]) && eom[1] >= signal[1]) {
crossBelowCount = crossBelowCount + 1
}
}
// ------------------------------------------------------------------------------
// Alert Conditions
// ------------------------------------------------------------------------------
var crossUp = eom > signal && !isnan(eom[1]) && eom[1] <= signal[1]
var crossDown = eom < signal && !isnan(eom[1]) && eom[1] >= signal[1]
var obPenetrate = eom > dynOb && !isnan(eom[1]) && eom[1] <= dynOb
var osPenetrate = eom < dynOs && !isnan(eom[1]) && eom[1] >= dynOs
var obExit = eom < dynOb && !isnan(eom[1]) && eom[1] >= dynOb
var osExit = eom > dynOs && !isnan(eom[1]) && eom[1] <= dynOs
var zeroCrossUp = eom > 0 && !isnan(eom[1]) && eom[1] <= 0
var zeroCrossDown = eom < 0 && !isnan(eom[1]) && eom[1] >= 0
// ------------------------------------------------------------------------------
// PLOTTING
// ------------------------------------------------------------------------------
// --- Zero Line ---
if (showZero) {
hline(value=0, color="#ffffff30", width=1)
}
// --- OB / OS Guide Lines ---
if (showGuides) {
hline(value=dynOb, color=opacity(bearColor, 40), width=1)
hline(value=dynOs, color=opacity(bullColor, 40), width=1)
}
// --- EoM Line (regime-colored) ---
plotLine(
value=eom,
width=2,
colors=[regimeColor],
label=["EoM"],
desc=["Ease of Movement (regime-colored). Positive = price advances easily."]
)
// --- Signal Line ---
if (showSignal) {
plotLine(
value=signal,
width=1,
colors=[signalColor],
label=["Signal"],
desc=["SMA of EoM — signal line for momentum direction"]
)
}
// --- Signal Fill (EoM vs signal) ---
if (showSignalFill) {
var signalBull = eom > signal
plotLine(
value=[eom, signal],
width=1,
colors=[opacity(bullColor, 25), opacity(bearColor, 25)],
colorIndex=signalBull ? 0 : 1,
fill=true,
label=["EoM", "Signal"],
desc=["Fill between EoM and signal SMA — momentum divergence visualization"]
)
}
// --- Momentum Histogram (color-coded by regime and direction) ---
if (showHistogram) {
var histColor = hist >= 0 ? histBullColor : histBearColor
plotBar(
value=hist,
colors=[opacity(histBullColor, 60), opacity(histBearColor, 60)],
colorIndex=hist >= 0 ? 0 : 1,
width=1,
label=["EoM Momentum"],
desc=["Histogram of EoM minus signal — momentum strength and direction"]
)
}
// --- Z-Score Line ---
if (showZScoreLine) {
plotLine(
value=eomZ,
width=1,
colors=[bullColor, bearColor, neutralColor],
colorIndex=eomZ > 1.0 ? 0 : (eomZ < -1.0 ? 1 : 2),
label=["EoM Z-Score"],
desc=["Z-score of EoM (±1 = 1 std dev from mean). Standardized momentum."]
)
}
// --- Alert Shapes ---
if (showShapes) {
if (crossUp) {
plotShape(
value=signal,
shape="triangleup",
color=histBullColor,
width=3,
label=["Cross Up"],
desc=["EoM crossed above signal — bullish momentum shift"]
)
}
if (crossDown) {
plotShape(
value=signal,
shape="triangledown",
color=histBearColor,
width=3,
label=["Cross Down"],
desc=["EoM crossed below signal — bearish momentum shift"]
)
}
if (zeroCrossUp) {
plotShape(
value=0,
shape="circle",
color=histBullColor,
width=2,
label=["Zero Cross Up"],
desc=["EoM crossed above zero — positive momentum confirmed"]
)
}
if (zeroCrossDown) {
plotShape(
value=0,
shape="circle",
color=histBearColor,
width=2,
label=["Zero Cross Down"],
desc=["EoM crossed below zero — negative momentum confirmed"]
)
}
if (obPenetrate) {
plotShape(
value=dynOb,
shape="xcross",
color=bearColor,
width=2,
label=["OB Penetrate"],
desc=["EoM entered overbought zone (EoM > " + dynOb + ")"]
)
}
if (osPenetrate) {
plotShape(
value=dynOs,
shape="xcross",
color=bullColor,
width=2,
label=["OS Penetrate"],
desc=["EoM entered oversold zone (EoM < " + dynOs + ")"]
)
}
}
// ------------------------------------------------------------------------------
// Regime Table (last bar only)
// ------------------------------------------------------------------------------
if (isLastBar) {
var regimeText = regimeBull ? "BULLISH" : (regimeBear ? "BEARISH" : "NEUTRAL")
var regimeTextColor = regimeBull ? bullColor : (regimeBear ? bearColor : "#9e9e9e")
var obText = useDynamic ? "Dynamic OB: " + dynOb : "Static OB: " + obLevel
var osText = useDynamic ? "Dynamic OS: " + dynOs : "Static OS: " + osLevel
plotTable(
data=[
["EoM V2", regimeText],
["EoM", eom[0]],
["Signal", signal[0]],
["Momentum", hist[0]],
["EoM Z-Score", eomZ[0]],
["Session High", sessionHighEOM],
["Session Low", sessionLowEOM],
[obText, osText],
["Cross Above", crossAboveCount],
["Cross Below", crossBelowCount]
],
position="top_right",
headerRow=true,
headerColumn=true,
textColor="#e2e8f0",
headerTextColor="#ffffff",
backgroundColor=transparency("#0f172a", 40),
headerBackgroundColor=transparency("#1e293b", 40),
borderColor=transparency("#334155", 40),
borderWidth=1,
fontSize=10,
cellPadding=4
)
}