Simplifying Everyday Life
Inverse Fisher Transform
Find answers to commonly asked questions about our products and services.
Summary
This script is based on the Inverse Fisher Transform applied to the average price of an asset, focusing on the highs and lows within a defined period.
It smooths values using past data and clamps them to avoid extreme inputs in the transformation.
The Inverse Fisher Transform is used to create an oscillator, which can indicate overbought and oversold conditions, making trend reversals more visible.
Practical Usage
The indicator is designed to detect potential turning points in the market. A trader might look for: Crossovers of the fish
line and its delayed (fish[1]
) version.
Positive and negative values around the zero line to spot trend changes.
This oscillator is often combined with other indicators to confirm entries and exits in trades.
Would you like a Python version of this script to work on?
Show the chart.
Let’s input Symbol, We will show the chart.
Can you show me the Pine Scripts code?
Yes, we offer the code:
…………………..
“` //@version=3
// author m2007@paran.com
// creator John EHLERS
study(“Inverse Fisher Transform on High Low”, shorttitle=”IFTHL”)
Len = input(10)
Price = (high + low ) /2
MaxH = highest (Price, Len)
MinL = lowest(Price, Len)
value11 = .52((Price – MinL) / (MaxH – MinL) – .5)
value12 = .5*value11[1]
value1 = value11 + value12
value2 = iff(value1 > -.9999 and value1 <.9999 ,value1 , ( iff (value1 > .9999 , .9999 , iff(value1 < -.9999, -.9999, value1))) )
fish1 = 0.25log((1+ value2) / (1 – value2)) fish2 = .5fish1[1]
fish = fish1 + fish2
plot(fish, color=red, linewidth = 2)
plot(fish[1], color=blue, linewidth =1)
plot(0) “` study this code
………………..
This Pine Script code implements the Inverse Fisher Transform applied to the average of the high and low prices of an asset. It was authored by “m2007@paran.com” and is attributed to John Ehlers, a well-known figure in the technical analysis community for his contributions to advanced indicators. Let’s break down the code piece by piece:
………………..
Explanation of Code
Study Definition:study("Inverse Fisher Transform on High Low", shorttitle="IFTHL")
This line defines the study and its title, allowing users to see it in the TradingView interface.
The shorttitle
parameter is a shorter identifier for this indicator.
Input:Len = input(10)
Len
is the input value, which defines the length of the period for calculating the highest high and lowest low. The default value is set to 10
.
Price Calculation:Price = (high + low) / 2
Price
is calculated as the average of the high and low prices for each bar, resulting in a value representing the “mid-point” of each bar.
Highest and Lowest Prices:MaxH = highest(Price, Len) MinL = lowest(Price, Len)
MaxH
: Calculates the highest value of the Price
over the period defined by Len
.MinL
: Calculates the lowest value of the Price
over the period defined by Len
.
Value Calculations:value11 = .5 * 2 * ((Price - MinL) / (MaxH - MinL) - .5) value12 = .5 * value11[1] value1 = value11 + value12
value11
scales the difference between the current price and the lowest price in the range relative to the highest price range. This value is rescaled between -0.5
and 0.5
.value12
takes the previous value (value11[1]
) and multiplies it by 0.5
, adding a smoothing effect.value1
is the sum of value11
and value12
, creating a smoothed version of the original calculation.
Clamping Values:value2 = iff(value1 > -.9999 and value1 < .9999, value1, iff(value1 > .9999, .9999, iff(value1 < -.9999, -.9999, value1)))
value2
restricts value1
to the range between -0.9999
and 0.9999
using the iff()
function.
If value1
exceeds 0.9999
, it is clamped to 0.9999
. If it’s less than -0.9999
, it’s clamped to -0.9999
. This ensures that the value stays within the bounds for the Inverse Fisher Transform calculation.
Inverse Fisher Transform Calculation:fish1 = 0.25 * log((1 + value2) / (1 - value2)) fish2 = .5 * fish1[1] fish = fish1 + fish2
fish1
is calculated using the Inverse Fisher Transform formula. This formula is intended to convert data into a more Gaussian-like distribution, making it easier to identify trends.fish2
applies smoothing by taking half of the previous fish1
value.fish
is the smoothed version of the fish1
values.
Plotting:plot(fish, color=red, linewidth=2) plot(fish[1], color=blue, linewidth=1) plot(0)
The final output (fish
) is plotted in red with a line width of 2
.fish[1]
(the previous value of fish
) is plotted in blue with a line width of 1
. This can help visualize trends and crossovers more clearly.plot(0)
adds a horizontal line at 0
for reference, which helps to visually identify positive and negative territories.
Can you show me the Python code?
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import yfinance as yf
from datetime import datetime, timedelta
from flask import Flask, request, render_template, redirect, url_for
import io
import base64
import os
app = Flask(__name__)
# Function to load data from Yahoo Finance
def load_stock_data(ticker, start_date, end_date):
stock = yf.download(ticker, start=start_date, end=end_date)
stock.reset_index(inplace=True)
return stock
# Function to format the ticker for Yahoo Finance
def format_ticker(ticker):
if ticker.isdigit(): # Korean stock ticker
return ticker + “.KS”
return ticker # US or other tickers
@app.route(‘/’)
def index():
return render_template(‘index.html’)
@app.route(‘/analyze’, methods=[‘POST’])
def analyze():
ticker = request.form[‘ticker’]
ticker = format_ticker(ticker)
end_date = datetime.now()
start_date = end_date – timedelta(days=200)
data = load_stock_data(ticker, start_date.strftime(‘%Y-%m-%d’), end_date.strftime(‘%Y-%m-%d’))
if data.empty:
return render_template(‘index.html’, error=”No data found for the given ticker. Please try again.”)
# Calculate Price as the average of High and Low
data[‘Price’] = (data[‘High’] + data[‘Low’]) / 2
# Input length
Len = 10
# Calculate MaxH and MinL for each rolling window of ‘Len’
data[‘MaxH’] = data[‘Price’].rolling(window=Len).max()
data[‘MinL’] = data[‘Price’].rolling(window=Len).min()
# Calculate value11 and value1
data[‘value11’] = 0.5 * 2 * ((data[‘Price’] – data[‘MinL’]) / (data[‘MaxH’] – data[‘MinL’]) – 0.5)
data[‘value12’] = 0.5 * data[‘value11’].shift(1)
data[‘value1’] = data[‘value11’] + data[‘value12’]
# Clamp value1 between -0.9999 and 0.9999
data[‘value2’] = data[‘value1’].apply(lambda x: min(max(x, -0.9999), 0.9999))
# Calculate Inverse Fisher Transform
data[‘fish1’] = 0.25 * np.log((1 + data[‘value2’]) / (1 – data[‘value2’]))
data[‘fish2’] = 0.5 * data[‘fish1’].shift(1)
data[‘fish’] = data[‘fish1’] + data[‘fish2’]
# Print recent 10 days of ‘fish’ values
recent_fish = data[[‘Date’, ‘fish’]].tail(10)
recent_fish[‘Date’] = recent_fish[‘Date’].dt.strftime(‘%Y-%m-%d’) # Convert Date to string for HTML rendering
print(“Recent 10 days of ‘fish’ values:”)
print(recent_fish)
# Plotting the results
plt.figure(figsize=(10, 5))
plt.plot(data[‘Date’], data[‘fish’], color=’red’, linewidth=2, label=’Fish’)
plt.plot(data[‘Date’], data[‘fish’].shift(1), color=’blue’, linewidth=1, label=’Fish (Previous)’)
plt.axhline(0, color=’black’, linestyle=’–‘)
plt.legend()
plt.title(‘Inverse Fisher Transform on High Low’)
# Save plot to a PNG image and encode it to base64
img = io.BytesIO()
plt.savefig(img, format=’png’)
img.seek(0)
plot_url = base64.b64encode(img.getvalue()).decode()
plt.close()
return render_template(‘result.html’, plot_url=plot_url, recent_fish=recent_fish.to_html(index=False, classes=’table table-striped’))
if __name__ == “__main__”:
port = int(os.environ.get(‘PORT’, 5000))
app.run(host=’0.0.0.0′, port=port, debug=False)