loss
Negative price change (loss)
loss(source)
Measures the magnitude of negative change from the previous bar. When price falls, loss() returns the absolute amount of the decline as a positive number. When price rises or stays flat, it returns 0. This isolates downward movement for analysis, and is a core building block for RSI and other momentum indicators.
Parameters
- source (field): Data series to measure (typically close)
Formula
loss = abs(min(source - source[1], 0))
If today's price < yesterday's: loss = |difference|
If today's price >= yesterday's: loss = 0
Examples
Filter for Down Days
Find stocks that closed lower than the previous day:
// stock declined today
loss(close) > 0;
Significant Downward Movement
Find stocks with large single-day declines:
// lost more than $2 today
loss(close) > 2;
Cumulative Losses
Track total losses over a period using sum():
// total losses over last 14 days
sum(loss(close), 14) > 10;
Gain vs Loss Comparison
Compare today's downward vs upward movement:
// today was a down day (loss exceeded gain)
loss(close) > gain(close);
Returns
Float >= 0 (the absolute price decline, or 0 if price didn't fall)
Notes
- Always returns a non-negative value (losses are expressed as positive numbers)
- Returns 0 on the first bar (no previous bar to compare)
- Use with sum() or wilderma() to aggregate losses over time