Quadratic Regression Slope [DW]
"Quadratic Regression Slope [DW]" by DonovanWall, MPL-2.0. Ported to FloScript by FloSignals; modifications under MPL-2.0. Original: Quadratic Regression Slope [DW] (v2.0), read 2026-10-12T15:59:31.241Z; source language v4.
Licence: Mozilla Public License 2.0 (MPL-2.0) — full text. The source is published with it, modifications included, under the same licence.
Quadratic Regression Slope [DW] by DonovanWall, ported from Pine v4. Pane indicator with 3 plots, bar/background colouring and 10 inputs.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © DonovanWall
//██████╗ ██╗ ██╗
//██╔══██╗██║ ██║
//██║ ██║██║ █╗ ██║
//██║ ██║██║███╗██║
//██████╔╝╚███╔███╔╝
//╚═════╝ ╚══╝╚══╝
// ------------------------------------------------------------------------------------------------
// Original author: DonovanWall
// Original title: Quadratic Regression Slope [DW]
// Licence: MPL-2.0 (the header above is the original notice, kept verbatim)
// Pine version: 4
// Fetched: 2026-10-12
// Ported to FloScript by FloSignals; modifications under MPL-2.0.
// Converter: @flosignals/floscript 0.1.0, strict mode, score 100/100
// ------------------------------------------------------------------------------------------------
//@floscript=1
//@version=5
// Converted by the FloScript converter from a Pine-compatible v4 source.
indicator(title="Quadratic Regression Slope [DW]", shorttitle="QRS [DW]", overlay=false)
//by Donovan Wall
//This is a study geared toward identifying price trends using Quadratic regression.
//Quadratic regression is the process of finding the equation of a parabola that best fits the set of data being analyzed.
//In this study, first a quadratic regression curve is calculated, then the slope of the curve is calculated and plotted.
//Custom bar colors are included. The color scheme is based on whether the slope is positive or negative, and whether it is increasing or decreasing.
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Updates:
// -> Migrated to v4.
// -> Updated QRS function for improved performance.
// -> Added an offset parameter to the script, which will base current value on offset values of the extrapolated QR curve.
// -> Included some experimental signal processing procedures:
// - Added an option to normalize the oscillator scale using RMS.
// - Added an optional compression algorithm to the script. This can be used to reduce transients (short duration, high amplitude values) by a specified level of intensity.
// -> Updated color scheme.
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Functions
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Quadratic Regression Slope
QRS(y, t, o) =>
var x = 1
x := x + 1
b0 = math.sum(x, t)
b1 = math.sum(math.pow(x, 2), t)
b2 = math.sum(math.pow(x, 3), t)
b3 = math.sum(math.pow(x, 4), t)
c0 = math.sum(y, t)
c1 = math.sum(x * y, t)
c2 = math.sum(math.pow(x, 2) * y, t)
a0 = ((b1 * b3 - math.pow(b2, 2)) * (c0 * b2 - c1 * b1) - (b0 * b2 - math.pow(b1, 2)) * (c1 * b3 - c2 * b2)) / ((b1 * b3 - math.pow(b2, 2)) * (t * b2 - b0 * b1) - (b0 * b2 - math.pow(b1, 2)) * (b0 * b3 - b1 * b2))
a1 = (c0 * b2 - c1 * b1 - (t * b2 - b0 * b1) * a0) / (b0 * b2 - math.pow(b1, 2))
a2 = (c0 - t * a0 - b0 * a1) / b1
qr = a0 + a1 * (x + o) + a2 * math.pow(x + o, 2)
QRS = qr - (na(qr[1]) ? qr : nz(qr[1]))
QRS
//Highest High Function
hi(x, reset) =>
var hi = 0.0
hi := reset or x > hi ? x : hi
hi
//Cumulative Mean Function
c_mean(y) =>
var x = 0
x := x + 1
var y_sum = 0.0
y_sum := y_sum + y
c_mean = y_sum / x
c_mean
//RMS Function
RMS(x, t) =>
math.sqrt(ta.sma(math.pow(x, 2), t))
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Inputs
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Source
src = input(defval=close, title="Source")
//Sampling Period
per = input.int(defval=89, minval=1, title="Sampling Period")
//Offset
off = input(defval=0, title="Offset")
//Smoothing Period
smper = input.int(defval=2, minval=1, title="Smoothing Period")
//Normalization Toggle
norm = input(defval=false, title="Normalize Output Scale")
//Signal Compression Inputs
use_comp = input(defval=false, title="Use Compression")
comp_intensity = input.float(defval=90.0, minval=0, maxval=100, title="Compression Intensity (%)")
comp_thresh_type = input.string(defval="Auto", options=["Auto", "Custom"], title="Compression Threshold Type")
comp_ht_custom = input.float(defval=0.0, minval=0, title="Custom High Compression Threshold")
comp_lt_custom = input.float(defval=0.0, maxval=0, title="Custom Low Compression Threshold")
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Definitions
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//QRS
qrs1 = QRS(src, per, off)
//RMS Normalization
rms = RMS(qrs1, per)
norm_qrs = qrs1 > 0 ? qrs1 / rms : qrs1 < 0 ? -math.abs(qrs1) / rms : 0
//Oscillator Selection
qrs2 = norm ? norm_qrs : qrs1
//Dichotomized QRS Values
qrs_pos = qrs2 > 0 ? qrs2 : 0
qrs_neg = qrs2 < 0 ? qrs2 : 0
//Compressor Thresholds
hi_qrs = hi(qrs_pos, ta.crossover(qrs2, 0))
lo_qrs = -hi(math.abs(qrs_neg), ta.crossunder(qrs2, 0))
comp_ht = comp_thresh_type == "Auto" ? c_mean(hi_qrs) : comp_ht_custom
comp_lt = comp_thresh_type == "Auto" ? c_mean(lo_qrs) : comp_lt_custom
//Transient Reduction
qrs = use_comp ? (qrs2 > comp_ht ? qrs2 - comp_intensity * (qrs2 - comp_ht) / 100 : qrs2 < comp_lt ? qrs2 + comp_intensity * (comp_lt - qrs2) / 100 : qrs2) : qrs2
//Colors
qcolor = qrs > 0 and qrs > qrs[1] ? #05ffa6 : qrs > 0 and qrs <= qrs[1] ? #00945f : qrs < 0 and qrs < qrs[1] ? #ff0a70 : qrs < 0 and qrs >= qrs[1] ? #990040 : #cccccc
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Outputs
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//QRS
plot(qrs, color=qcolor, style=plot.style_columns, title="QRS")
//Thresholds
plot(use_comp ? comp_ht : na, color=color.new(#cccccc, 80), style=plot.style_circles, title="High Compression Threshold")
plot(use_comp ? comp_lt : na, color=color.new(#cccccc, 80), style=plot.style_circles, title="Low Compression Threshold")
//Bar Color
barcolor(qcolor)
This file is under the Mozilla Public License 2.0; it is a port of the original by DonovanWall, with the original licence header kept and the changes made for FloScript noted in the file.
- v2
Library refresh 2026-10-14
- v1
Library refresh 2026-10-12
Disclaimer. Scripts are written and published by members, or ported by FloSignals from open-source originals, and are their authors' own work and opinion. FloSignals does not review them for correctness and nothing in a script is financial advice or a recommendation to buy or sell anything — read the Risk Disclaimer. Posting here is under the Community Rules; a script that is not the poster's to post can be reported as the Copyright & Takedowns page says.

Comments (0)
No comments yet. Members can leave one.