xel_arjona

Standard Error of the Estimate -Composite Bands-

Standard Error of the Estimate - Code and adaptation by @glaz & @XeL_arjona
Ver. 2.00.a


Original implementation idea of bands by:
Traders issue: Stocks & Commodities V. 14:9 (375-379):
Standard Error Bands by Jon Andersen


This code is a former update to previous "Standard Error Bands" that was wrongly applied given that previous version in reality use the Standard Error OF THE MEAN, not THE ESTIMATE as it should be used by Jon Andersen original idea and corrected in this version.

As always I am very Thankfully with the support at the Pine Script Editor chat room, with special mention to user @glaz in order to help me adequate the alpha-beta (y-y') algorithm, as well to give him full credit to implement the "wide" version of the former bands.

For a quick and publicly open explanation of this truly statistical (regression analysis) indicator, you can refer at Here!

Extract from the former URL:
Standard Error Bands are quite different than Bollinger's. First, they are bands constructed around a linear regression curve. Second, the bands are based on two standard errors above and below this regression line. The error bands measure the standard error of the estimate around the linear regression line. Therefore, as a price series follows the course of the regression line the bands will narrow, showing little error in the estimate. As the market gets noisy and random, the error will be greater resulting in wider bands.

Script de código abierto

Siguiendo el verdadero espíritu de TradingView, el autor de este script lo ha publicado en código abierto, para que los traders puedan entenderlo y verificarlo. ¡Un hurra por el autor! Puede utilizarlo de forma gratuita, aunque si vuelve a utilizar este código en una publicación, debe cumplir con lo establecido en las Normas internas. Puede añadir este script a sus favoritos y usarlo en un gráfico.

Exención de responsabilidad

La información y las publicaciones que ofrecemos, no implican ni constituyen un asesoramiento financiero, ni de inversión, trading o cualquier otro tipo de consejo o recomendación emitida o respaldada por TradingView. Puede obtener información adicional en las Condiciones de uso.

¿Quiere utilizar este script en un gráfico?
//@version=2
study("Standard Error of the Estimate -Composite Bands-", shorttitle="SEE", overlay=true)
p = input(title="Rolling Lookback Window:", defval=21)
sdeg = input(title="Smoothing Factor:", defval=3)

// Standard Error of the Estimate Algorithm's
beta(array,per) =>
    val1 = sum(n*array,per)-(per*sma(n,per)*sma(array,per))
    val2 = sum(pow(n,2),per)-(per*pow(sma(n,per),2))
    calcB = val1/val2
alpha(array,per) =>
    calcA = sma(array,per)-(beta(array,per)*sma(n,per))
see(array,per,mult,dir,type) =>
    lr = linreg(array,per,0)
    val1 = (sum(pow(array,2),per))-((alpha(array,per)*sum(array,per)))-((beta(array,per)*sum(n*array,per)))
    val2 = per - 2
    narrow = sqrt(val1/val2)
    est = sum(pow(lr-array,2),per) / (per - 2 )
    wide = sqrt(est)
    d = dir ? 1 : -1
    band = type ? narrow : wide
    seb = lr + d * mult * band

// Plotting
UWB = plot(sma(see(close,p,2,true,false),sdeg),color=red,transp=90)
UNB = plot(sma(see(close,p,2,true,true),sdeg),color=red,transp=90)
middle = plot(sma(linreg(close,p,0),sdeg),color=red,style=line,transp=0)
BNB = plot(sma(see(close,p,2,false,true),sdeg),color=red,transp=90)
BWB = plot(sma(see(close,p,2,false,false),sdeg),color=red,transp=90)
fill(UWB,BWB,transp=95,title="WSEE",color=red)
fill(UNB,BNB,transp=90,title="NSEE",color=red)