Library Reference
Browse the PyneCore library overview for built-in market data variables and function usage. Find the modules and types used when writing indicators and strategies.
The PyneCore library is a complete Python implementation of the Pine Script API, providing compatibility with Pine Script functions and modules. This library enables easy porting of Pine Script code to Python while taking advantage of all the benefits of the Python language.
Usage
To use the PyneCore library, simply import the required modules or functions from the pynecore.lib package:
"""
@pyne
"""
from pynecore.lib import ta, math, array, close, high, low
# Import specific functions from a module
from pynecore.lib.ta import sma, ema, macdGlobal Properties
The global variables familiar from Pine Script (such as open, high, low, close, hl2, etc.) are available in
PyneCore from the pynecore.lib package:
"""
@pyne
"""
from pynecore.lib import open, high, low, close
from pynecore.lib import hl2, hlc3, ohlc4, hlcc4
from pynecore.lib import volume, bar_indexThese variables are automatically managed by the system, always filled with the current bar data during execution.
Module System
The complete module system of the Pine Script API is available in PyneCore. The module names are almost identical to Pine Script names, with only one exception:
| Pine | PyneCore | Note |
|---|---|---|
| str | string | str is a built-in Python type name, so it’s available as string |
Main Modules
The most important modules of the PyneCore library:
- ta: Technical indicators and analysis functions
- math: Mathematical functions
- array: Array operation functions
- string: Text handling functions
- timeframe: Timeframe handling functions
- color: Color definitions and manipulation functions
- session: Session handling functions
- strategy: Strategy functions and definitions
- request: Cross-symbol/timeframe data and currency conversion
Combining Pine Script and Python Styles
PyneCore allows both Pine Script functional and native Python styles. This flexibility lets you choose the most comfortable and efficient approach for a given task:
"""
@pyne
"""
from pynecore.lib import array, map
# Pine Script-style array module usage
a = array.new_float(5)
array.set(a, 0, 1.0)
array.push(a, 2.0)
# Or use the same with native Python list operations
a[0] = 1.0
a.append(2.0)
# Pine Script-style map module usage
m = map.new()
map.put(m, "key", 42)
# Or use the same with native Python dict operations
m["key"] = 42All functional Pine modules (array, map, etc.) in the PyneCore library work completely, but Python’s native solutions can also be used, keeping code readability and personal preferences in mind.
Pine Script Compatibility
The PyneCore library implements the Pine Script API while leveraging Python’s strengths. PyneCore is validated against TradingView on 1,000 published TradingView scripts (Pine Script v4âv6, converted to Pyne code with PyneComp): all 1,353 comparable outputs match, 99.771% of 132 million plotted values are bit-identical, and 353,577 strategy trades match TradingView’s timing (snapshot 2026-10-24, Pyne in the Wild). See Compatibility for details.
Documentation
PyneCore has its own complete reference documentation covering all library functions, variables, and constants with PyneCore-specific examples and compatibility notes.
- PyneCore Reference - Complete reference for all namespaces
- PyneCore Reference â Library - Function reference by namespace
Usage Examples
Technical Indicators
"""
@pyne
"""
from pynecore.lib import script, ta, close, plot
@script.indicator(title="SMA and EMA Comparison")
def main():
sma_val = ta.sma(close, 20)
ema_val = ta.ema(close, 20)
plot(sma_val, "SMA 20")
plot(ema_val, "EMA 20")Mathematical Functions
"""
@pyne
"""
from pynecore.lib import script, math, close, plot
@script.indicator(title="Correlation Example")
def main():
val1 = math.abs(close - close[1])
result = math.log(val1) if val1 > 0 else 0
plot(result, "Log of Abs Change")Strategy Example
"""
@pyne
"""
from pynecore.lib import script, ta, close, high, low
from pynecore.lib import strategy
@script.strategy("Simple Crossover Strategy")
def main():
fast_ma = ta.sma(close, 9)
slow_ma = ta.sma(close, 21)
if ta.crossover(fast_ma, slow_ma):
strategy.entry("Long", strategy.long)
if ta.crossunder(fast_ma, slow_ma):
strategy.entry("Short", strategy.short)Python Advantages
While PyneCore provides full compatibility with the Pine Script API, you can also take advantage of Python language features. For more detailed differences, see the Differences from Pine Script page.
NA Handling
"""
@pyne
"""
from pynecore.lib import script, close, na, nz, plot
@script.indicator(title="NA Handling")
def main():
prev: float = close[1] # na on the first bar
# na() is the test: true for a numeric na, an infinite float, an NA object or ""
if na(prev):
prev = close
change = nz(close - close[1]) # na replaced by 0.0
plot(change, "Change")A numeric na (float or int) is a native float('nan'); na(float) and NA(float) both
return it. Arithmetic propagates it and every comparison with it is False, as in Pine. Inside
Pyne code, na(x) is the correct test: isinstance(x, NA) is False for a numeric na, and
x == na never matches. Outside the transformed script, in plain Python that consumes PyneCore
results, the value is an ordinary nan: test it with math.isnan() (bool(nan) is True).
More Complex Modules
The PyneCore library also includes more complex modules, such as the strategy module for strategy development, or
various display options. These are typically accessible in a submodule structure:
"""
@pyne
"""
from pynecore.lib import script, close, volume, plot
@script.indicator(title="Plot Styles")
def main():
# Style constants live in the plot namespace
plot(close, title="Line Type", style=plot.style_line)
plot(volume, title="Column Type", style=plot.style_columns)