mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-25 22:08:05 +00:00
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
Deep review of all indicator categories verified .md headers against .cs WarmupPeriod, parameters, inputs, and outputs. Fixes include warmup corrections, parameter documentation, output type accuracy, and Pine Script alignment.
This commit is contained in:
@@ -1,46 +1,29 @@
|
||||
// Licensed under the Apache License, Version 2.0
|
||||
// © mihakralj
|
||||
//@version=6
|
||||
indicator("Linear Transformation (LINEAR)", "Lineartrans", overlay=false)
|
||||
|
||||
//@function Applies a linear transformation (y = a*(x - sma) + sma + b) relative to the source's SMA, calculated internally.
|
||||
//@param source series float The input series to transform.
|
||||
//@param period simple int The lookback period for the internal SMA calculation.
|
||||
//@param a float The scaling factor (slope).
|
||||
//@param b float The offset (intercept).
|
||||
//@returns series float The linearly transformed series relative to its internally calculated SMA.
|
||||
//@optimized for performance and dirty data
|
||||
linear(series float source, float a, float b) =>
|
||||
if na(source) or na(a) or na(b)
|
||||
runtime.error("Parameters 'source', 'a', 'b' cannot be na and 'period' must be > 0.")
|
||||
var int p = 200
|
||||
var array<float> buffer = array.new_float(p, na)
|
||||
var int head = 0
|
||||
var float sum = 0.0
|
||||
var int valid_count = 0
|
||||
float oldest = array.get(buffer, head)
|
||||
if not na(oldest)
|
||||
sum -= oldest
|
||||
valid_count -= 1
|
||||
if not na(source)
|
||||
sum += source
|
||||
valid_count += 1
|
||||
array.set(buffer, head, source)
|
||||
head := (head + 1) % p
|
||||
smaValue = nz(sum / valid_count, source)
|
||||
a * (source - smaValue) + smaValue + b
|
||||
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(close, "Source")
|
||||
i_smaPeriod = input.int(200, "SMA Period", minval=1)
|
||||
i_a = input.float(2.0, "Scale (a)")
|
||||
i_b = input.float(20.0, "Offset (b)")
|
||||
i_source = input.source(close, "Source")
|
||||
i_slope = input.float(1.0, "Slope (a)")
|
||||
i_intercept = input.float(0.0, "Intercept (b)")
|
||||
|
||||
// Calculation
|
||||
transformedSource = linear(i_source, i_a, i_b)
|
||||
result = lineartrans(i_source, i_slope, i_intercept)
|
||||
|
||||
// Plot
|
||||
plot(transformedSource, "Linear Transformation", color=color.yellow, linewidth=2)
|
||||
plot(result, "Lineartrans", color=color.yellow, linewidth=2)
|
||||
|
||||
Reference in New Issue
Block a user