# Kairi Relative Index Indicator for ThinkorSwim

#### BenTen

Staff member
Staff
VIP
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

Code:
``````# Kairi Relative Index Leading Indicator
# Assembled by BenTen at useThinkScript.com

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);``````

Yes. Simple.

@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

Here you go @skynetgen:

Ruby:
``````#FloatFLLine - Updated P&L to include additional stats label.
#Updated 2019.10.20 - diazlaz - Additional Stats Label
#                             - Incorporated Nube's and JQ's BnH Logic
#

declare lower;

input ProfileLine = 1200;
input ProfileDesc = "T";
input ShowShareCount = No;

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

plot TargetLine = ProfileLine;
TargetLine.SetDefaultColor(Color.YELLOW);
TargetLine.SetLineWeight(3);

FPL.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
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"));
ZeroLine.SetDefaultColor(Color.GRAY);

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, "Low: " + LowestAll(FPL), Color.Pink);
AddLabel (yes, "Max: " + HighestAll(FPL), Color.Lime);

#end of FloatFLLine``````

What is beautiful about this concept is, BNF used similar strategy to make over \$400 Million starting with just \$6k or so. Who knows how many times he blew up, if he did, if its all true. But, this explains the concept of moving averages and their deviations from the mean.

What is beautiful about this concept is, BNF used similar strategy to make over \$400 Million starting with just \$6k or so. Who knows how many times he blew up, if he did, if its all true. But, this explains the concept of moving averages and their deviations from the mean.
If someone made this much from one technical indicator it would never go public. If it did that means the indicator is no longer that reliable and has lost its accuracy. Indicators lose their relevance once more people start to use them. There's a study that back tested many popular indicators and all of them performed below the buy and hold strategy meaning they give no edge. The only proven edge you can have with any indicator is finding its optimal parameters which is backed up by a study which tested the default setting of the MACD and the optimal parameters. The 2nd one outperformed the market.

87k+ Posts
186 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?