Introduction to Pine Script™ v6
- Pine Script has been upgraded to v6, and all future updates will exclusively support this version.
- Upgrading from v5 to v6 is recommended to access new features and enhancements.
- Migration Guide: Details the changes in Pine behaviors and conversion steps for v5 scripts to v6.
New Features in Pine Script™ v6
1. Dynamic Requests
- Enhanced request.*() Functions:
- Accept "series string" arguments for parameters defining requested contexts.
- A single request.*() call can dynamically change its data feed on historical bars.
- These functions can now be called inside:
- Loops
- Conditional structures
- Exported library functions
- Learn More: Check the "Dynamic requests" section in the Other Timeframes and Data page.
2. Boolean Type Enhancements
- Strict Boolean Values:
- “bool” type values are strictly
trueorfalseand neverna.
- “bool” type values are strictly
- Lazy Evaluation:
- Operators
orandandnow use short-circuit evaluation:- If the first expression in
oristrue, the second is skipped. - If the first expression in
andisfalse, the second is skipped.
- If the first expression in
- Benefits:
- Increased runtime efficiency for scripts using conditional expressions.
- Operators
3. Label and Text Enhancements
- Customizable Text Sizes:
- The
sizeproperty (labels) andtext_sizeproperty (boxes/tables) now supportintvalues. - Sizes are in typographic points, offering more granular control.
- The
- Text Formatting Options:
- New
text_formattingparameter for:label.new()box.new()table.cell()
- Supported formats:
text.format_boldtext.format_italictext.format_none
- Modify formatting using corresponding
set_text_formatting()functions.
- New
4. Strategy Enhancements
- Trade Limit Adjustments:
- Strategies no longer stop calculating when hitting the 9000 trade limit (outside Deep Backtesting mode).
- Oldest trades are trimmed to make room for new ones.
- Strategy Tester:
- Trimmed orders are invisible but do not affect simulations.
- Retrieve the earliest active trade’s index using
strategy.closedtrades.first_index.
5. Array Enhancements
- Negative Indexing:
- Functions now support negative indices to reference elements from the end:
- Example:
array.get(myArray, -2)retrieves the second-to-last element. - Equivalent to:
array.get(myArray, array.size(myArray) - 2).
- Example:
- Affected functions:
array.get()array.set()array.insert()array.remove()
- Functions now support negative indices to reference elements from the end:
Tags
PineScript
