Загрузка...

Pine Script Versions and Execution Model | Pine Script Learning | chapter 5

Pine Script Versions
Pine Script has gone through various versions since its release, each adding new features and optimizations. The current version is Pine Script v5, which introduced several improvements over earlier versions.

Key Versions and Their Features
v1 and v2:

Basic plotting and calculations.
Limited control over security functions and lack of explicit variable declarations.
No support for complex data structures like arrays.
v3:

Introduced more plotting capabilities, including custom shapes and labels.
Enhanced the security function, allowing for the use of higher time frames.
Introduced the := operator to differentiate between variable declaration and re-assignment.
v4:

Added support for arrays, enabling the use of lists to store values, which is essential for more complex algorithms.
Added the request.security() function, enhancing access to data from different time frames and symbols.
Brought improvements in plotting capabilities, like color gradients and line styles.
Introduced line, label, and table objects for more sophisticated chart drawings.
v5:

Added na handling for cleaner syntax and enhanced error handling.
Introduced improved libraries and built-in functions for more robust and efficient coding.
Enhanced table functionality for customized displays on charts.
Added support for input.timeframe and input.source for more versatile user inputs.
Significant enhancements in error reporting and backward compatibility.
Note: It’s always recommended to use the latest version (//@version=5) when starting a new script, as it provides the latest features and best performance. To specify the version, include the line //@version=5 at the top of your script.

Pine Script Execution Model
Understanding the execution model is key to using Pine Script effectively. Pine Script operates differently from most other programming languages because it’s designed to run on each bar of a chart in real-time.

1. Execution Flow
Pine Script code runs once per bar, starting from the leftmost bar (oldest) to the rightmost (most recent).
Each bar’s data is processed sequentially, which means calculations are updated in the order of historical bars.
For each bar, Pine Script re-runs all the code, updating variables and re-computing values.
2. Global Scope and Bar Processing
All variables declared are recalculated on each bar, meaning any value depends on the state of previous bars.
Pine Script's execution model requires you to understand variable states over time. For instance, you need to use := to reassign values conditionally or persist data across bars.
3. On-Bars Calculation
Pine Scripts don’t operate tick-by-tick; instead, they compute values only when a bar closes. Therefore, calculations are based on Open, High, Low, and Close (OHLC) values of each bar rather than real-time updates within the bar.
This impacts how indicators are designed, especially in situations that require intrabar calculations.
4. Variable Persistence
Immutable Variables: These are defined using the = operator and don’t change after their initial assignment.
Mutable Variables: Use the := operator to redefine the value on subsequent bars.
Pine Script retains variable states across bars, which allows for the creation of indicators that rely on historical data.
5. Security and Higher Time Frame (HTF) Data
Pine Script’s request.security() function is essential for multi-timeframe analysis. This function allows you to access data from higher (or even lower) timeframes, such as daily data on a 1-hour chart.
Syntax: request.security(symbol, timeframe, expression), where expression can be any calculation you want to perform on the specified timeframe.

Видео Pine Script Versions and Execution Model | Pine Script Learning | chapter 5 канала Pinecodex
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять