mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-06 04:57:44 +00:00
53 lines
1.8 KiB
Plaintext
53 lines
1.8 KiB
Plaintext
// Licensed under the Apache License, Version 2.0
|
|
// © mihakralj
|
|
//@version=6
|
|
indicator("Ehlers Fisher Transform (FISHER)", "FISHER", overlay=false)
|
|
|
|
//@function Calculates the Fisher Transform oscillator
|
|
//@param source Source price (typically hl2)
|
|
//@param period Lookback period for min/max normalization
|
|
//@returns [fisher, signal] Fisher Transform value and signal line
|
|
fisher(series float source, simple int period) =>
|
|
if period <= 0
|
|
runtime.error("Period must be greater than 0")
|
|
if period > 500
|
|
runtime.error("Period exceeds maximum of 500")
|
|
|
|
var float value = 0.0
|
|
var float fisher = 0.0
|
|
var float signal = 0.0
|
|
|
|
float highest = ta.highest(source, period)
|
|
float lowest = ta.lowest(source, period)
|
|
|
|
float price_range = highest - lowest
|
|
float normalized = price_range > 0 ? (source - lowest) / price_range : 0.5
|
|
normalized := 2.0 * normalized - 1.0
|
|
|
|
float alpha = 0.33
|
|
value := alpha * normalized + (1.0 - alpha) * value
|
|
|
|
// Ehlers/Skender: snap to ±0.999 when |Value1| > 0.99
|
|
value := value > 0.99 ? 0.999 : value < -0.99 ? -0.999 : value
|
|
|
|
// Ehlers 2002: Fish = arctanh(Value1) + 0.5 * Fish[1] (IIR feedback)
|
|
fisher := 0.5 * math.log((1.0 + value) / (1.0 - value)) + 0.5 * fisher
|
|
|
|
// Signal = Fish[1] (previous bar's Fisher)
|
|
signal := fisher[1]
|
|
|
|
[fisher, signal]
|
|
|
|
// ---------- Main loop ----------
|
|
|
|
i_period = input.int(10, "Period", minval=1, maxval=500)
|
|
i_source = input.source(hl2, "Source")
|
|
|
|
[fisher_line, signal_line] = fisher(i_source, i_period)
|
|
|
|
plot(fisher_line, "Fisher", color=color.yellow, linewidth=2)
|
|
plot(signal_line, "Signal", color=color.orange, linewidth=1)
|
|
hline(0, "Zero", color=color.gray, linestyle=hline.style_dotted)
|
|
hline(2, "Overbought", color=color.red, linestyle=hline.style_dashed)
|
|
hline(-2, "Oversold", color=color.green, linestyle=hline.style_dashed)
|