Library · Pine Script v6 · Library

Skipp Math

by skipp-dev· code credited to preuss_steffen

Skipp Math is a utility library for Pine Script v6 containing constants and functions for probability calculations, statistical analysis, and data normalization.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code137
Settings0inputs
LicenceNone statedfile: MPL-2.0
Last update2 days ago26 Oct 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new library, select all of the template text and paste. Press Save and give it a name.
  4. 4Publish or import itA library draws nothing. Publish it from the editor, then import its functions in your own scripts.

Source Code

137 lines of Pine Script v6 from pine/skipp_math.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

skipp_math.pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © preuss_steffen

//@version=6
library("skipp_math", overlay = true)
// Last refreshed: 2026-07-03

// --------------------------------------------------
// Constants
// --------------------------------------------------
// 2026-08-26 (#4756): getter-functions -> `export const` (moeglich seit
// Juni 2025). Werte unveraendert; API-Bruch nur in der Form (kein `()`).

export const float PROB_EPS    = 0.0001
export const float LOGIT_CLAMP = 20.0
export const float PRICE_EPS   = 0.0001
export const float Z_95        = 1.96

// --------------------------------------------------
// Clamping
// --------------------------------------------------

export clamp01(float x) =>
    math.max(0.0, math.min(1.0, x))

export clamp(float val, float lo, float hi) =>
    math.max(lo, math.min(hi, val))

export eps_clamp(float p) =>
    float eps = PROB_EPS
    math.max(eps, math.min(1.0 - eps, p))

// --------------------------------------------------
// Probability / logit
// --------------------------------------------------

export logit(float p) =>
    float pc = math.max(PROB_EPS, math.min(1.0 - PROB_EPS, p))
    math.max(-LOGIT_CLAMP, math.min(LOGIT_CLAMP, math.log(pc / (1.0 - pc))))

export sigmoid(float x) =>
    x < -500.0 ? 0.0 : x > 500.0 ? 1.0 : 1.0 / (1.0 + math.exp(-x))

export platt_prob(float pRaw, float a, float b) =>
    sigmoid(a * logit(pRaw) + b)

export safe_log(float p) =>
    math.log(math.max(PROB_EPS, p))

// --------------------------------------------------
// Range position (min-max normalisation)
// --------------------------------------------------

// @function Position of x inside its [lowest, highest] band over `len`
//           bars, in [0, 1] (stochastic-%K style min-max normalisation).
//           NOT a percentile rank: a single outlier high/low rescales
//           every value; for skewed distributions this diverges strongly
//           from ta.percentrank semantics.
export range_position(series float x, simple int len) =>
    float lo = ta.lowest(x, len)
    float hi = ta.highest(x, len)
    hi == lo ? 0.5 : (x - lo) / (hi - lo)

// @function DEPRECATED misnomer (2026-07-08): despite the name this is
//           min-max range position, not a percentile rank — see
//           range_position (identical behavior). Kept so existing
//           importers keep compiling; new code must call range_position.
export pct_rank(series float x, simple int len) =>
    range_position(x, len)

// --------------------------------------------------
// Statistics
// --------------------------------------------------

export ci95_halfwidth(float p, float n) =>
    if na(p) or na(n) or n <= 0.0
        float(na)
    else
        float z2  = Z_95 * Z_95
        float den = 1.0 + z2 / n
        float half = (Z_95 * math.sqrt((p * (1.0 - p) / n) + (z2 / (4.0 * n * n)))) / den
        half

export brier(float p, float y) =>
    float d = p - y
    d * d

export logloss(float p, float y) =>
    float pc = eps_clamp(p)
    if na(pc) or na(y)
        float(na)
    else
        -(y * math.log(pc) + (1.0 - y) * math.log(1.0 - pc))

// --------------------------------------------------
// Array safety
// --------------------------------------------------

export safe_remove_float(float[] arr, int idx) =>
    if idx >= 0 and idx < array.size(arr)
        array.remove(arr, idx)

export safe_remove_int(int[] arr, int idx) =>
    if idx >= 0 and idx < array.size(arr)
        array.remove(arr, idx)

export safe_remove_bool(bool[] arr, int idx) =>
    if idx >= 0 and idx < array.size(arr)
        array.remove(arr, idx)

export safe_get_float(float[] arr, int idx, float fallback) =>
    idx >= 0 and idx < array.size(arr) ? array.get(arr, idx) : fallback

export safe_get_int(int[] arr, int idx, int fallback) =>
    idx >= 0 and idx < array.size(arr) ? array.get(arr, idx) : fallback

export safe_get_bool(bool[] arr, int idx, bool fallback) =>
    idx >= 0 and idx < array.size(arr) ? array.get(arr, idx) : fallback

// --------------------------------------------------
// Misc helpers
// --------------------------------------------------

export min_sec(float a, float b) =>
    na(a) ? b : na(b) ? a : math.min(a, b)

export soft(bool x) =>
    (x == true) ? true : (x == false) ? false : true

export fail_open(bool _cond) =>
    _cond == true ? true : (_cond == false) ? false : true

export score_add(bool cond, int points) =>
    cond ? points : 0

export penalty(bool cond, int penalties) =>
    cond ? penalties : 0

Overview

Skipp Math provides clamping utilities, logit and sigmoid transformations, range position computation, 95% confidence interval half-width, Brier score, log loss, and safe array removal methods. The library emphasizes numerical stability with safety checks and does not plot directly on the chart but supports scripts that overlay on the price chart. It defines no input settings and is intended as a foundational module.

Details

Published by

skipp-dev on GitHub

Code credit

preuss_steffen, as written in the script's header

Type

Library, Pine Script v6

Draws

Library (no plots)

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

FunctionLinearRegression

by ricardosantos79
261 stars

This Pine Script v5 library provides functions to calculate and plot linear regression channels using sample point arrays. It evaluates paired X and Y arrays to calculate the regression slope, intercept, fitted values, maximum deviation, minimum deviation, and

Library v5 Trend
Updated 4 years ago · None stated GitHub repository of FunctionLinearRegression

PositionSizing

by iamrichardD
57 stars

This Pine Script v6 library calculates trade position sizes and provides risk management functions for external scripts. It computes position sizes from account equity, percentage risk, and stop-loss distance, and offers dynamic sizing adjustments based on vol

Library v6
Updated 1 year ago · Apache-2.0 GitHub repository of PositionSizing

Chart Patterns

by deepentropy
13 stars

Chart Patterns is a Pine Script v6 library designed to scan for and render technical chart patterns directly on the price chart. It defines custom user-defined types to configure scanning parameters, such as Zigzag pivot offsets, error ratios, flat ratios, and

Library v6 Repaints
Updated 6 months ago · MIT GitHub repository of Chart Patterns

AuthLib

by alboogycOdR
6 stars

AuthLib is a Pine Script utility library providing access control and state management structures for technical indicators. It checks callers against a hardcoded array of authorized TradingView usernames before executing operations. The library exports user-de

Library v5 SMC / ICT / price actionSessions & time
Updated 7 months ago · None stated GitHub repository of AuthLib

WebhookMessageLibrary

by TradersPost
6 stars

WebhookMessageLibrary is a helper library designed to construct structured JSON payload messages for automated trading integrations like TradersPost. It defines custom exported types and constants for trade actions, market sentiments, quantities, limit prices,

Library v5
Updated 1 year ago · None stated GitHub repository of WebhookMessageLibrary

PineDraw

by 345-strategies
5 stars

PineDraw is a Pine Script v6 library that provides object primitives for drawing and updating price levels on the chart. It enables indicators and strategies to maintain lines, boxes, and labels in place by updating existing objects instead of deleting and rec

Library v6 Support & resistance
Updated 2 days ago · MPL-2.0 GitHub repository of PineDraw

More libraries

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers