mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-03 11:47:44 +00:00
86fe32a682
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: aider (openrouter/anthropic/claude-sonnet-4) <aider@aider.chat> Co-authored-by: Warp <agent@warp.dev>
29 lines
1.1 KiB
Plaintext
29 lines
1.1 KiB
Plaintext
// The MIT License (MIT)
|
|
// © mihakralj
|
|
//@version=6
|
|
indicator("Logistic Function (SIGMOID)", "SIGMOID", overlay=false, precision=6)
|
|
|
|
//@function Applies the logistic (sigmoid) function to a source series.
|
|
// Formula: S(x) = 1 / (1 + exp(-k * (x - x0)))
|
|
// Maps any real-valued input to the range (0, 1).
|
|
//@doc https://github.com/mihakralj/pinescript/blob/main/indicators/numerics/sigmoid.md
|
|
//@param src The source series.
|
|
//@param k The steepness factor of the sigmoid curve. Higher k means a steeper curve.
|
|
//@param x0 The x-value of the sigmoid's midpoint (where the output is 0.5).
|
|
//@returns The sigmoid transformed series, values between 0 and 1.
|
|
sigmoid(series float src, simple float k, float x0) =>
|
|
1 / (1 + math.exp(-k * (src - x0)))
|
|
|
|
// ---------- Main loop ----------
|
|
|
|
// Inputs
|
|
i_source = input.source(close, "Source")
|
|
i_steepness_k = input.float(0.5, "Steepness (k)", minval = 0.000001, step = 0.1)
|
|
|
|
// Calculation
|
|
sigmoidValue = sigmoid(i_source, i_steepness_k, ta.sma(i_source,200))
|
|
|
|
// Plot
|
|
plot(sigmoidValue, "Sigmoid", color=color.yellow, linewidth=2)
|
|
|