Declares a variable that persists across bars and, unlike var, keeps its changes between ticks of the live bar.
varip works like var: initialised once, then kept from bar to bar. The difference is only on the live bar. A var variable is rolled back to its value at the bar's open before each new tick, while a varip variable is not, so changes made on an earlier tick of the same bar stay.
On historical bars the script runs once per bar, so var and varip behave identically there. That makes varip the way to count ticks or to record something that happened intrabar, such as the highest value seen between ticks, and it makes any varip result differ between a backtest and live trading.
Syntax
varip [<variable_type> ]<variable_name> = <expression> [export ]type <UDT_identifier> varip <field_type> <field_name> [= <value>]Remarks
- varip accepts int, float, bool, color and string values, and objects whose fields are declared with varip.
- A varip counter resets when the chart reloads, since history replays without the ticks.
- On Sidechair: varip behaves the same as var. The live bar is rolled back and rerun on every update, so a varip variable does not keep tick-level changes.
Example
//@version=6
indicator("Varip")
varip int ticks = 0
var int bars = 0
ticks += 1
if barstate.isnew
bars += 1
plot(ticks, "Calculations", color.orange)
plot(bars, "Bars", color.blue)See also
Runs on Sidechair