gain
Positive price change (gain)
gain(source)
Parameters
| Name | Type | Description |
|---|---|---|
source |
field | Data series to measure (typically close) |
Formula
```
gain = max(source - source[1], 0)
If today's price > yesterday's: gain = difference
If today's price <= yesterday's: gain = 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 >= 0 (the positive price change, or 0 if price didn't rise) ## Notes - Always returns a non-negative value - Returns 0 on the first bar (no previous bar to compare) - Use with sum() or wilderma() to aggregate gains over time ## See Also loss, rsi, change