mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-22 04:28:04 +00:00
29 lines
919 B
Plaintext
29 lines
919 B
Plaintext
// The MIT License (MIT)
|
|||
|
|
// © mihakralj
|
||
|
|
//@version=6
|
||
|
|
indicator("Square Root Transformation (SQRT)", "Sqrttrans", overlay=false)
|
||
|
|
|
||
|
|
//@function Applies a square root transformation (y = √x) to the input series.
|
||
|
|
//@doc https://github.com/mihakralj/pinescript/blob/main/indicators/numerics/sqrt.md
|
||
|
|
//@param source series float The input series to transform. Must contain non-negative values.
|
||
|
|
//@returns series float The square root transformed series. Returns na if source < 0.
|
||
|
|
//@optimized for performance and dirty data
|
||
|
|
sqrtT(series float source) =>
|
||
|
|
if na(source)
|
||
|
|
runtime.error("Parameter 'source' cannot be na.")
|
||
|
|
if source < 0
|
||
|
|
na
|
||
|
|
else
|
||
|
|
math.sqrt(source)
|
||
|
|
|
||
|
|
// ---------- Main loop ----------
|
||
|
|
|
||
|
|
// Inputs
|
||
|
|
i_source = input(close, "Source")
|
||
|
|
|
||
|
|
// Calculation
|
||
|
|
transformedSource = sqrtT(i_source)
|
||
|
|
|
||
|
|
// Plot
|
||
|
|
plot(transformedSource, "Square Root Transformation", color=color.yellow, linewidth=2)
|