xel_arjona

ORDINARY LEAST SQUARES Slope by @XeL_Arjona

ORDINARY LEAST SQUARES Slope by @XeL_Arjona
Ver. 1 by Ricardo M Arjona @XeL_Arjona

DISCLAIMER:

The Following indicator/code IS NOT intended to be a formal investment advice or recommendation by the author, nor should be construed as such. Users will be fully responsible by their use regarding their own trading vehicles/assets.

The embedded code and ideas within this work are FREELY AND PUBLICLY available on the Web for NON LUCRATIVE ACTIVITIES and must remain as is.


WHAT'S THIS?

This is a REAL mathematically approach of an ORDINARY LEAST SQUARES LINE FITTING SLOPE as TradingView currently don't have a native one embedded, neither as a pine function. Other "Sope" indicators from this linear regression model I found on public library are currently based on "momentum" rather tan slope.

Any modifications or additions are quite welcome!

Cheers!
@XeL_Arjona

Mã nguồn mở

Với tinh thần TradingView, tác giả của tập lệnh này đã xuất bản nó dưới dạng mã nguồn mở, vì vậy các nhà giao dịch có thể hiểu và xác minh nó. Chúc mừng tác giả! Bạn có thể sử dụng mã này miễn phí, nhưng việc sử dụng lại mã này trong một ấn phẩm chịu sự điều chỉnh của Nội quy nội bộ. Bạn có thể yêu thích nó để sử dụng nó trên biểu đồ.

Thông báo miễn trừ trách nhiệm

Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.

Bạn muốn sử dụng tập lệnh này trên biểu đồ?
//@version=2
study("ORDINARY LEAST SQUARES Slope by @XeL_Arjona",shorttitle="LinReg Slope", overlay=false,precision=4)
p   = input(title="Lookback Window:",defval=21)
src = input(title="Series Source:",type=source,defval=close)
// SLOPE FUNCTION
ols_slope(array,lookback) =>
    x1 = n[lookback]
    x2 = n
    y1 = linreg(array,lookback,lookback)
    y2 = linreg(array,lookback,0)
    dx = x2-x1
    dy = y2-y1
    out = (dy/dx)
// STUDY VARIABLES TO OUTPUT
slp = ols_slope(src,p)
// PLOTTING DIRECTIVES
plot(slp,style=columns,color=slp>0?blue:red,title="OLS Slope",transp=55)