You are using an out of date browser. It may not display this or other websites correctly.

You should upgrade or use an alternative browser.

You should upgrade or use an alternative browser.

- Thread starter Sean_C
- Start date

Repaints

Solution

See if this is what you're looking for. I found it in the Thinkscript Cloud.

Code:

```
# Quadratic Regression
# Robert Payne
# funwiththinkscript.com
input length = 20;
def n = length;
def bn = BarNumber();
def lastBar = HighestAll(if IsNaN(close) then 0 else bn);
def x = bn;
def y = close;
# calculate summation values
def startBar = lastBar - (n - 1);
def sumX = if bn < startBar then 0 else x + sumX[1];
def sumY = if bn < startBar then 0 else y + sumY[1];
def sumX2 = if bn < startBar then 0 else Power(x, 2) + sumX2[1];
def sumX3 = if bn < startBar then 0 else Power(x, 3) + sumX3[1];
def sumX4 = if bn < startBar then 0 else Power(x, 4) + sumX4[1];
def sumXY = if bn < startBar then 0 else x * y + sumXY[1];
def sumX2Y...
```

Also, @RobertPayne- any chance of a discount to usethinkscript members for your indicators for sale on your site?

See if this is what you're looking for. I found it in the Thinkscript Cloud.

Code:

```
# Quadratic Regression
# Robert Payne
# funwiththinkscript.com
input length = 20;
def n = length;
def bn = BarNumber();
def lastBar = HighestAll(if IsNaN(close) then 0 else bn);
def x = bn;
def y = close;
# calculate summation values
def startBar = lastBar - (n - 1);
def sumX = if bn < startBar then 0 else x + sumX[1];
def sumY = if bn < startBar then 0 else y + sumY[1];
def sumX2 = if bn < startBar then 0 else Power(x, 2) + sumX2[1];
def sumX3 = if bn < startBar then 0 else Power(x, 3) + sumX3[1];
def sumX4 = if bn < startBar then 0 else Power(x, 4) + sumX4[1];
def sumXY = if bn < startBar then 0 else x * y + sumXY[1];
def sumX2Y = if bn < startBar then 0 else Power(x, 2) * y + sumX2Y[1];
# intermediary calculations
def xx = sumX2 - Power(sumX, 2) / n;
def xy = sumXY - (sumX * sumY / n);
def xx2 = sumX3 - (sumX2 * sumX / n);
def x2y = sumX2Y - (sumX2 * sumY / n);
def x2x2 = sumX4 - (Power(sumX2, 2) / n);
# calculate coefficients for the quadratic equation
def a0 = (x2y * xx - xy * xx2) / (xx * x2x2 - Power(xx2, 2));
def b0 = (xy * x2x2 - x2y * xx2) / (xx * x2x2 - Power(xx2, 2));
def c0 = sumY / n - b0 * sumX / n - a0 * sumX2 / n;
# for a, b, and c use the final value on the last bar of the chart for all calculations
def a = GetValue(a0, bn - lastBar);
def b = GetValue(b0, bn - lastBar);
def c = GetValue(c0, bn - lastBar);
# calculate and plot the regression curve
plot theCurve = if bn < startBar then Double.NaN else a * Power(x, 2) + b * x + c;
#####
```

If it works, please post a picture here!

I was looking for a PRC but not seeing one? Don Monkey made one but it's not shared. It's a fancy LRC that fits the price better. I am a mean reversion trader so I would use them for range estimates.@Jonas99 How is the TradingView version different from all the COGs, Hursts, and Polynomial Regression already written for ToS?

Given that these are the worst of the worst repainters, how do you use this in your strategy?

@markos This Quad regression line looks impressive. Any idea how can to make two lines like a channel instead of single line ? higher line touching highs and lower line touching lows

See if this is what you're looking for. I found it in the Thinkscript Cloud.

Code:`# Quadratic Regression # Robert Payne # funwiththinkscript.com input length = 20; def n = length; def bn = BarNumber(); def lastBar = HighestAll(if IsNaN(close) then 0 else bn); def x = bn; def y = close; # calculate summation values def startBar = lastBar - (n - 1); def sumX = if bn < startBar then 0 else x + sumX[1]; def sumY = if bn < startBar then 0 else y + sumY[1]; def sumX2 = if bn < startBar then 0 else Power(x, 2) + sumX2[1]; def sumX3 = if bn < startBar then 0 else Power(x, 3) + sumX3[1]; def sumX4 = if bn < startBar then 0 else Power(x, 4) + sumX4[1]; def sumXY = if bn < startBar then 0 else x * y + sumXY[1]; def sumX2Y = if bn < startBar then 0 else Power(x, 2) * y + sumX2Y[1]; # intermediary calculations def xx = sumX2 - Power(sumX, 2) / n; def xy = sumXY - (sumX * sumY / n); def xx2 = sumX3 - (sumX2 * sumX / n); def x2y = sumX2Y - (sumX2 * sumY / n); def x2x2 = sumX4 - (Power(sumX2, 2) / n); # calculate coefficients for the quadratic equation def a0 = (x2y * xx - xy * xx2) / (xx * x2x2 - Power(xx2, 2)); def b0 = (xy * x2x2 - x2y * xx2) / (xx * x2x2 - Power(xx2, 2)); def c0 = sumY / n - b0 * sumX / n - a0 * sumX2 / n; # for a, b, and c use the final value on the last bar of the chart for all calculations def a = GetValue(a0, bn - lastBar); def b = GetValue(b0, bn - lastBar); def c = GetValue(c0, bn - lastBar); # calculate and plot the regression curve plot theCurve = if bn < startBar then Double.NaN else a * Power(x, 2) + b * x + c; #####`

If it works, please post a picture here!

## PolynomialQuadraticMA_JQ

## v01.10.2021 version 01 dated October 2021

## based on

## Polynomial Quadratic Moving Average

## Mobius

## V01.09.2021

## JQ adulterations;

## the Y from close to (close + vwap)/2

## added a label identifying Y and n

##

## use with SingleBar VWAP to visualize the single bar VWAP

## mobius' comments and header

#15:33 Mobius: Bored so fooling around with close to zero lag moving averages again.

# Polynomial Quadratic Moving Average

# Mobius

# V01.09.2021

input n = 20; # mobius default was 20

script E

{

input y = 1;

input n = 10;

def t = fold i = 0 to n

with s

do s + getValue(y, i);

plot output = t;

}

def y = (close + VWAP )/2; #mobius y = close

def x = compoundValue(1, x[1] + 1, 1);

def Ex = E(x, n);

def Ey = E(y, n);

def Ex2 = E(sqr(x), n);

def Ex3 = E(power(x, 3), n);

def Ex4 = E(power(x, 4), n);

def Exy = E(x*y, n);

def Ex2y = E(sqr(x)*Y, n);

def Exx = Ex2 - (sqr(Ex)/n);

def Ex_y = Exy - ((Ex * Ey)/n);

def Exx2 = Ex3 - ((Ex2 * Ex)/n);

def Ex2_y = Ex2y - ((Ex2 * Ey)/n);

def Ex2x2 = Ex4 - (sqr(Ex2)/n);

def a = ((Ex2_y * Exx) - (Ex_y * Exx2)) / ((Exx * Ex2x2) - sqr(Exx2));

def b = ((Ex_y * Ex2x2) - (Ex2_y * Exx2)) / ((Exx * Ex2x2) - Sqr(Exx2));

def c = (Ey / n) - (b * (Ex / n)) - (a * (Ex2 / n));

plot poly = (a*sqr(x)) + (b*x) + c;

#label by JQ

addlabel (1, "Polynomial Quadratic Moving Average y=(close +vwap)/2 n=" + n + " ", poly.takevaluecolor());

# End Code Polynomial Quadratic Moving Average

## v01.10.2021 version 01 dated October 2021

## based on

## Polynomial Quadratic Moving Average

## Mobius

## V01.09.2021

## JQ adulterations;

## the Y from close to (close + vwap)/2

## added a label identifying Y and n

##

## use with SingleBar VWAP to visualize the single bar VWAP

## mobius' comments and header

#15:33 Mobius: Bored so fooling around with close to zero lag moving averages again.

# Polynomial Quadratic Moving Average

# Mobius

# V01.09.2021

input n = 20; # mobius default was 20

script E

{

input y = 1;

input n = 10;

def t = fold i = 0 to n

with s

do s + getValue(y, i);

plot output = t;

}

def y = (close + VWAP )/2; #mobius y = close

def x = compoundValue(1, x[1] + 1, 1);

def Ex = E(x, n);

def Ey = E(y, n);

def Ex2 = E(sqr(x), n);

def Ex3 = E(power(x, 3), n);

def Ex4 = E(power(x, 4), n);

def Exy = E(x*y, n);

def Ex2y = E(sqr(x)*Y, n);

def Exx = Ex2 - (sqr(Ex)/n);

def Ex_y = Exy - ((Ex * Ey)/n);

def Exx2 = Ex3 - ((Ex2 * Ex)/n);

def Ex2_y = Ex2y - ((Ex2 * Ey)/n);

def Ex2x2 = Ex4 - (sqr(Ex2)/n);

def a = ((Ex2_y * Exx) - (Ex_y * Exx2)) / ((Exx * Ex2x2) - sqr(Exx2));

def b = ((Ex_y * Ex2x2) - (Ex2_y * Exx2)) / ((Exx * Ex2x2) - Sqr(Exx2));

def c = (Ey / n) - (b * (Ex / n)) - (a * (Ex2 / n));

plot poly = (a*sqr(x)) + (b*x) + c;

#label by JQ

addlabel (1, "Polynomial Quadratic Moving Average y=(close +vwap)/2 n=" + n + " ", poly.takevaluecolor());

# End Code Polynomial Quadratic Moving Average

Last edited by a moderator:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|

M | Create AddOrder statement for Linear Regression Slope | Questions | 1 | |

R | Linear Regression Reversal Scan | Questions | 0 | |

Linear Regression R-Squared | Questions | 1 | ||

G | Linear regression for rsi and slow stochastic | Questions | 1 | |

Linear Regression Angle | Questions | 3 |

Start a new thread and receive assistance from our community.

87k+
Posts

273
Online

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club

- Exclusive indicators
- Proven strategies & setups
- Private Discord community
- ‘Buy The Dip’ signal alerts
- Exclusive members-only content
- Add-ons and resources
- 1 full year of unlimited support

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

- The most viewed thread:

https://usethinkscript.com/threads/repainting-trend-reversal-for-thinkorswim.183/ - Our most popular indicator:

https://usethinkscript.com/threads/buy-the-dip-indicator-for-thinkorswim.3553/ - Answers to frequently asked questions:

https://usethinkscript.com/threads/answers-to-commonly-asked-questions.6006/

What are the benefits of VIP Membership?

VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.

How can I access the premium indicators?

To access the premium indicators, which are plug and play ready, sign up for VIP membership here.