Skip to content
Algo Trade Analytics Docs

varip - Pine Script Keyword

varip (var intrabar persist) is the keyword used for the assignment and one-time initialization of a variable or a field of a user-defined type. It’s similar to the var keyword, but variables and fields declared with varip retain their values between executions of the script on the same bar.

varip [<variable_type> ]<variable_name> = <expression>
[export ]type <UDT_identifier>
varip <field_type> <field_name> [= <value>]
  • When using varip to declare variables in strategies that may execute more than once per historical chart bar, the values of such variables are preserved across successive iterations of the script on the same bar.
//@version=6indicator("varip with types")type barData    int index = -1    varip int ticks = -1var currBar = barData.new()currBar.index += 1currBar.ticks += 1// Will be equal to bar_index on all barsplot(currBar.index)// In real time, will increment per every tick on the chartplot(currBar.ticks)