InvestorUnknown

Adaptive Trend Classification: Moving Averages [InvestorUnknown]

InvestorUnknown 업데이트됨   
Adaptive Trend Classification: Moving Averages

Overview

The Adaptive Trend Classification (ATC) Moving Averages indicator is a robust and adaptable investing tool designed to provide dynamic signals based on various types of moving averages and their lengths. This indicator incorporates multiple layers of adaptability to enhance its effectiveness in various market conditions.

Key Features

Adaptability of Moving Average Types and Lengths: The indicator utilizes different types of moving averages (EMA, HMA, WMA, DEMA, LSMA, KAMA) with customizable lengths to adjust to market conditions.
Dynamic Weighting Based on Performance:] Weights are assigned to each moving average based on the equity they generate, with considerations for a cutout period and decay rate to manage (reduce) the influence of past performances.
Exponential Growth Adjustment:The influence of recent performance is enhanced through an adjustable exponential growth factor, ensuring that more recent data has a greater impact on the signal.
Calibration Mode: Allows users to fine-tune the indicator settings for specific signal periods and backtesting, ensuring optimized performance.
Visualization Options: Multiple customization options for plotting moving averages, color bars, and signal arrows, enhancing the clarity of the visual output.
Alerts: Configurable alert settings to notify users based on specific moving average crossovers or the average signal.


User Inputs

Adaptability Settings
λ (Lambda): Specifies the growth rate for exponential growth calculations.
Decay (%): Determines the rate of depreciation applied to the equity over time.
CutOut Period: Sets the period after which equity calculations start, allowing for a focus on specific time ranges.
Robustness Lengths: Defines the range of robustness for equity calculation with options for Narrow, Medium, or Wide adjustments.
Long/Short Threshold: Sets thresholds for long and short signals.
Calculation Source: The data source used for calculations (e.g., close price).

Moving Averages Settings
Lengths and Weights: Allows customization of lengths and initial weights for each moving average type (EMA, HMA, WMA, DEMA, LSMA, KAMA).

Calibration Mode
Calibration Mode: Enables calibration for fine-tuning inputs.
Calibrate: Specifies which moving average type to calibrate.
Strategy View: Shifts entries and exits by one bar for non-repainting backtesting.



Calculation Logic

Rate of Change (R): Calculates the rate of change in the price.
Set of Moving Averages: Generates multiple moving averages with different lengths for each type.

diflen(length) =>
    int L1 = na,       int L_1 = na
    int L2 = na,       int L_2 = na
    int L3 = na,       int L_3 = na
    int L4 = na,       int L_4 = na
    if robustness == "Narrow"
        L1 := length + 1,        L_1 := length - 1
        L2 := length + 2,        L_2 := length - 2
        L3 := length + 3,        L_3 := length - 3
        L4 := length + 4,        L_4 := length - 4
    else if robustness == "Medium"
        L1 := length + 1,        L_1 := length - 1
        L2 := length + 2,        L_2 := length - 2
        L3 := length + 4,        L_3 := length - 4
        L4 := length + 6,        L_4 := length - 6
    else
        L1 := length + 1,        L_1 := length - 1
        L2 := length + 3,        L_2 := length - 3
        L3 := length + 5,        L_3 := length - 5
        L4 := length + 7,        L_4 := length - 7        
    [L1,L2,L3,L4,L_1,L_2,L_3,L_4]

  // Function to calculate different types of moving averages
ma_calculation(source, length, ma_type) =>
    if ma_type == "EMA"
        ta.ema(source, length)
    else if ma_type == "HMA"
        ta.sma(source, length)
    else if ma_type == "WMA"
        ta.wma(source, length)
    else if ma_type == "DEMA"
        ta.dema(source, length)
    else if ma_type == "LSMA"
        lsma(source,length)
    else if ma_type == "KAMA"
        kama(source, length)
    else
        na

// Function to create a set of moving averages with different lengths
SetOfMovingAverages(length, source, ma_type) =>
    [L1,L2,L3,L4,L_1,L_2,L_3,L_4] = diflen(length)
    MA   = ma_calculation(source,  length, ma_type)
    MA1  = ma_calculation(source,  L1,     ma_type)
    MA2  = ma_calculation(source,  L2,     ma_type)
    MA3  = ma_calculation(source,  L3,     ma_type)
    MA4  = ma_calculation(source,  L4,     ma_type)
    MA_1 = ma_calculation(source, L_1,     ma_type)
    MA_2 = ma_calculation(source, L_2,     ma_type)
    MA_3 = ma_calculation(source, L_3,     ma_type)
    MA_4 = ma_calculation(source, L_4,     ma_type)
    [MA, MA1, MA2, MA3, MA4, MA_1, MA_2, MA_3, MA_4]

Exponential Growth Factor: Computes an exponential growth factor based on the current bar index and growth rate.

// The function `e(L)` calculates an exponential growth factor based on the current bar index and a given growth rate `L`.
e(L) =>
    // Calculate the number of bars elapsed.
    // If the `bar_index` is 0 (i.e., the very first bar), set `bars` to 1 to avoid division by zero.
    bars = bar_index == 0 ? 1 : bar_index    
    // Define the cuttime time using the `cutout` parameter, which specifies how many bars will be cut out off the time series.
    cuttime = time[cutout]    
    // Initialize the exponential growth factor `x` to 1.0.
    x = 1.0    
    // Check if `cuttime` is not `na` and the current time is greater than or equal to `cuttime`.
    if not na(cuttime) and time >= cuttime
        // Use the mathematical constant `e` raised to the power of `L * (bar_index - cutout)`.
        // This represents exponential growth over the number of bars since the `cutout`.
        x := math.pow(math.e, L * (bar_index - cutout))    
    x

Equity Calculation: Calculates the equity based on starting equity, signals, and the rate of change, incorporating a natural decay rate.
pine code

// This function calculates the equity based on the starting equity, signals, and rate of change (R).
eq(starting_equity, sig, R) =>
    cuttime = time[cutout]
    if not na(cuttime) and time >= cuttime
        // Calculate the rate of return `r` by multiplying the rate of change `R` with the exponential growth factor `e(La)`.
        r = R * e(La)
        // Calculate the depreciation factor `d` as 1 minus the depreciation rate `De`.
        d = 1 - De
        var float a = 0.0
        // If the previous signal `sig[1]` is positive, set `a` to `r`.
        if (sig[1] > 0)
            a := r
        // If the previous signal `sig[1]` is negative, set `a` to `-r`.
        else if (sig[1] < 0)
            a := -r
        // Declare the variable `e` to store equity and initialize it to `na`.
        var float e = na
        // If `e[1]` (the previous equity value) is not available (first calculation):
        if na(e[1])
            e := starting_equity
        else
            // Update `e` based on the previous equity value, depreciation factor `d`, and adjustment factor `a`.
            e := (e[1] * d) * (1 + a)
        // Ensure `e` does not drop below 0.25.
        if (e < 0.25)
            e := 0.25
        e
    else
        na

Signal Generation: Generates signals based on crossovers and computes a weighted signal from multiple moving averages.

Main Calculations

The indicator calculates different moving averages (EMA, HMA, WMA, DEMA, LSMA, KAMA) and their respective signals, applies exponential growth and decay factors to compute equities, and then derives a final signal by averaging weighted signals from all moving averages.


Visualization and Alerts

The final signal, along with additional visual aids like color bars and arrows, is plotted on the chart. Users can also set up alerts based on specific conditions to receive notifications for potential trading opportunities.

Repainting

The indicator does support intra-bar changes of signal but will not repaint once the bar is closed, if you want to get alerts only for signals after bar close, turn on “Strategy View” while setting up the alert.

Conclusion

The Adaptive Trend Classification: Moving Averages Indicator is a sophisticated tool for investors, offering extensive customization and adaptability to changing market conditions. By integrating multiple moving averages and leveraging dynamic weighting based on performance, it aims to provide reliable and timely investing signals.
릴리즈 노트:
Correction of the Short threshold input "title"

// Before
Short_threshold = input.float(-0.1, "Long Threshold", step = 0.01, group = "Adaptability Settings")
// Now
Short_threshold = input.float(-0.1, "Short Threshold", step = 0.01, group = "Adaptability Settings")
오픈 소스 스크립트

이 스크립트의 오써는 참된 트레이딩뷰의 스피릿으로 이 스크립트를 오픈소스로 퍼블리쉬하여 트레이더들로 하여금 이해 및 검증할 수 있도록 하였습니다. 오써를 응원합니다! 스크립트를 무료로 쓸 수 있지만, 다른 퍼블리케이션에서 이 코드를 재사용하는 것은 하우스룰을 따릅니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.

면책사항

이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.

차트에 이 스크립트를 사용하시겠습니까?