InvestorUnknown

Infinite Impulse Response Filter ForLoop [InvestorUnknown]

Overview


The Infinite Impulse Response Filter ForLoop indicator is designed for seeking quick and accurate trend identification. Leveraging the Infinite Impulse Response (IIR) filter technique, this indicator provides fast and responsive signals to aid in market timing and trend following.

User Inputs

  • Start and End Lengths: Define the range of lengths over which the IIRF values are calculated.
  • Moving Average Type: Choose from EMA, SMA, WMA, VWMA, or TMA for trend smoothing.
  • Moving Average Length: Specify the length for the chosen MA type.
  • Calculation Source: Select the price data used for calculations (default is close price).

Signal Calculation

Signal Mode (sigmode): Determines the type of signal generated by the indicator. Options are "Fast", "Slow", "Thresholds Crossing", and "Fast Threshold".
1. Slow: is a simple crossing of the midline (0).
2. Fast: positive signal depends if the current MA > MA or MA is above 0.99, negative signals comes if MA < MA or MA is below -0.99.
3. Thresholds Crossing: simple ta.crossover and ta.crossunder of the user defined threshold for Long and Short.
4. Fast Threshold: signal changes if the value of MA changes by more than user defined threshold against the current signal

col1 = MA > 0 ? colup : coldn
var color col2 = na
if MA > MA[1] or MA > 0.99
    col2 := colup
if MA < MA[1] or MA < -0.99
    col2 := coldn
var color col3 = na
if ta.crossover(MA,longth)
    col3 := colup
if ta.crossunder(MA,shortth)
    col3 := coldn
var color col4 = na 
if (MA > MA[1] + fastth)
    col4 := colup
if (MA < MA[1] - fastth)
    col4 := coldn

color col = switch sigmode
    "Slow" => col1
    "Fast" => col2
    "Thresholds Crossing" => col3
    "Fast Threshold" => col4

Visualization Settings

  • Bull Color (colup): The color used to indicate bullish signals.
  • Bear Color (coldn): The color used to indicate bearish signals.
  • Color Bars (barcol): Option to color the bars based on the signal.

Custom function

// Function to calculate an array of IIRF values over a range of lengths
IIRFforLoop(a, b, c, s) =>
    // Initialize an array to store IIRF values
    var Array = array.new_float(b - a + 1, 0.0)
    
    // Loop over the range from 'a' to 'b'
    for x = 0 to (b - a)
        // Calculate the length for the current iteration
        len = a + x
        
        // Calculate the IIRF alpha parameter
        iirfAlpha = 2 / (len + 1)
        
        // Calculate the lag for the IIRF calculation
        iirfLag = math.round(1 / iirfAlpha - 1)
        
        // Initialize the IIRF value
        iirf = 0.0
        
        // Update the IIRF value using the IIR filter formula
        iirf := iirfAlpha * (s + ta.change(s, iirfLag)) + (1 - iirfAlpha) * nz(iirf[1])
        
        // Determine the trend based on the current and previous IIRF values
        trend = iirf > iirf[1] ? 1 : -1
        
        // Store the trend value in the array
        array.set(Array, x, trend)
    
    // Calculate the average of the IIRF values in the array
    Avg = array.avg(Array)
    
    // Calculate the moving average of the average IIRF values based on the selected MA type
    float MA = switch maType
        "EMA" =>   ta.ema(Avg,    c)     // Exponential Moving Average
        "SMA" =>   ta.sma(Avg,    c)     // Simple Moving Average
        "WMA" =>   ta.wma(Avg,    c)     // Weighted Moving Average
        "VWMA" =>  ta.vwma(Avg,   c)     // Volume Weighted Moving Average
        "TMA" =>   ta.trima(Avg,  c)     // Triangular Moving Average
        => 
            runtime.error("No matching MA type found.") // Error handling for invalid MA type
            float(na)
    
    // Return the array of IIRF values, their average, and the moving average
    [Array, Avg, MA]

Important Considerations

Rapid Signal Response: The IIRF ForLoop is designed to provide very fast trend signals, making it suitable for short-term trading and quick decision-making.
Complementary Tool: While powerful, the IIRF ForLoop should be used in conjunction with other indicators and market analysis techniques to confirm signals and improve trading accuracy.

Conclusion

The Infinite Impulse Response Filter ForLoop indicator is a highly responsive and flexible tool that can significantly enhance your trading strategy. Its ability to quickly identify trends and generate signals based on various moving average types and customizable thresholds makes it invaluable for active traders. For the best results, use this indicator alongside other technical analysis tools to confirm signals and ensure robust trading decisions.
오픈 소스 스크립트

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

면책사항

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

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