Kairi Relative Index Indicator for ThinkorSwim


Staff member
The Kairi Relative Index is a metric that traders use to to time their purchases of a stock, or to understand trends in the stock market.

A momentum oscillator measures the strength of the up or down movement of price instead of the actual price level. The harder and faster a tradable's price falls, the bigger the oscillator move. The same goes for an upward move. Once the price move slows down, so does the momentum oscillator.


thinkScript Code

# Kairi Relative Index Leading Indicator
# Assembled by BenTen at useThinkScript.com
# Converted from https://www.tradingview.com/script/2viDaDnF-Kairi-Relative-Index/

declare lower;

input length = 100;
input src = close;

def sma = simpleMovingAvg(src, length);
def kri = 100 * (src - sma) / sma;

plot ZeroLine = 0;
plot line = kri;

line.AssignValueColor(if kri > 0 then color.green else color.red);

A few resources to help you understand more about this indicator:


Well-known member
@diazlaz Mind sharing this PNL study you are using? I just started playing with backtesting with strategies and find the default PNL study solely lacking


Well-known member
2019 Donor
Here you go @skynetgen:

#FloatFLLine - Updated P&L to include additional stats label.
#Original TD Ameritrade - FloatingPL
#Updated 2019.10.20 - diazlaz - Additional Stats Label
#                             - Incorporated Nube's and JQ's BnH Logic

declare lower;

input ProfileLine = 1200;
input TradeSize = 1000;
input TradeAmount = 100000;
input useTradeAmount = no;
input ProfileDesc = "T";
input ShowShareCount = No;

AddLabel(yes, ProfileDesc, COLOR.ORANGE);

def TradeSize2 = CompoundValue(1, Round(TradeAmount / close, 0), 0);
AddLabel(ShowShareCount, "Number Of Shares: " +  if useTradeAmount then astext(TradeSize2) else astext(TradeSize) + " at " + AsText(close), Color.WHITE);

plot FPL = FPL();
plot ZeroLine = 0;

plot TargetLine = ProfileLine;

FPL.DefineColor("Positive and Up", Color.GREEN);
FPL.DefineColor("Positive and Down", Color.DARK_GREEN);
FPL.DefineColor("Negative and Down", Color.RED);
FPL.DefineColor("Negative and Up", Color.DARK_RED);
FPL.AssignValueColor(if FPL >= 0 then if FPL > FPL[1] then FPL.Color("Positive and Up") else FPL.Color("Positive and Down") else if FPL < FPL[1] then FPL.Color("Negative and Down") else FPL.Color("Negative and Up"));

def ProfitState = CompoundValue(1, if FPL >= ProfileLine then 1 else ProfitState[1], 0);
def ProfitCount = CompoundValue(1, if FPL >= ProfileLine then ProfitCount[1] + 1 else ProfitCount[1], 0);
plot pLongBuy = (ProfitState[1] != ProfitState);

def BnH = close - First(open);
def returnColor = if BnH crosses above BnH[1] then 1 else
                  if BnH crosses below BnH[1] then 0 else returnColor[1];
def BHPnL = TickValue() * (1 / TickSize()) * BnH;

AddLabel (yes, "Profit Touch: " + ProfitCount, Color.YELLOW);
AddLabel (yes, "P&L: " + AsDollars(FPL),
if FPL >= 0 then if FPL > FPL[1] then FPL.Color("Positive and Up") else FPL.Color("Positive and Down") else if FPL < FPL[1] then FPL.Color("Negative and Down") else FPL.Color("Negative and Up"));

AddLabel (yes, "%: " + AsPercent(FPL / TradeAmount), Color.CYAN);
AddLabel (yes, "Low: " + LowestAll(FPL), Color.Pink);
AddLabel (yes, "Max: " + HighestAll(FPL), Color.Lime);
AddLabel (yes, "Buy and Hold PL: " + AsDollars(BHPnL * TradeSize), Color.Gray);
AddLabel (yes, "BH%: " + AsPercent(BHPnL / TradeAmount), Color.Gray);

#end of FloatFLLine

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.