RSI IFT (Inverse Fisher Transform) For ThinkOrSwim

cos251

Well-known member
Sharing this version of the RSI Inverse Fisher Transform - Inverse of arctanh(x). If this was previously posted, my apologies. I searched and did not find a copy other than the one I shared to be included on a different indicator.

This RSI IFT gives buy and sell signals (although the sell signals are a little late). This can be used stand alone or with other indicators to add additional confirmation in either direction.

Of course, feel free to modify as you wish.

KMnErKV.png


Quick Notes
  1. Calculation is based on 5 period RSI then an average
  2. Candle color option is included and takes into account if instrument is in a squeeze or not
    1. On/off setting
Reference Material
https://www.mesasoftware.com/papers/TheInverseFisherTransform.pdf
https://www.mql5.com/en/articles/303


Ruby:
# RSI_IFT (smoothed Inverse Fisher Transform RSI)
# Change Log
#
# 2022.01.25    v1.1    @cos251    -    Added .01 multiplier per proper forumat; pointed out by @bigboss
#
# 2021.01.29    v1.0    @cos251    -    Intial Script; takes smoothed 5 period RSI and puts it #                                       through Inverse arctanh(x) forumla
#
#CREDITS
# - https://www.mesasoftware.com/papers/TheInverseFisherTransform.pdf
# - https://www.mql5.com/en/articles/303

declare lower;

#--- Inputs
input useMultiplier = no;
input length = 5;
def over_Bought = .5;
def over_Sold = -.5;
input paintbars = no;
input showVerticalLines = yes;
input audibleAlerts = yes;
#--- End Inputs


#--- RSI and Smoothed Inverse RSI Calculation
def R =if useMultiplier then (reference RSI(length, close) - 50) * .1 else (reference RSI(length, close) - 50);
def AvgRSI = MovingAverage(AverageType.Exponential,R,9);
def iRSI = (Power(Double.E, 2 * AvgRSI) - 1) / (Power(Double.E, 2 * AvgRSI) + 1);
plot Inverse_RSI = iRSI;
#AddLabel(yes,iRSI);
Inverse_RSI.SetDefaultColor(Color.DARK_GRAY);
Inverse_RSI.AssignValueColor(if Inverse_RSI > .5 then Color.GREEN else if Inverse_RSI < -.5 then Color.RED else Color.Current);
#--- End RSI and Smoothed Calculation


#--- OB/OS
plot ob = over_Bought;
plot os = over_Sold;
ob.SetDefaultColor(Color.DARK_GRAY);
os.SetDefaultColor(Color.DARK_GRAY);
#--- End OB/OS

#--- Add VerticalLine
def sqzAlert = reference TTM_Squeeze().SqueezeAlert; #Hint -Used for candle price color
AddVerticalLine(showVerticalLines and (iRSI > 0) and (iRSI[1] < 0), "Entry BUY", Color.GRAY);
AddVerticalLine(showVerticalLines and (iRSI[1] > 0) and (iRSI < 0), "Entry SELL", Color.YELLOW);
AssignPriceColor(if paintbars and iRSI > 0 and sqzAlert == 1 then Color.GREEN else if paintbars and iRSI < 0 and sqzAlert == 1 then Color.RED else if paintbars and sqzAlert == 0 then Color.GRAY else Color.Current);


Alert(audibleAlerts and (iRSI > 0) and (iRSI[1] < 0), "Buy", Alert.BAR, Sound.Chimes);
Alert(audibleAlerts and (iRSI[1] > 0) and (iRSI < 0), "Sell", Alert.BAR, Sound.Ding);



UPDATE!!!!!!!!!!
Upper Strategy Indicator v1.0

Per request - here is a strategy version of the RSI_IFT. I've included the following
  1. Selection between
    1. Long trade
    2. Short trade
  2. Price bar color per trade selection
    1. Green for long or both
    2. Red for short or both
  3. Vertical Lines for RSI_IFT Signal for visual effect

Please remember to save as a strategy and not study!

Thx!

O7Tc812.jpg


Ruby:
# RSI_IFT_Strat (smoothed Inverse Fisher Transform RSI)
# Change Log
# 2021.08.20    v1.0    @cos251    -    Intial Script; takes smoothed 5 period RSI and puts it #
#                                       through Inverse arctanh(x) forumla; converted to strategy for
#                                       back testing purposes
#
# Removing the header credits and description is not permitted, any modification needs to be shared.
#
#CREDITS
# - https://www.mesasoftware.com/papers/TheInverseFisherTransform.pdf
# - https://www.mql5.com/en/articles/303

declare upper;

#--- Inputs
input length = 5;
input tradetype = { default "long", "short", "both" };
input paintbars = yes;
input showVerticalLines = yes;
#--- End Inputs


#--- RSI and Smoothed Inverse RSI Calculation
def R = reference RSI(length, close) - 50;
def AvgRSI = MovingAverage(AverageType.Exponential,R,9);
def iRSI = (Power(Double.E, 2 * AvgRSI) - 1) / (Power(Double.E, 2 * AvgRSI) + 1);
def Inverse_RSI = iRSI;
#--- End RSI and Smoothed Calculation

#--- Add VerticalLine
def sqzAlert = reference TTM_Squeeze().SqueezeAlert; #Hint -Used for candle price color
# and sqzAlert == 1
AddVerticalLine(showVerticalLines and (tradetype == tradetype.long or tradetype == tradetype.both) and (iRSI > 0) and (iRSI[1] < 0), "Entry BUY", Color.GRAY);
AddVerticalLine(showVerticalLines and (tradetype == tradetype.short or tradetype == tradetype.both) and (iRSI[1] > 0) and (iRSI < 0), "Entry SELL", Color.YELLOW);
AssignPriceColor(if paintbars and (tradetype == tradetype.long or tradetype == tradetype.both) and iRSI > 0  then Color.GREEN else if paintbars and (tradetype == tradetype.short or tradetype == tradetype.both) and iRSI < 0 then Color.RED else if paintbars  then Color.GRAY else Color.Current);


AddOrder(OrderType.BUY_TO_OPEN, iRSI > 0 and iRSI[1] < 0 and (tradetype == tradetype.long or tradetype == tradetype.both), open, tickcolor = GetColor(9), arrowcolor = GetColor(9), name = "LONG");
AddOrder(OrderType.SELL_TO_CLOSE, iRSI < 0 and iRSI[1] > 0 and (tradetype == tradetype.long or tradetype == tradetype.both),open, tickcolor = GetColor(9), arrowcolor = GetColor(9), name = "LONG_EXIT");

AddOrder(OrderType.SELL_TO_OPEN,iRSI < 0 and iRSI[1] > 0 and (tradetype == tradetype.short or tradetype == tradetype.both),open, tickcolor = GetColor(8), arrowcolor = GetColor(8), name = "SHORT" );
AddOrder(OrderType.BUY_TO_CLOSE, iRSI > 0 and iRSI[1] < 0 and (tradetype == tradetype.short or tradetype == tradetype.both),open, tickcolor = GetColor(8), arrowcolor = GetColor(8), name = "SHORT_EXIT");
 
Last edited:
Had this from long ago. Just a different presentation. Cross zero or color change for signals. Red/green OS/OB
Code:
declare lower;

def e = 2.318281828;
input length = 10;
def overbought = 0.7;
def oversold = -0.7;

def diff = if close > close[1] then close - close[1] else 0;
def diff2 = if close < close[1] then close[1] - close else 0;

rec avg = compoundValue(1, 2 / (length + 1) * diff + (length - 1) / (length + 1) * avg[1], diff * 2 / (length + 1));
rec avg2 = compoundValue(1, 2 / (length + 1) * diff2 + (length - 1) / (length + 1) * avg2[1], diff2 * 2 / (length + 1));

def value = if avg2 != 0 then 100 - 100 / (1 + avg / avg2) else 0;
def Value1 = 0.1 * (value - 50);
def Value2 = wma(Value1, 9);
def IFish = (Power(e, (2 * Value2)) - 1) / (Power(e, (2 * Value2)) + 1 );

plot plot2 = 0.7;
plot plot3 = -0.7;
plot zero = 0;

Plot plot1 = IFish;
plot1.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
plot1.SetLineWeight(2);
#plot1.DefineColor("Up", Color.UPTICK);
#plot1.DefineColor("Down", Color.DOWNTICK);
#plot1.AssignValueColor(if plot1 > plot1[1] then plot1.color("Up") else if plot1 < plot1[1] then #plot1.color("Down") else GetColor(1));

plot1.DefineColor("OverBought", Color.dark_green);
plot1.DefineColor("Normalpos", Color.dark_orange);
plot1.DefineColor("Normalneg", Color.dark_orange);
plot1.DefineColor("OverSold", Color.dark_red);
plot1.AssignValueColor(if plot1 > overBought then plot1.color("OverBought") else if plot1 < overSold then plot1.color("OverSold") else if plot1 < 0.5 then plot1.color("Normalneg") else plot1.color("Normalpos"));
 
Very nice touch, I like the adjustment. Makes for a safer signal and helps align with other indicators.
I saw tsla got sell signal at 5:58 am "west coast time" premarket and buy signal at 8:54am . Wow I would have been " I'm Rich *****" day lol.
 
Had this from long ago. Just a different presentation. Cross zero or color change for signals. Red/green OS/OB
Code:
declare lower;

def e = 2.318281828;
input length = 10;
def overbought = 0.7;
def oversold = -0.7;

def diff = if close > close[1] then close - close[1] else 0;
def diff2 = if close < close[1] then close[1] - close else 0;

rec avg = compoundValue(1, 2 / (length + 1) * diff + (length - 1) / (length + 1) * avg[1], diff * 2 / (length + 1));
rec avg2 = compoundValue(1, 2 / (length + 1) * diff2 + (length - 1) / (length + 1) * avg2[1], diff2 * 2 / (length + 1));

def value = if avg2 != 0 then 100 - 100 / (1 + avg / avg2) else 0;
def Value1 = 0.1 * (value - 50);
def Value2 = wma(Value1, 9);
def IFish = (Power(e, (2 * Value2)) - 1) / (Power(e, (2 * Value2)) + 1 );

plot plot2 = 0.7;
plot plot3 = -0.7;
plot zero = 0;

Plot plot1 = IFish;
plot1.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
plot1.SetLineWeight(2);
#plot1.DefineColor("Up", Color.UPTICK);
#plot1.DefineColor("Down", Color.DOWNTICK);
#plot1.AssignValueColor(if plot1 > plot1[1] then plot1.color("Up") else if plot1 < plot1[1] then #plot1.color("Down") else GetColor(1));

plot1.DefineColor("OverBought", Color.dark_green);
plot1.DefineColor("Normalpos", Color.dark_orange);
plot1.DefineColor("Normalneg", Color.dark_orange);
plot1.DefineColor("OverSold", Color.dark_red);
plot1.AssignValueColor(if plot1 > overBought then plot1.color("OverBought") else if plot1 < overSold then plot1.color("OverSold") else if plot1 < 0.5 then plot1.color("Normalneg") else plot1.color("Normalpos"));
Thanks for sharing @horserider. This provides good anticipation to change in direction.
 
Sharing this version of the RSI Inverse Fisher Transform - Inverse of arctanh(x). If this was previously posted, my apologies. I searched and did not find a copy other than the one I shared to be included on a different indicator.

This RSI IFT gives buy and sell signals (although the sell signals are a little late). This can be used stand alone or with other indicators to add additional confirmation in either direction.

Of course, feel free to modify as you wish.

KMnErKV.png


Quick Notes
  1. Calculation is based on 5 period RSI then an average
  2. Candle color option is included and takes into account if instrument is in a squeeze or not
    1. On/off setting
Reference Material
https://www.mesasoftware.com/papers/TheInverseFisherTransform.pdf
https://www.mql5.com/en/articles/303


Code:
# RSI_IFT (smoothed Inverse Fisher Transform RSI)
# Change Log
# 2021.01.29    v1.0    @cos251    -    Intial Script; takes smoothed 5 period RSI and puts it #                                       through Inverse arctanh(x) forumla
#
#CREDITS
# - https://www.mesasoftware.com/papers/TheInverseFisherTransform.pdf
# - https://www.mql5.com/en/articles/303

declare lower;

#--- Inputs
input length = 5;
def over_Bought = .5;
def over_Sold = -.5;
input paintbars = no;
input showVerticalLines = yes;
#--- End Inputs


#--- RSI and Smoothed Inverse RSI Calculation
def R = reference RSI(length, close) - 50;
def AvgRSI = MovingAverage(AverageType.Exponential,R,9);
def iRSI = (Power(Double.E, 2 * AvgRSI) - 1) / (Power(Double.E, 2 * AvgRSI) + 1);
plot Inverse_RSI = iRSI;
#AddLabel(yes,iRSI);
Inverse_RSI.SetDefaultColor(Color.DARK_GRAY);
Inverse_RSI.AssignValueColor(if Inverse_RSI > .5 then Color.GREEN else if Inverse_RSI < -.5 then Color.RED else Color.Current);
#--- End RSI and Smoothed Calculation


#--- OB/OS
plot ob = over_Bought;
plot os = over_Sold;
ob.SetDefaultColor(Color.DARK_GRAY);
os.SetDefaultColor(Color.DARK_GRAY);
#--- End OB/OS

#--- Add VerticalLine
def sqzAlert = reference TTM_Squeeze().SqueezeAlert; #Hint -Used for candle price color
AddVerticalLine(showVerticalLines and (iRSI > 0) and (iRSI[1] < 0), "Entry BUY", Color.GRAY);
AddVerticalLine(showVerticalLines and (iRSI[1] > 0) and (iRSI < 0), "Entry SELL", Color.YELLOW);
AssignPriceColor(if paintbars and iRSI > 0 and sqzAlert == 1 then Color.GREEN else if paintbars and iRSI < 0 and sqzAlert == 1 then Color.RED else if paintbars and sqzAlert == 0 then Color.GRAY else Color.Current);
Very interesting! How do you add a P&L report to this in order to backtest strategy?
Thank you in advance!
 
The lines of code you added will add the basic components of the P&L. It will produce the buy/sell signals, initiate a trade (on chart only that is) and close the trade based on your conditions. Then what you do is right click the buy or sell order and select Show Report (I think that is what it is called). And it will show you a report of the mock, back tested trades. YOu can also add the default P&L indicator to the lower chart area.
 
The lines of code you added will add the basic components of the P&L. It will produce the buy/sell signals, initiate a trade (on chart only that is) and close the trade based on your conditions. Then what you do is right click the buy or sell order and select Show Report (I think that is what it is called). And it will show you a report of the mock, back tested trades. YOu can also add the default P&L indicator to the lower chart area.
when I add those lines of code to strategy it deletes the signal from chart even though I mirrored the instructions, as well as moving code to strategy section. Any ideas?

Thank you in advance!
 
Sharing this version of the RSI Inverse Fisher Transform - Inverse of arctanh(x). If this was previously posted, my apologies. I searched and did not find a copy other than the one I shared to be included on a different indicator.

This RSI IFT gives buy and sell signals (although the sell signals are a little late). This can be used stand alone or with other indicators to add additional confirmation in either direction.

Of course, feel free to modify as you wish.

KMnErKV.png


Quick Notes
  1. Calculation is based on 5 period RSI then an average
  2. Candle color option is included and takes into account if instrument is in a squeeze or not
    1. On/off setting
Reference Material
https://www.mesasoftware.com/papers/TheInverseFisherTransform.pdf
https://www.mql5.com/en/articles/303


Code:
# RSI_IFT (smoothed Inverse Fisher Transform RSI)
# Change Log
# 2021.01.29    v1.0    @cos251    -    Intial Script; takes smoothed 5 period RSI and puts it #                                       through Inverse arctanh(x) forumla
#
#CREDITS
# - https://www.mesasoftware.com/papers/TheInverseFisherTransform.pdf
# - https://www.mql5.com/en/articles/303

declare lower;

#--- Inputs
input length = 5;
def over_Bought = .5;
def over_Sold = -.5;
input paintbars = no;
input showVerticalLines = yes;
#--- End Inputs


#--- RSI and Smoothed Inverse RSI Calculation
def R = reference RSI(length, close) - 50;
def AvgRSI = MovingAverage(AverageType.Exponential,R,9);
def iRSI = (Power(Double.E, 2 * AvgRSI) - 1) / (Power(Double.E, 2 * AvgRSI) + 1);
plot Inverse_RSI = iRSI;
#AddLabel(yes,iRSI);
Inverse_RSI.SetDefaultColor(Color.DARK_GRAY);
Inverse_RSI.AssignValueColor(if Inverse_RSI > .5 then Color.GREEN else if Inverse_RSI < -.5 then Color.RED else Color.Current);
#--- End RSI and Smoothed Calculation


#--- OB/OS
plot ob = over_Bought;
plot os = over_Sold;
ob.SetDefaultColor(Color.DARK_GRAY);
os.SetDefaultColor(Color.DARK_GRAY);
#--- End OB/OS

#--- Add VerticalLine
def sqzAlert = reference TTM_Squeeze().SqueezeAlert; #Hint -Used for candle price color
AddVerticalLine(showVerticalLines and (iRSI > 0) and (iRSI[1] < 0), "Entry BUY", Color.GRAY);
AddVerticalLine(showVerticalLines and (iRSI[1] > 0) and (iRSI < 0), "Entry SELL", Color.YELLOW);
AssignPriceColor(if paintbars and iRSI > 0 and sqzAlert == 1 then Color.GREEN else if paintbars and iRSI < 0 and sqzAlert == 1 then Color.RED else if paintbars and sqzAlert == 0 then Color.GRAY else Color.Current);



UPDATE!!!!!!!!!!
Upper Strategy Indicator v1.0

Per request - here is a strategy version of the RSI_IFT. I've included the following
  1. Selection between
    1. Long trade
    2. Short trade
  2. Price bar color per trade selection
    1. Green for long or both
    2. Red for short or both
  3. Vertical Lines for RSI_IFT Signal for visual effect
Thx!

O7Tc812.jpg


Ruby:
# RSI_IFT_Strat (smoothed Inverse Fisher Transform RSI)
# Change Log
# 2021.08.20    v1.0    @cos251    -    Intial Script; takes smoothed 5 period RSI and puts it #
#                                       through Inverse arctanh(x) forumla; converted to strategy for
#                                       back testing purposes
#
# Removing the header credits and description is not permitted, any modification needs to be shared.
#
#CREDITS
# - https://www.mesasoftware.com/papers/TheInverseFisherTransform.pdf
# - https://www.mql5.com/en/articles/303

declare upper;

#--- Inputs
input length = 5;
input tradetype = { default "long", "short", "both" };
input paintbars = yes;
input showVerticalLines = yes;
#--- End Inputs


#--- RSI and Smoothed Inverse RSI Calculation
def R = reference RSI(length, close) - 50;
def AvgRSI = MovingAverage(AverageType.Exponential,R,9);
def iRSI = (Power(Double.E, 2 * AvgRSI) - 1) / (Power(Double.E, 2 * AvgRSI) + 1);
def Inverse_RSI = iRSI;
#--- End RSI and Smoothed Calculation

#--- Add VerticalLine
def sqzAlert = reference TTM_Squeeze().SqueezeAlert; #Hint -Used for candle price color
# and sqzAlert == 1
AddVerticalLine(showVerticalLines and (tradetype == tradetype.long or tradetype == tradetype.both) and (iRSI > 0) and (iRSI[1] < 0), "Entry BUY", Color.GRAY);
AddVerticalLine(showVerticalLines and (tradetype == tradetype.short or tradetype == tradetype.both) and (iRSI[1] > 0) and (iRSI < 0), "Entry SELL", Color.YELLOW);
AssignPriceColor(if paintbars and (tradetype == tradetype.long or tradetype == tradetype.both) and iRSI > 0  then Color.GREEN else if paintbars and (tradetype == tradetype.short or tradetype == tradetype.both) and iRSI < 0 then Color.RED else if paintbars  then Color.GRAY else Color.Current);


AddOrder(OrderType.BUY_TO_OPEN, iRSI > 0 and iRSI[1] < 0 and (tradetype == tradetype.long or tradetype == tradetype.both), open, tickcolor = GetColor(9), arrowcolor = GetColor(9), name = "LONG");
AddOrder(OrderType.SELL_TO_CLOSE, iRSI < 0 and iRSI[1] > 0 and (tradetype == tradetype.long or tradetype == tradetype.both),open, tickcolor = GetColor(9), arrowcolor = GetColor(9), name = "LONG_EXIT");

AddOrder(OrderType.SELL_TO_OPEN,iRSI < 0 and iRSI[1] > 0 and (tradetype == tradetype.short or tradetype == tradetype.both),open, tickcolor = GetColor(8), arrowcolor = GetColor(8), name = "SHORT" );
AddOrder(OrderType.BUY_TO_CLOSE, iRSI > 0 and iRSI[1] < 0 and (tradetype == tradetype.short or tradetype == tradetype.both),open, tickcolor = GetColor(8), arrowcolor = GetColor(8), name = "SHORT_EXIT");
Hey thx for this! Also i like the way you have volume setup in the first pic- care to share code?
 
The volume color coding to match the candles is a result of the AssignPriceColor function in the first indicator. It will color the volume bars by default.
 
good morning
i am new here.
can you help me with the upper chart
UPDATE!!!!!!!!!!
Upper Strategy Indicator v1.0
some how i cant put it on but on the let corner it said the strategy is applied but other than that i dont see anything else.

no line, not anything.

but your lower study works great.

thanks
 
Last edited by a moderator:
good morning
i am new here.
can you help me with the upper chart

When you create strategy you have to save it as strategy and not study.
Instead of study click the middle button which says strategy. Then click create and save your script . Hope this helps
 
Last edited by a moderator:
@Superfast The code does not indicate anything that would cause repainting.
Be aware that the delay in the signal of loss of momentum, while not unusual in this type of indicator, does tend to give back profits which can be significant in a volatile market and result in a loss. No indicator should be used in isolation.
 
Last edited:
Thanks, I'm looking at what indicators would work best with this. If it's a momentum indicator/strategy, it could be good to pair it with a volatility indicator (squeeze) or vix/vx indicator or something of the sort. There's the trendreversal indicator which repaints hence the reason I was asking about this one. Thanks again, please feel free to add anything else that may help.
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
378 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top