OPEN-SOURCE SCRIPT
Atualizado

Fisher ForLoop [InvestorUnknown]

4 247
Overview

The Fisher ForLoop indicator is designed to apply the Fisher Transform over a range of lengths and signal modes. It calculates an array of Fisher values, averages them, and then applies an EMA to these values to derive a trend signal. This indicator can be customized with various settings to suit different trading strategies.

User Inputs

  1. Start Length (a): The initial length for the Fisher Transform calculation (inclusive).
  2. End Length (b): The final length for the Fisher Transform calculation (inclusive).
  3. EMA Length (c): The length of the EMA applied to the average Fisher values.
  4. Calculation Source (s): The price source used for calculations (e.g., ohlc4).


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 Fisher EMA is above Fisher EMA or above 0.99, otherwise the signal is negative.
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 Fisher EMA changes by more than user defined threshold against the current signal

Pine Script®
// Determine the color based on the EMA value // If EMA is greater than 0, use the bullish color, otherwise use the bearish color col1 = EMA > 0 ? colup : coldn // Determine the color based on the EMA trend // If the current EMA is greater than the previous EMA or greater than 0.99, use the bullish color, otherwise use the bearish color col2 = EMA > EMA[1] or EMA > 0.99 ? colup : coldn // Initialize a variable for the color based on threshold crossings var color col3 = na // If the EMA crosses over the long threshold, set the color to bullish if ta.crossover(EMA, longth) col3 := colup // If the EMA crosses under the short threshold, set the color to bearish if ta.crossunder(EMA, shortth) col3 := coldn // Initialize a variable for the color based on fast threshold changes var color col4 = na // If the EMA increases by more than the fast threshold, set the color to bullish if (EMA > EMA[1] + fastth) col4 := colup // If the EMA decreases by more than the fast threshold, set the color to bearish if (EMA < EMA[1] - fastth) col4 := coldn // Initialize the final color variable color col = na // Set the color based on the selected signal mode if sigmode == "Slow" col := col1 // Use slow mode color if sigmode == "Fast" col := col2 // Use fast mode color if sigmode == "Thresholds Crossing" col := col3 // Use thresholds crossing color if sigmode == "Fast Threshold" col := col4 // Use fast threshold color else na // If no valid signal mode is selected, set color to na


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: FisherForLoop

This function calculates an array of Fisher values over a specified range of lengths (from a to b). It then computes the average of these values and applies an EMA to derive the final trend signal.

Pine Script®
// Function to calculate an array of Fisher values over a range of lengths FisherForLoop(a, b, c, s) => // Initialize an array to store Fisher values for each length var FisherArray = array.new_float(b - a + 1, 0.0) // Loop through each length from 'a' to 'b' for x = 0 to (b - a) // Calculate the current length len = a + x // Calculate the highest and lowest values over the current length high_ = ta.highest(s, len) low_ = ta.lowest(s, len) // Initialize the value variable value = 0.0 // Update the value using the Fisher Transform formula // The formula normalizes the price to a range between -0.5 and 0.5, then smooths it value := .66 * ((s - low_) / (high_ - low_) - .5) + .67 * nz(value[1]) // Clamp the value to be within -0.999 to 0.999 to avoid math errors val = value > .99 ? .999 : value < -.99 ? -.999 : value // Initialize the fish1 variable fish1 = 0.0 // Apply the Fisher Transform to the normalized value // This converts the value to a Fisher value, which emphasizes extreme changes in price fish1 := .5 * math.log((1 + val) / (1 - val)) + .5 * nz(fish1[1]) // Store the previous Fisher value for comparison fish2 = fish1[1] // Determine the trend based on the Fisher values // If the current Fisher value is greater than the previous, the trend is up (1) // Otherwise, the trend is down (-1) trend = fish1 > fish2 ? 1 : -1 // Store the trend in the FisherArray at the current index array.set(FisherArray, x, trend) // Calculate the average of the FisherArray Avg = array.avg(FisherArray) // Apply an EMA to the average Fisher values to smooth the result EMA = ta.ema(Avg, c) // Return the FisherArray, the average, and the EMA [FisherArray, Avg, EMA] // Call the FisherForLoop function with the user-defined inputs [Array, Avg, EMA] = FisherForLoop(a, b, c, s)


Important Considerations

  • Speed: This indicator is very fast and can provide rapid signals for potential entries. However, this speed also means it may generate false signals if used in isolation.
  • Complementary Use: It is recommended to use this indicator in conjunction with other indicators and analysis methods to confirm signals and enhance the reliability of your trading strategy.
  • Strength: The main strength of the Fisher ForLoop indicator is its ability to identify very fast entries and prevent entries against the current (short-term) market trend.


This indicator is useful for identifying trends and potential reversal points in the market, providing flexibility through its customizable settings. However, due to its sensitivity and speed, it should be used as part of a broader trading strategy rather than as a standalone tool.
Notas de Lançamento
- Added option to choose different type of Moving Average

Pine Script®
maType = input.string("EMA", "MA Type", ["EMA", "SMA", "WMA", "VWMA","TMA"], group = "Fisher ForLoop Settings", inline = "M") FisherForLoop(a, b, c, s) => var FisherArray = array.new_float(b - a + 1, 0.0) for x = 0 to (b - a) len = a + x high_ = ta.highest(s, len) low_ = ta.lowest(s, len) value = 0.0 value := .66 * ((s - low_) / (high_ - low_) - .5) + .67 * nz(value[1]) val = value > .99 ? .999 : value < -.99 ? -.999 : value fish1 = 0.0 fish1 := .5 * math.log((1 + val) / (1 - val)) + .5 * nz(fish1[1]) fish2 = fish1[1] trend = fish1 > fish2 ? 1 : -1 array.set(FisherArray, x, trend) Avg = array.avg(FisherArray) float FisherMA = switch maType "EMA" => ta.ema(Avg, c) "SMA" => ta.sma(Avg, c) "WMA" => ta.wma(Avg, c) "VWMA" => ta.vwma(Avg, c) "TMA" => ta.trima(Avg, c) => runtime.error("No matching MA type found.") float(na) [FisherArray, Avg, FisherMA]


- Adjusted signal calculation for the "Fast" signal to work well with different types of the Moving Average

Pine Script®
// Fast var color col2 = na if FisherMA > FisherMA[1] or FisherMA > 0.99 col2 := colup if FisherMA < FisherMA[1] or FisherMA < -0.99 col2 := coldn


- Added Alerts

barconfirm = input.bool(false, "Wait for bar close for Alert?", group = "Alert Settings")

Pine Script®
var int alertsignal = na if col == colup alertsignal := 1 if col == coldn alertsignal := -1 Long = ta.crossover(alertsignal, 0) Short = ta.crossunder(alertsignal, 0) alertcondition(barconfirm ? Long[1] : Long, "LONG", "Fisher ForLoop went Long") alertcondition(barconfirm ? Short[1] : Short,"SHORT", "Fisher ForLoop went Short")

Aviso legal

As informações e publicações não devem ser e não constituem conselhos ou recomendações financeiras, de investimento, de negociação ou de qualquer outro tipo, fornecidas ou endossadas pela TradingView. Leia mais em Termos de uso.