An ultra-low latency tensor computation and deep neural runtime engineered natively for Pine Script v6. Execute dynamic forward-backward propagation, register symbolic math tapes, and compile complex non-convex neural topologies directly on live candlestick feeds.
Bypass clumsy external broker bridges, web sockets, and high-overhead execution APIs. NeuraLib runs client-side inside the TradingView engine, achieving sub-millisecond weight inference.
NeuraLib is designed to powernext-generation indicatorsinside PineScript v6
NeuraLib is for the full workflow: features, targets, scaling, batches, training, validation, and inference. The value is not a prepackaged signal; it is a runtime developers can build on.
No complex math required. NeuraLib’s autograd engine automatically tracks and compiles derivative gradients under the hood, allowing you to train complex networks with a single function call.
Build any network topology from standard feed-forward structures to recurrent networks. NeuraLib automatically compiles your design into an optimized mathematical model that executes instantly on chart feeds.
Instantly plug in popular machine learning activations including ReLU, Leaky ReLU, Sigmoid, and Tanh, pre-optimized for rapid calculations.
Runs entirely within TradingView's memory limits. It automatically recycles old calculation data, keeping your charts responsive and fast.
Prevent the most critical mistake in financial machine learning: look-ahead leakage. NeuraLib separates training batches from the newest held-out rows, then evaluates validation data through profiles fit on the training side only.
trainBatch() computes the model input side first. validationBatch() returns the held-out tail, but keeps scaling anchored to the same training-side feature and target profile.
Validation rows are the newest chronological rows after the training prefix. As new bars are pushed, prior validation rows naturally graduate into the training side while the freshest rows become the new holdout tail.
Rolling datasets can select a target row after each feature window with targetOffset. That is a forward label offset, not a separate no-data barrier between training and validation.
NeuraLib includes standard regression and classification losses alongside trading-oriented objectives such as directional, quantile, multi-horizon weighted, and Sharpe-style loss. Optimizers are selected through the same compile flow, from SGD and momentum through RMSProp, Adam, and AdamW.
Use Huber for outlier-tolerant regression, directional loss for sign-aware training, and quantile or multi-horizon weighting when the label structure needs asymmetric emphasis.
Compile models with SGD, Momentum, RMSProp, Adam, or AdamW. AdamW adds decoupled weight decay when regularization is needed, but it remains one option in the optimizer set.
Use presetSharpe() when the experiment should score predicted returns through a risk-adjusted objective instead of plain point error. It sits alongside the standard loss suite, not in place of it.
NeuraLib_Models adds Conv1D temporal networks, LSTM and GRU recurrent models, Transformers with Self Attention, and Reinforcement Learning utilities directly onto normal nl.Sequential chains. The model still trains, validates, predicts, and manages weights through the same core NeuraLib runtime.
Build Pine Script sequence models that extract local structure from rolling market windows, compress temporal activations with 1D pooling, and route them into compact prediction or action-value heads.
.input(array.from(8), "state_window") .temporalConvStack(4, 2, 2, 2, 1) .globalAvgPool1d(3, 2) .duelingQHead(4, 3)
The expansion supplies architecture blocks. Core NeuraLib still owns tensors, datasets, scaling, optimizers, losses, validation, prediction, and weight updates.
NeuraLib encapsulates complex matrix mathematics into clean, developer-focused interfaces. Spin up a dense sequential layer map and compile learning schedules in a few straightforward lines.
//@version=6
// Core Layer Setup - NeuraLib Sequential Model
import Alien_Algorithms/NeuraLib/1 as nl
var nl.Model model = nl.newSequential(
name = "E-Mini SP500 Trend Predictor",
optimizer = nl.optimizer.adamw(lr = 0.002, weightDecay = 1e-4)
)
if barstate.isfirst
model.add(nl.layers.dense(inputs = 8, units = 16, activation = nl.activation.leaky_relu()))
model.add(nl.layers.dropout(rate = 0.15))
model.add(nl.layers.dense(inputs = 16, units = 8, activation = nl.activation.tanh()))
model.add(nl.layers.dense(inputs = 8, units = 1, activation = nl.activation.linear()))
// Fit compile parameters using Huber directional loss
model.compile(loss = nl.loss.huber(delta = 1.0))A NeuraLib experiment is not a one-line prediction call. The useful loop is to define the data contract, collect clean rows, train against a chronological holdout, and only then route predictions into indicator logic.
Fix the feature width, target shape, model architecture, loss, optimizer, and training gate before rows start flowing through the script.
Build feature and target rows from confirmed chart data, then push them into WindowDataset or RollingDataset so invalid rows are rejected and scaler profiles stay controlled.
Request trainBatch() and validationBatch(), update weights only on the training side, and evaluate the held-out side without letting validation data rewrite the model.
Scale live inputs, run predict(), inverse-scale outputs when needed, then compare prediction behavior, training loss, and validation loss before changing the experiment.
Gain immediate TradingView access to the NeuraLib ML Engine. Build self-learning indicators, deploy neural network architectures, and stop hard-coding static logic.
Quant conceptualized and built by Alien_Algorithms.