VanHe1sing

Machine Learning: Multiple Logistic Regression

VanHe1sing Cập nhật   

Multiple Logistic Regression Indicator
The Logistic Regression Indicator for TradingView is a versatile tool that employs multiple logistic regression based on various technical indicators to generate potential buy and sell signals. By utilizing key indicators such as RSI, CCI, DMI, Aroon, EMA, and SuperTrend, the indicator aims to provide a systematic approach to decision-making in financial markets.

How It Works:

  • Technical Indicators:
    The script uses multiple technical indicators such as RSI, CCI, DMI, Aroon, EMA, and SuperTrend as input variables for the logistic regression model.
    These indicators are normalized to create categorical variables, providing a consistent scale for the model.

  • Logistic Regression:
    The logistic regression function is applied to the normalized input variables (x1 to x6) with user-defined coefficients (b0 to b6).
    The logistic regression model predicts the probability of a binary outcome, with values closer to 1 indicating a bullish signal and values closer to 0 indicating a bearish signal.

  • Loss Function (Cross-Entropy Loss):
    The cross-entropy loss function is calculated to quantify the difference between the predicted probability and the actual outcome.
    The goal is to minimize this loss, which essentially measures the model's accuracy.
    // Error Function (cross-entropy loss)
    loss(y, p) =>
        -y * math.log(p) - (1 - y) * math.log(1 - p)
    
    // y - depended variable
    // p - multiple logistic regression


  • Gradient Descent:
    Gradient descent is an optimization algorithm used to minimize the loss function by adjusting the weights of the logistic regression model.
    The script iteratively updates the weights (b1 to b6) based on the negative gradient of the loss function with respect to each weight.
    // Adjusting model weights using gradient descent 
    b1 -= lr * (p + loss) * x1
    b2 -= lr * (p + loss) * x2
    b3 -= lr * (p + loss) * x3
    b4 -= lr * (p + loss) * x4
    b5 -= lr * (p + loss) * x5
    b6 -= lr * (p + loss) * x6
    
    // lr - learning rate or step of learning
    // p - multiple logistic regression
    // x_n - variables

  • Learning Rate:
    The learning rate (lr) determines the step size in the weight adjustment process. It prevents the algorithm from overshooting the minimum of the loss function.
    Users can set the learning rate to control the speed and stability of the optimization process.

  • Visualization:
    The script visualizes the output of the logistic regression model by coloring the SMA.
    Arrows are plotted at crossover and crossunder points, indicating potential buy and sell signals.
    Lables are showing logistic regression values from 1 to 0 above and below bars

  • Table Display:
    A table is displayed on the chart, providing real-time information about the input variables, their values, and the learned coefficients.
    This allows traders to monitor the model's interpretation of the technical indicators and observe how the coefficients change over time.

    How to Use:

  • Parameter Adjustment:
    Users can adjust the length of technical indicators (rsi_length, cci_length, etc.) and the Z score length based on their preference and market characteristics.
    Set the initial values for the regression coefficients (b0 to b6) and the learning rate (lr) according to your trading strategy.

  • Signal Interpretation:
    Buy signals are indicated by an upward arrow (▲), and sell signals are indicated by a downward arrow (▼).
    The color-coded SMA provides a visual representation of the logistic regression output by color.

  • Table Information:
    Monitor the table for real-time information on the input variables, their values, and the learned coefficients.
    Keep an eye on the learning rate to ensure a balance between model adjustment speed and stability.

  • Backtesting and Validation:
    Before using the script in live trading, conduct thorough backtesting to evaluate its performance under different market conditions.
    Validate the model against historical data to ensure its reliability.

Phát hành các Ghi chú:
-
Phát hành các Ghi chú:
Alert Update:

Phát hành các Ghi chú:
Alert Update.

Alert Conditons
Alert UP: when logistic reg crossover 0.5 value
"Logistic Regression UP"

Alert DOWN: when logistic reg crossunder 0.5 value
"Logistic Regression DOWN"

Any alert() Function Call:
"Logistic Regression: 1▲"
or
"Logistic Regression: 1▼"
Phát hành các Ghi chú:

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 đồ?