Posts

Showing posts with the label Rolling Window

Pine Script Arrays: Push, Remove, and Average Values Across Multiple Bars (v6 Guide)

Image
When a single series value per bar is not enough, Pine Script's array type lets you store, manipulate, and aggregate arbitrary collections of numbers at runtime — enabling rolling windows, dynamic buffers, and multi-value statistics that the built-in ta.* functions cannot express alone. 1. What Is an Array in Pine Script? An array in Pine Script v6 is an ordered, zero-indexed collection of elements of a single type (e.g., array<float> , array<int> , array<bool> ). Unlike a series , which automatically stores one value per historical bar, an array is a mutable object whose size and contents you control explicitly with built-in array.* functions. Key Characteristics Zero-indexed: The first element is at index 0 ; the last is at index array.size(arr) - 1 . Mutable: Elements can be added, removed, or overwritten at any time. Typed: All elements must share the same declared type. Persistent with var ...