gain
Positive price change (gain)
gain(source)
Parameters
| Name | Type | Description |
|---|---|---|
source |
field | Data series to measure (typically close) |
Formula
gain = GREATEST(source - source[1], 0)
Examples
// stock gained today
gain(close) > 0;
// gained more than $2 today
gain(close) > 2;
// total gains over last 14 days
sum(gain(close), 14) > 10;
// today was an up day (gain exceeded loss)
gain(close) > loss(close);
Returns
float
Notes
Always non-negative; returns 0 on the first bar and on any bar where price doesn't rise. Pair with sum() or wilderma() to aggregate gains over time.