Files

30 lines
941 B
Plaintext
Raw Permalink Normal View History

// Licensed under the Apache License, Version 2.0
// © mihakralj
//@version=6
indicator("Linear Scaling Transformer (LINEARTRANS)", "LINEARTRANS", overlay=true, precision=8)
//@function Applies a simple affine (linear) transformation: y = slope * x + intercept
//@param src Source series to transform
//@param a Slope (scaling factor). Default 1.0.
//@param b Intercept (offset). Default 0.0.
//@returns Linearly transformed value: a * src + b
//@optimized Single FMA operation per bar — O(1) with zero allocations.
lineartrans(series float src, float a, float b) =>
if na(src)
na
else
a * src + b
// ---------- Main loop ----------
// Inputs
i_source = input.source(close, "Source")
i_slope = input.float(1.0, "Slope (a)")
i_intercept = input.float(0.0, "Intercept (b)")
// Calculation
result = lineartrans(i_source, i_slope, i_intercept)
// Plot
plot(result, "Lineartrans", color=color.yellow, linewidth=2)