Training & Data

Configuring Training

Define what error means, how gradients update weights, how learning rate evolves, and when Pine is allowed to perform expensive training work.

Updated Publisher Alien_AlgorithmsPine Script v6

CompileConfig

Training configurationpine
nl.CompileConfig cfg = nl.compileConfig()
cfg := cfg
  .optimizer(nl.adamW(0.003))
  .schedule(nl.warmupCosine(0.003, 25, 300))
  .loss(nl.LossKind.huber)
  .metric(nl.MetricKind.mae)
  .clipNorm(1.0)
  .withTrainingGate(true)
MethodPurpose
.optimizer(state)Selects SGD, Momentum, RMSProp, Adam, or AdamW state.
.schedule(state)Controls learning rate over optimizer steps.
.loss(kind)Defines the differentiable training objective.
.reduction(kind)Controls how per-element loss becomes a batch loss.
.metric(kind)Tracks an interpretable secondary measure without changing gradients.
.clipNorm(v) / .clipValue(v)Constrains unstable gradients.
.gradAccumSteps(n)Accumulates gradients across calls before applying an update.
.historyLength(n)Controls stored training-stat history.

Task presets

Presets configure sensible loss and metric combinations, then remain chainable so you can override optimizer or stability controls.

PresetUse
.presetPriceRegression()Predicting a price level.
.presetReturnRegression()Predicting a signed return.
.presetBinaryDirection()Two-class probability output.
.presetBinaryDirectionLogits()Two-class raw-logit output.
.presetQValues()Action-value or reinforcement-learning-style targets.
.presetSharpe()Sharpe-style risk-adjusted objective.

Optimizers

ConstructorNotes
nl.sgd(lr)Plain gradient descent; simple and easy to reason about.
nl.momentum(lr, momentum)Adds a velocity term to smooth updates.
nl.rmsprop(lr, rho, epsilon)Adaptive rates from a running squared-gradient profile.
nl.adam(lr, beta1, beta2, epsilon)Modern adaptive default using first and second moments.
nl.adamW(lr, beta1, beta2, epsilon, weightDecay)Adam with decoupled weight decay; the recommended NeuraLib starting point.

Learning-rate schedules

  • constantSchedule() keeps one rate.
  • stepDecay() reduces the rate at fixed intervals.
  • cosineDecay() smoothly decays toward a minimum.
  • warmupCosine() ramps up gently before cosine decay.

Training stability

Gradient clipping

.clipNorm(1.0) is a strong default for recurrent, temporal, and deeper models. Value clipping is available when individual gradient spikes are the concern.

Regularization

Use compact architectures, dropout, AdamW weight decay, chronological validation, and early stopping together. No single setting prevents overfitting.

Start with fewer degrees of freedom
In Pine, a smaller model is both cheaper and often statistically safer. Begin with 4–8 hidden units and grow only when validation behavior supports it.

Cadence controls

.batchSize(n), .epochsPerBar(n), and .evalStride(n) express training preferences. Execution gates determine whether a call is allowed to update at all.

  • Live-edge gate: .withTrainingGate(true) trains only at the confirmed historical edge and onward.
  • Every call: .trainEveryCall() permits updates across historical execution; reserve it for compact models or manual cadence gates.
NeuraLib is a machine-learning research runtime for Pine Script. Model output is not financial advice and does not guarantee future performance. © Alien_Algorithms.