Kairi Relative Index Indicator for ThinkorSwim

BenTen

BenTen

Administrative
Staff
VIP
Warehouse
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
# 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:
 
D

diazlaz

Well-known member
VIP
Warehouse
beautiful and simple one of my favorites so far Ben!
 
S

skynetgen

Active member
Warehouse
@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
 
D

diazlaz

Well-known member
VIP
Warehouse
Here you go @skynetgen:

Ruby:
#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;
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);
pLongBuy.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
pLongBuy.SetDefaultColor(Color.WHITE);
pLongBuy.SetLineWeight(5);

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
 
P

princesly

New member
Warehouse
@diazlaz FYI, I just this the labels show up but not the kairi indicator plot. I tried merging both to no avail.
 

Top