Repaints Trend Friend Chart Setup For ThinkOrSwim

Repaints

nerdytrader

New member
Image of the Trend Friend Indicator

https://drive.google.com/file/d/1dTt8SRW4USeIi8eGuzGIMW3LYze6uNUO/view?usp=sharing

https://drive.google.com/file/d/1YX9YaG7GB69rb5ZGjjKvmPOkI_qIlRlp/view?usp=sharing



Hello, this will be my first contribution. I by no means take credit for much of the actual script within the study, it is mostly a collection of studies that I have found over time on this forum that I have decided to mold into a upper study that displays all indicators in a way I find to be ultra imsimplictic and easy to interpret visually.

I have always wanted an upper study that is "floating", ie. does not move at all even when you zoom in or zoom out on the chart. It is fixed to the top of the chart and there are 7 main indicators that are displayed as a color changing line, each displayed one below the other in 7 compact lines.

Each line is color coded to be either green (or white) for bullish , red (or magenta) for bearish, or nuetral if applicable. The goal is to have most (or all preferably) of the lines to match bullish or bearish color.

The indicators used are as followed.
-Supertrend (yahoo version)
-A version of RSI
-Regression Ribbon
-MTF TMO
-Fractal RSI
-Geometric Moving Averages
-Trend Reversal

Feel free to tinker with it if you'd like, I'd love to see what you all can add or revise and come up with something exceptional. I have always wanted an upper study that does no move with the chart so I can always see what is changing, that is why I created this. I haven't really seen anything similar. Essentially, it could be a lower study as well, but I wanted it to be on the chart to eliminate the space it takes to add a lower study, so the chart is bigger. Usually when you plot a lower style study on the chart, you'll get a smushed or distorted chart, or the studies will be all over the place and impossible to see or even find. With this study, it stays at the top always, above the candles , out of the way, and never really becomes a nuisance.

Let me know what you think and have a great weekend.


The coding is as followed:


###############################################
################# INPUTS #######################
###############################################

#############################################
########## SUPERTREND INPUTS #################
############## LINE NO. 1 ######################
input YST_AtrMult = 1.00;
input YSTnATR = 6;
input YST_AvgType = AverageType.HULL;
input UseEmaCross = yes;
input YST_EMA1 = 2;
input YST_EMA2 = 20;
###########################################
############## RSI INPUTS ###################
############## LINE NO. 2 ####################
input RSI_PRICE = close;
input RSI_LENGTH = 13;
input RSI_averageType = AverageType.WILDERS;
input showHorRsiLine = yes;
input showAvgRsi = yes;
input RS_avgRsiLength = 3;
input RSI_avgRsiAverageType = AverageType.WILDERS;
#################################################
############ REG RIBBON INPUTS ###################
############## LINE NO. 3 #########################
input REG_PRICE = close;
input REG_DISPLACE = 0;
input REG_LinRegLength = 80;
input REG_EMAlength = 20;
############################################
############# TMO INPUTS ####################
############## LINE NO.4 #####################
input TMO_LENGTH = 14;
input TMO_CALC_LENGTH = 5;
input TMO_SMOOTH_LENGTH = 3;
#################################################
############# GAMMA RSI INPUTS ###################
################ LINE NO.5 ########################
input gamma = .8;
####################################################
########## GEOMETRIC MA INPUTS ######################
############## LINE NO.6 #############################
input GEOprice = CLOSE;
input GEOper = 50;
INPUT GEODISPLACE1 = -.14;
input GEOprice2 = CLOSE;
input GEOper2 = 50;
INPUT GEODISPLACE2 = .14;
input GEOprice3 = CLOSE;
input GEOper3 = 7;
####################################################
########## TREND REVERSAL INPUTS ####################
############## LINE NO.7 #############################
INPUT REV_PRICE = close;
INPUT REV_superfast_length = 9;
INPUT REV_fast_length = 14;
INPUT REV_slow_length = 21;
INPUT REV_DISPLACE = 0;
################################################
####### SUPERTREND TRENDLINE ####################
################################################
def x0 = if(isNaN(close[-1]) and !isNaN(close), barNumber(), x0[1]);
def YST_ATR = ATR("length" = YSTnATR, "average type" = YST_AvgType);
def UP_Band_Basic = HL2 + (YST_AtrMult * YST_ATR);
def LW_Band_Basic = HL2 + (-YST_AtrMult * YST_ATR);
def UP_Band = if ((UP_Band_Basic < UP_Band[1]) or (close[1] > UP_Band[1])) then UP_Band_Basic else UP_Band[1];
def LW_Band = if ((LW_Band_Basic > LW_Band[1]) or (close[1] < LW_Band[1])) then LW_Band_Basic else LW_Band[1];

def ST = if ((ST[1] == UP_Band[1]) and (close < UP_Band)) then UP_Band
else if ((ST[1] == UP_Band[1]) and (close > Up_Band)) then LW_Band
else if ((ST[1] == LW_Band[1]) and (close > LW_Band)) then LW_Band
else if ((ST[1] == LW_Band) and (close < LW_Band)) then UP_Band
else LW_Band;
def EMA1Val = MovAvgExponential(close, YST_EMA1);
def EMA2Val = MovAvgExponential(close, YST_EMA2);
def EMADirection = if EMA1Val > EMA2Val then 1 else if EMA1Val < EMA2Val then -1 else 0;
DEF Long = if close > ST then ST else Double.NaN;
DEF Short = if close < ST then ST else Double.NaN;
DEF YTREND= IF LONG IS TRUE OR SHORT IS TRUE THEN 1 ELSE DOUBLE.NAN;
def LongTrigger = isNaN(Long[1]) and !isNaN(Long);
def ShortTrigger = isNaN(Short[1]) and !isNaN(Short);
DEF LongDot = if LongTrigger then ST else Double.NaN;
DEF ShortDot = if ShortTrigger then ST else Double.NaN;
def LongConfirm = (UseEmaCross and close > ST and EMADirection == 1) or (!UseEmaCross and LongTrigger);
def ShortConfirm = (UseEmaCross and close < ST and EMADirection == -1) or (!UseEmaCross and ShortTrigger);
DEF LongAlert =IF LongConfirm IS TRUE and LongConfirm[1] != LongConfirm IS TRUE THEN 1 ELSE DOUBLE.NAN;
DEF ShortAlert = IF ShortConfirm IS TRUE and ShortConfirm[1] != ShortConfirm IS TRUE THEN 1 ELSE DOUBLE.NAN;
DEF ST_ALERTING = IF LONGALERT IS TRUE THEN 1 OR IF SHORTALERT IS TRUE THEN 1 ELSE DOUBLE.NAN ELSE DOUBLE.NAN;

PLOT YAHOOTREND = YTREND IS TRUE;
YAHOOTREND.SETPaintingStrategy (paintingStrategy.HORIZONTAL);
YAHOOTREND.AssignVALUEColor( IF close < ST and (!UseEmaCross or EMADirection == -1) then Color.RED
else if close > ST and (!UseEmaCross or EMADirection == 1) then Color.GREEN
else COLOR.MAGENTA);
YAHOOTREND.SETLineWeight (5);
###########################################
########## RSI TRENDLINE ####################
###########################################
DEF over_Bought = 70;
DEF over_Sold = 30;
def NetChgAvg = MovingAverage(RSI_averageType, RSI_PRICE - RSI_PRICE[1], RSI_LENGTH);
def TotChgAvg = MovingAverage(RSI_averageType, AbsValue(RSI_PRICE - RSI_PRICE[1]), RSI_LENGTH);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
DEF EXTREME = 50 * (ChgRatio + 1);
DEF OverSold = over_Sold;
DEF OverBought = over_Bought;
DEF UpSignal = if EXTREME <= OverSold then OverSold else Double.NaN;
DEF DownSignal = if EXTREME >= OverBought then OverBought else Double.NaN;
def avgRsi = MovingAverage(RSI_avgRsiAverageType, EXTREME, RS_avgRsiLength) ;
DEF RSI_UP = AVGRSI > AVGRSI[1] IS TRUE OR UPSIGNAL IS TRUE;
DEF RSI_DOWN = AVGRSI < AVGRSI[1] IS TRUE OR DOWNSIGNAL IS TRUE;
DEF RSI_TRENDING = IF RSI_UP IS TRUE OR RSI_DOWN IS TRUE THEN .98 ELSE DOUBLE.NAN;

PLOT EAVGRSI = RSI_TRENDING ;
EavgRsi.AssignValueColor(if avgRsi > avgRsi[1] then COLOR.GREEN else IF avgRsi < avgRsi[1] THEN COLOR.RED ELSE COLOR.GRAY );
EavgRsi.SetPaintingStrategy(PAINtingStrategy.LINE);
EavgRsi.SetLineWeight(5);
##############################################
####### REG RIBBON TRENDLINE ###################
##############################################
def LinReg = Inertia(REG_PRICE[-REG_DISPLACE], REG_LinRegLength);
def EMA_LR = ExpAverage(LinReg[-REG_DISPLACE], REG_EMAlength);
def Body = (open + close)/2;
DEF LR = LinReg;
DEF EMA_LinReg= EMA_LR;
DEF REG_UP = IF EMA_LINREG > LR IS TRUE THEN .96 ELSE DOUBLE.NAN;
DEF REG_DOWN= IF EMA_LINREG < LR IS TRUE THEN .96 ELSE DOUBLE.NAN;
DEF REG_TREND = IF REG_UP IS TRUE OR REG_DOWN IS TRUE THEN .96 ELSE DOUBLE.NAN;

PLOT RIBBON_TREND = REG_TREND ;
RIBBON_TREND.SETPAintingStrategy (PAINtingStrategy.line);
RIBBON_TREND.SETLineWeight (5);
RIBBON_TREND.ASSIGNValueColor (IF EMA_LINREG < LR THEN COLOR.GREEN ELSE COLOR.RED);
###############################################
############# TMO TRENDLINE ####################
###############################################
def o2 = open;
def c2 = close;
def data = fold i = 0 to TMO_LENGTH with s do s + (if c2> GetValue(o2, i) then 2 else if c2 < GetValue(o2, i) then- 1 else 0);
def EMA5 = ExpAverage(data, TMO_CALC_LENGTH);
def Main1 = ExpAverage(EMA5, TMO_CALC_LENGTH);
def signal1 = ExpAverage(Main1, TMO_CALC_LENGTH);
def TMO_UP = IF Main1 > signal1 IS TRUE THEN .94 ELSE DOUBLE.NAN;
def TMO_DOWN = IF Main1 < signal1 IS TRUE THEN .94 ELSE DOUBLE.NAN;
DEF TMO_TRENDING = IF TMO_UP IS TRUE OR TMO_DOWN IS TRUE THEN .94 ELSE DOUBLE.NAN;

plot TMO_TREND = TMO_TRENDING;
TMO_TREND.SetPaintingStrategy (PAINtingStrategy.LINE);
TMO_TREND.AssignValueColor(if Main1 > signal1 then Color.LIME else IF Main1 < signal1 THEN COLOR.RED ELSE COLOR.GRAY);
TMO_TREND.SetLineWeight (5);
#################################################
############# GAMMA RSI TRENDLINE ################
#################################################
def o;def h;def l;def c;def CU1;def CU2;def CU;def CD1;
def CD2;def CD;def L0;def L1;def L2;def L3;

o = (open + close[1]) / 2;
h = Max(high, close[1]);
l = Min(low, close[1]);
c = (o + h + l + close) / 4;

L0 = (1 – gamma) * c + gamma * L0[1];
L1 = -gamma * L0 + L0[1] + gamma * L1[1];
L2 = -gamma * L1 + L1[1] + gamma * L2[1];
L3 = -gamma * L2 + L2[1] + gamma * L3[1];

if L0 >= L1 then {CU1 = L0 - L1; CD1 = 1; } else { CD1 = L1 - L0; CU1 = 1; } if L1 >= L2 then { CU2 = CU1 + L1 - L2; CD2 =CD1; } else { CD2 = CD1 + L2 - L1; CU2 = CU1; } if L2 >= L3 Then { CU = CU2 + L2 - L3; CD = CD2; } else { CU = CU2; CD = CD2 + L3 - L2; }

def G_RSI = if CU + CD <> 0 then CU / (CU + CD) ELSE 1;
DEF GRSI_UP = IF G_RSI > G_RSI[2] IS TRUE THEN .92 ELSE DOUBLE.NAN;
DEF GRSI_DOWN = IF G_RSI < G_RSI[2] IS TRUE THEN .92 ELSE DOUBLE.NAN;
DEF G_RSI_TRENDING= IF GRSI_UP IS TRUE OR GRSI_DOWN IS TRUE THEN .92 ELSE DOUBLE.NAN;

plot GRSI_TREND = G_RSI_TRENDING ;
GRSI_TREND.SetPaintingStrategy (PAINtingStrategy.LINE);
GRSI_TREND.SetLineWeight(5);
GRSI_TREND.AssignValueColor(if G_RSI > G_RSI[2] THEN COLOR.GREEN ELSE COLOR.RED);
################################################################
################## GEOMETRIC MA TRENDLINE #######################
################################################################
def lmean = log(GEOprice) ;
def smean = sum(lmean,GEOper) ;
def gma = exp(smean/GEOper)-GEODISPLACE1 ;
def lmean2 = log(GEOprice2) ;
def smean2 = sum(lmean2,GEOper2) ;
def gma2 = exp(smean2/GEOper2)-GEODISPLACE2 ;
def lmean3= log(GEOprice3) ;
def smean3= sum(lmean3,GEOper3) ;
def gma3= exp(smean3/GEOper3) ;

DEF pGMA = gma ;
DEF pGMA2 = gma2;
DEF pGMA3 = gma3;
DEF GEOTREND = IF PGMA3 > PGMA2 IS TRUE THEN .9 ELSE .9;

PLOT TRENDGEO = GEOTREND ;
TRENDGEO.SETPAintingStrategy (PAINTingStrategy.LINE);
TRENDGEO.ASSIGNValueColor (IF PGMA3 > PGMA2 OR PGMA3 > PGMA THEN COLOR.GREEN ELSE COLOR.RED);
TRENDGEO.SETLineWeight (5);
##############################################
########### REVERSAL TRENDLINE #################
##############################################
def mov_avg9 = ExpAverage(REV_PRICE[-REV_DISPLACE], REV_superfast_length);
def mov_avg14 = ExpAverage(REV_PRICE[-REV_DISPLACE], REV_fast_length);
def mov_avg21 = ExpAverage(REV_PRICE[-REV_DISPLACE], REV_slow_length);
def Superfast = mov_avg9;
def Fast = mov_avg14;
def Slow = mov_avg21;
def buy = mov_avg9 > mov_avg14 and mov_avg14 > mov_avg21 and low > mov_avg9;
def stopbuy = mov_avg9 <= mov_avg14;
def buynow = !buy[1] and buy;
def buysignal = CompoundValue(1, if buynow and !stopbuy then 1 else if buysignal[1] == 1 and stopbuy then 0 else buysignal[1], 0);
def Buy_Signal = buysignal[1] == 0 and buysignal == 1;
def Momentum_Down = buysignal[1] == 1 and buysignal == 0;
def sell = mov_avg9 < mov_avg14 and mov_avg14 < mov_avg21 and high < mov_avg9;
def stopsell = mov_avg9 >= mov_avg14;
def sellnow = !sell[1] and sell;
def sellsignal = CompoundValue(1, if sellnow and !stopsell then 1 else if sellsignal[1] == 1 and stopsell then 0 else sellsignal[1], 0);
def Sell_Signal = sellsignal[1] == 0 and sellsignal;

input REV_method = {default average, high_low};
def bubbleoffset = .0005;
def percentamount = .01;
def revAmount = .05;
def atrreversal = 2.0;
def atrlength = 5;
def pricehigh = high;
def pricelow = low;
def averagelength = 5;
def averagetype = AverageType.EXPONENTIAL;
def mah = MovingAverage(averagetype, pricehigh, averagelength);
def mal = MovingAverage(averagetype, pricelow, averagelength);
def priceh = if REV_method == REV_method.high_low then pricehigh else mah;
def pricel = if REV_method == REV_method.high_low then pricelow else mal;
def EI = ZigZagHighLow("price h" = priceh, "price l" = pricel, "percentage reversal" = percentamount, "absolute reversal" = revAmount, "atr length" = atrlength, "atr reversal" = atrreversal);
rec EISave = if !IsNaN(EI) then EI else GetValue(EISave, 1);
def chg = (if EISave == priceh then priceh else pricel) - GetValue(EISave, 1);
def isUp = chg >= 0;
def EIL = if !IsNaN(EI) and !isUp then pricel else GetValue(EIL, 1);
def EIH = if !IsNaN(EI) and isUp then priceh else GetValue(EIH, 1);
def dir = CompoundValue(1, if EIL != EIL[1] or pricel == EIL[1] and pricel == EISave then 1 else if EIH != EIH[1] or priceh == EIH[1] and priceh == EISave then -1 else dir[1], 0);
def signal = CompoundValue(1, if dir > 0 and pricel > EIL then if signal[1] <= 0 then 1 else signal[1] else if dir < 0 and priceh < EIH then if signal[1] >= 0 then -1 else signal[1] else signal[1], 0);

DEF bullish2 = signal > 0 and signal[1] <= 0 IS TRUE;
def bearish2 = signal < 0 and signal[1] >= 0 IS TRUE;
DEF TRENDINGREVERSAL = IF BULLISH2 IS TRUE OR BEARISH2 IS TRUE THEN .88 ELSE .88;
DEF TRENDREV = IF TRENDINGREVERSAL IS TRUE THEN .88 ELSE .88;

PLOT REV= IF TRENDREV IS TRUE THEN .88 ELSE .88;
REV.SETPaintingStrategy (PAINtingStrategy.LINE);
REV.ASSIGNValueColor(IF BULLISH2 THEN COLOR.GREEN ELSE IF BEARISH2 THEN COLOR.RED ELSE COLOR.GRAY);
REV.SETLineWeight (5);

DEF BULL =IF BULLISH2 IS TRUE THEN .88 ELSE DOUBLE.NAN;
DEF BEAR = IF BEARISH2 IS TRUE THEN .88 ELSE DOUBLE.NAN;;

PLOT BULLORBEAR =IF BULLISH2 IS TRUE OR BEARISH2 IS TRUE THEN .88 ELSE .88;;
BULLORBEAR.ASSIGNVAlueColor (IF BULLISH2 THEN COLOR.WHITE ELSE IF BEARISH2 THEN COLOR.MAGENTA ELSE IF REV THEN COLOR.GRAY ELSE COLOR.CURRENT);
BULLORBEAR.SETPAintingStrategy (PAINtingStrategy.SQUARES);
BULLORBEAR.SETLineWeight (5);
################################################
################## LABELS #######################
################################################
AddChartBubble(barNumber() == highestAll(x0)-100, REV, "REV", createcolor(0,100,255));
AddChartBubble(barNumber() == highestAll(x0)-90, GEOTREND, "GEO", createcolor(0,100,255));
AddChartBubble(barNumber() == highestAll(x0)-80, GRSI_TREND, "FRSI", createcolor(0,100,255));
AddChartBubble(barNumber() == highestAll(x0)-70, TMO_TREND, "TMO", createcolor(0,100,255));
AddChartBubble(barNumber() == highestAll(x0)-60, RIBBON_TREND, "REG",createcolor(0,100,255));
AddChartBubble(barNumber() == highestAll(x0)-50, EAVGRSI, "RSI",createcolor(0,100,255));
AddChartBubble(barNumber() == highestAll(x0)-40, YAHOOTREND, "ST", createcolor(0,100,255));

ADDLABEL( CLOSE > ST , "BULLISH", CREATECOLOR(20,160,10));
ADDLABEL( CLOSE < ST , "BEARISH", COLOR.RED);

ADDLABEL( LongAlert AND ST, "BUY" , CREATECOLOR(20,160,10));
ADDLABEL( SHORTALERT AND ST, "SELL" , COLOR.RED);

DEF TREND_FRIEND = G_RSI > G_RSI[2] IS TRUE AND Main1 > signal1 IS TRUE AND EMA_LINREG > LR IS TRUE AND CLOSE > ST IS TRUE AND PGMA3 > PGMA2 IS TRUE ;

DEF FRIENDLY = IF GRSI_UP IS TRUE AND TMO_UP IS TRUE AND REG_UP IS TRUE AND CLOSE > ST IS TRUE AND PGMA3 > PGMA2 IS TRUE THEN 1 ELSE DOUBLE.NAN;

DEF TREND_KILLER = G_RSI < G_RSI[2] IS TRUE AND Main1 < signal1 IS TRUE AND EMA_LINREG < LR IS TRUE AND CLOSE < ST IS TRUE AND PGMA3 < PGMA2 IS TRUE ;

DEF DEADLY = IF GRSI_DOWN IS TRUE AND TMO_DOWN IS TRUE AND REG_DOWN IS TRUE AND CLOSE < ST IS TRUE AND PGMA3 > PGMA2 IS TRUE THEN 1 ELSE DOUBLE.NAN;

ADDLABEL(TREND_KILLER, "TREND KILLER", COLOR.MAGENTA);
ADDLABEL(DEADLY, "TREND KILLER", COLOR.MAGENTA);

ADDLABEL(TREND_FRIEND, "TREND FRIEND ", COLOR.WHITE);
ADDLABEL(FRIENDLY, "TREND FRIEND ", COLOR.WHITE);
[/CODE]
 
Last edited:
Image of the Trend Friend Indicator

https://drive.google.com/file/d/1dTt8SRW4USeIi8eGuzGIMW3LYze6uNUO/view?usp=sharing

https://drive.google.com/file/d/1YX9YaG7GB69rb5ZGjjKvmPOkI_qIlRlp/view?usp=sharing



Hello, this will be my first contribution. I by no means take credit for much of the actual script within the study, it is mostly a collection of studies that I have found over time on this forum that I have decided to mold into a upper study that displays all indicators in a way I find to be ultra imsimplictic and easy to interpret visually.

I have always wanted an upper study that is "floating", ie. does not move at all even when you zoom in or zoom out on the chart. It is fixed to the top of the chart and there are 7 main indicators that are displayed as a color changing line, each displayed one below the other in 7 compact lines.

Each line is color coded to be either green (or white) for bullish , red (or magenta) for bearish, or nuetral if applicable. The goal is to have most (or all preferably) of the lines to match bullish or bearish color.

The indicators used are as followed.
-Supertrend (yahoo version)
-A version of RSI
-Regression Ribbon
-MTF TMO
-Fractal RSI
-Geometric Moving Averages
-Trend Reversal

Feel free to tinker with it if you'd like, I'd love to see what you all can add or revise and come up with something exceptional. I have always wanted an upper study that does no move with the chart so I can always see what is changing, that is why I created this. I haven't really seen anything similar. Essentially, it could be a lower study as well, but I wanted it to be on the chart to eliminate the space it takes to add a lower study, so the chart is bigger. Usually when you plot a lower style study on the chart, you'll get a smushed or distorted chart, or the studies will be all over the place and impossible to see or even find. With this study, it stays at the top always, above the candles , out of the way, and never really becomes a nuisance.

Let me know what you think and have a great weekend.


The coding is as followed:


###############################################
################# INPUTS #######################
###############################################

#############################################
########## SUPERTREND INPUTS #################
############## LINE NO. 1 ######################
input YST_AtrMult = 1.00;
input YSTnATR = 6;
input YST_AvgType = AverageType.HULL;
input UseEmaCross = yes;
input YST_EMA1 = 2;
input YST_EMA2 = 20;
###########################################
############## RSI INPUTS ###################
############## LINE NO. 2 ####################
input RSI_PRICE = close;
input RSI_LENGTH = 13;
input RSI_averageType = AverageType.WILDERS;
input showHorRsiLine = yes;
input showAvgRsi = yes;
input RS_avgRsiLength = 3;
input RSI_avgRsiAverageType = AverageType.WILDERS;
#################################################
############ REG RIBBON INPUTS ###################
############## LINE NO. 3 #########################
input REG_PRICE = close;
input REG_DISPLACE = 0;
input REG_LinRegLength = 80;
input REG_EMAlength = 20;
############################################
############# TMO INPUTS ####################
############## LINE NO.4 #####################
input TMO_LENGTH = 14;
input TMO_CALC_LENGTH = 5;
input TMO_SMOOTH_LENGTH = 3;
#################################################
############# GAMMA RSI INPUTS ###################
################ LINE NO.5 ########################
input gamma = .8;
####################################################
########## GEOMETRIC MA INPUTS ######################
############## LINE NO.6 #############################
input GEOprice = CLOSE;
input GEOper = 50;
INPUT GEODISPLACE1 = -.14;
input GEOprice2 = CLOSE;
input GEOper2 = 50;
INPUT GEODISPLACE2 = .14;
input GEOprice3 = CLOSE;
input GEOper3 = 7;
####################################################
########## TREND REVERSAL INPUTS ####################
############## LINE NO.7 #############################
INPUT REV_PRICE = close;
INPUT REV_superfast_length = 9;
INPUT REV_fast_length = 14;
INPUT REV_slow_length = 21;
INPUT REV_DISPLACE = 0;
################################################
####### SUPERTREND TRENDLINE ####################
################################################
def x0 = if(isNaN(close[-1]) and !isNaN(close), barNumber(), x0[1]);
def YST_ATR = ATR("length" = YSTnATR, "average type" = YST_AvgType);
def UP_Band_Basic = HL2 + (YST_AtrMult * YST_ATR);
def LW_Band_Basic = HL2 + (-YST_AtrMult * YST_ATR);
def UP_Band = if ((UP_Band_Basic < UP_Band[1]) or (close[1] > UP_Band[1])) then UP_Band_Basic else UP_Band[1];
def LW_Band = if ((LW_Band_Basic > LW_Band[1]) or (close[1] < LW_Band[1])) then LW_Band_Basic else LW_Band[1];

def ST = if ((ST[1] == UP_Band[1]) and (close < UP_Band)) then UP_Band
else if ((ST[1] == UP_Band[1]) and (close > Up_Band)) then LW_Band
else if ((ST[1] == LW_Band[1]) and (close > LW_Band)) then LW_Band
else if ((ST[1] == LW_Band) and (close < LW_Band)) then UP_Band
else LW_Band;
def EMA1Val = MovAvgExponential(close, YST_EMA1);
def EMA2Val = MovAvgExponential(close, YST_EMA2);
def EMADirection = if EMA1Val > EMA2Val then 1 else if EMA1Val < EMA2Val then -1 else 0;
DEF Long = if close > ST then ST else Double.NaN;
DEF Short = if close < ST then ST else Double.NaN;
DEF YTREND= IF LONG IS TRUE OR SHORT IS TRUE THEN 1 ELSE DOUBLE.NAN;
def LongTrigger = isNaN(Long[1]) and !isNaN(Long);
def ShortTrigger = isNaN(Short[1]) and !isNaN(Short);
DEF LongDot = if LongTrigger then ST else Double.NaN;
DEF ShortDot = if ShortTrigger then ST else Double.NaN;
def LongConfirm = (UseEmaCross and close > ST and EMADirection == 1) or (!UseEmaCross and LongTrigger);
def ShortConfirm = (UseEmaCross and close < ST and EMADirection == -1) or (!UseEmaCross and ShortTrigger);
DEF LongAlert =IF LongConfirm IS TRUE and LongConfirm[1] != LongConfirm IS TRUE THEN 1 ELSE DOUBLE.NAN;
DEF ShortAlert = IF ShortConfirm IS TRUE and ShortConfirm[1] != ShortConfirm IS TRUE THEN 1 ELSE DOUBLE.NAN;
DEF ST_ALERTING = IF LONGALERT IS TRUE THEN 1 OR IF SHORTALERT IS TRUE THEN 1 ELSE DOUBLE.NAN ELSE DOUBLE.NAN;

PLOT YAHOOTREND = YTREND IS TRUE;
YAHOOTREND.SETPaintingStrategy (paintingStrategy.HORIZONTAL);
YAHOOTREND.AssignVALUEColor( IF close < ST and (!UseEmaCross or EMADirection == -1) then Color.RED
else if close > ST and (!UseEmaCross or EMADirection == 1) then Color.GREEN
else COLOR.MAGENTA);
YAHOOTREND.SETLineWeight (5);
###########################################
########## RSI TRENDLINE ####################
###########################################
DEF over_Bought = 70;
DEF over_Sold = 30;
def NetChgAvg = MovingAverage(RSI_averageType, RSI_PRICE - RSI_PRICE[1], RSI_LENGTH);
def TotChgAvg = MovingAverage(RSI_averageType, AbsValue(RSI_PRICE - RSI_PRICE[1]), RSI_LENGTH);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
DEF EXTREME = 50 * (ChgRatio + 1);
DEF OverSold = over_Sold;
DEF OverBought = over_Bought;
DEF UpSignal = if EXTREME <= OverSold then OverSold else Double.NaN;
DEF DownSignal = if EXTREME >= OverBought then OverBought else Double.NaN;
def avgRsi = MovingAverage(RSI_avgRsiAverageType, EXTREME, RS_avgRsiLength) ;
DEF RSI_UP = AVGRSI > AVGRSI[1] IS TRUE OR UPSIGNAL IS TRUE;
DEF RSI_DOWN = AVGRSI < AVGRSI[1] IS TRUE OR DOWNSIGNAL IS TRUE;
DEF RSI_TRENDING = IF RSI_UP IS TRUE OR RSI_DOWN IS TRUE THEN .98 ELSE DOUBLE.NAN;

PLOT EAVGRSI = RSI_TRENDING ;
EavgRsi.AssignValueColor(if avgRsi > avgRsi[1] then COLOR.GREEN else IF avgRsi < avgRsi[1] THEN COLOR.RED ELSE COLOR.GRAY );
EavgRsi.SetPaintingStrategy(PAINtingStrategy.LINE);
EavgRsi.SetLineWeight(5);
##############################################
####### REG RIBBON TRENDLINE ###################
##############################################
def LinReg = Inertia(REG_PRICE[-REG_DISPLACE], REG_LinRegLength);
def EMA_LR = ExpAverage(LinReg[-REG_DISPLACE], REG_EMAlength);
def Body = (open + close)/2;
DEF LR = LinReg;
DEF EMA_LinReg= EMA_LR;
DEF REG_UP = IF EMA_LINREG > LR IS TRUE THEN .96 ELSE DOUBLE.NAN;
DEF REG_DOWN= IF EMA_LINREG < LR IS TRUE THEN .96 ELSE DOUBLE.NAN;
DEF REG_TREND = IF REG_UP IS TRUE OR REG_DOWN IS TRUE THEN .96 ELSE DOUBLE.NAN;

PLOT RIBBON_TREND = REG_TREND ;
RIBBON_TREND.SETPAintingStrategy (PAINtingStrategy.line);
RIBBON_TREND.SETLineWeight (5);
RIBBON_TREND.ASSIGNValueColor (IF EMA_LINREG < LR THEN COLOR.GREEN ELSE COLOR.RED);
###############################################
############# TMO TRENDLINE ####################
###############################################
def o2 = open;
def c2 = close;
def data = fold i = 0 to TMO_LENGTH with s do s + (if c2> GetValue(o2, i) then 2 else if c2 < GetValue(o2, i) then- 1 else 0);
def EMA5 = ExpAverage(data, TMO_CALC_LENGTH);
def Main1 = ExpAverage(EMA5, TMO_CALC_LENGTH);
def signal1 = ExpAverage(Main1, TMO_CALC_LENGTH);
def TMO_UP = IF Main1 > signal1 IS TRUE THEN .94 ELSE DOUBLE.NAN;
def TMO_DOWN = IF Main1 < signal1 IS TRUE THEN .94 ELSE DOUBLE.NAN;
DEF TMO_TRENDING = IF TMO_UP IS TRUE OR TMO_DOWN IS TRUE THEN .94 ELSE DOUBLE.NAN;

plot TMO_TREND = TMO_TRENDING;
TMO_TREND.SetPaintingStrategy (PAINtingStrategy.LINE);
TMO_TREND.AssignValueColor(if Main1 > signal1 then Color.LIME else IF Main1 < signal1 THEN COLOR.RED ELSE COLOR.GRAY);
TMO_TREND.SetLineWeight (5);
#################################################
############# GAMMA RSI TRENDLINE ################
#################################################
def o;def h;def l;def c;def CU1;def CU2;def CU;def CD1;
def CD2;def CD;def L0;def L1;def L2;def L3;

o = (open + close[1]) / 2;
h = Max(high, close[1]);
l = Min(low, close[1]);
c = (o + h + l + close) / 4;

L0 = (1 – gamma) * c + gamma * L0[1];
L1 = -gamma * L0 + L0[1] + gamma * L1[1];
L2 = -gamma * L1 + L1[1] + gamma * L2[1];
L3 = -gamma * L2 + L2[1] + gamma * L3[1];

if L0 >= L1 then {CU1 = L0 - L1; CD1 = 1; } else { CD1 = L1 - L0; CU1 = 1; } if L1 >= L2 then { CU2 = CU1 + L1 - L2; CD2 =CD1; } else { CD2 = CD1 + L2 - L1; CU2 = CU1; } if L2 >= L3 Then { CU = CU2 + L2 - L3; CD = CD2; } else { CU = CU2; CD = CD2 + L3 - L2; }

def G_RSI = if CU + CD <> 0 then CU / (CU + CD) ELSE 1;
DEF GRSI_UP = IF G_RSI > G_RSI[2] IS TRUE THEN .92 ELSE DOUBLE.NAN;
DEF GRSI_DOWN = IF G_RSI < G_RSI[2] IS TRUE THEN .92 ELSE DOUBLE.NAN;
DEF G_RSI_TRENDING= IF GRSI_UP IS TRUE OR GRSI_DOWN IS TRUE THEN .92 ELSE DOUBLE.NAN;

plot GRSI_TREND = G_RSI_TRENDING ;
GRSI_TREND.SetPaintingStrategy (PAINtingStrategy.LINE);
GRSI_TREND.SetLineWeight(5);
GRSI_TREND.AssignValueColor(if G_RSI > G_RSI[2] THEN COLOR.GREEN ELSE COLOR.RED);
################################################################
################## GEOMETRIC MA TRENDLINE #######################
################################################################
def lmean = log(GEOprice) ;
def smean = sum(lmean,GEOper) ;
def gma = exp(smean/GEOper)-GEODISPLACE1 ;
def lmean2 = log(GEOprice2) ;
def smean2 = sum(lmean2,GEOper2) ;
def gma2 = exp(smean2/GEOper2)-GEODISPLACE2 ;
def lmean3= log(GEOprice3) ;
def smean3= sum(lmean3,GEOper3) ;
def gma3= exp(smean3/GEOper3) ;

DEF pGMA = gma ;
DEF pGMA2 = gma2;
DEF pGMA3 = gma3;
DEF GEOTREND = IF PGMA3 > PGMA2 IS TRUE THEN .9 ELSE .9;

PLOT TRENDGEO = GEOTREND ;
TRENDGEO.SETPAintingStrategy (PAINTingStrategy.LINE);
TRENDGEO.ASSIGNValueColor (IF PGMA3 > PGMA2 OR PGMA3 > PGMA THEN COLOR.GREEN ELSE COLOR.RED);
TRENDGEO.SETLineWeight (5);
##############################################
########### REVERSAL TRENDLINE #################
##############################################
def mov_avg9 = ExpAverage(REV_PRICE[-REV_DISPLACE], REV_superfast_length);
def mov_avg14 = ExpAverage(REV_PRICE[-REV_DISPLACE], REV_fast_length);
def mov_avg21 = ExpAverage(REV_PRICE[-REV_DISPLACE], REV_slow_length);
def Superfast = mov_avg9;
def Fast = mov_avg14;
def Slow = mov_avg21;
def buy = mov_avg9 > mov_avg14 and mov_avg14 > mov_avg21 and low > mov_avg9;
def stopbuy = mov_avg9 <= mov_avg14;
def buynow = !buy[1] and buy;
def buysignal = CompoundValue(1, if buynow and !stopbuy then 1 else if buysignal[1] == 1 and stopbuy then 0 else buysignal[1], 0);
def Buy_Signal = buysignal[1] == 0 and buysignal == 1;
def Momentum_Down = buysignal[1] == 1 and buysignal == 0;
def sell = mov_avg9 < mov_avg14 and mov_avg14 < mov_avg21 and high < mov_avg9;
def stopsell = mov_avg9 >= mov_avg14;
def sellnow = !sell[1] and sell;
def sellsignal = CompoundValue(1, if sellnow and !stopsell then 1 else if sellsignal[1] == 1 and stopsell then 0 else sellsignal[1], 0);
def Sell_Signal = sellsignal[1] == 0 and sellsignal;

input REV_method = {default average, high_low};
def bubbleoffset = .0005;
def percentamount = .01;
def revAmount = .05;
def atrreversal = 2.0;
def atrlength = 5;
def pricehigh = high;
def pricelow = low;
def averagelength = 5;
def averagetype = AverageType.EXPONENTIAL;
def mah = MovingAverage(averagetype, pricehigh, averagelength);
def mal = MovingAverage(averagetype, pricelow, averagelength);
def priceh = if REV_method == REV_method.high_low then pricehigh else mah;
def pricel = if REV_method == REV_method.high_low then pricelow else mal;
def EI = ZigZagHighLow("price h" = priceh, "price l" = pricel, "percentage reversal" = percentamount, "absolute reversal" = revAmount, "atr length" = atrlength, "atr reversal" = atrreversal);
rec EISave = if !IsNaN(EI) then EI else GetValue(EISave, 1);
def chg = (if EISave == priceh then priceh else pricel) - GetValue(EISave, 1);
def isUp = chg >= 0;
def EIL = if !IsNaN(EI) and !isUp then pricel else GetValue(EIL, 1);
def EIH = if !IsNaN(EI) and isUp then priceh else GetValue(EIH, 1);
def dir = CompoundValue(1, if EIL != EIL[1] or pricel == EIL[1] and pricel == EISave then 1 else if EIH != EIH[1] or priceh == EIH[1] and priceh == EISave then -1 else dir[1], 0);
def signal = CompoundValue(1, if dir > 0 and pricel > EIL then if signal[1] <= 0 then 1 else signal[1] else if dir < 0 and priceh < EIH then if signal[1] >= 0 then -1 else signal[1] else signal[1], 0);

DEF bullish2 = signal > 0 and signal[1] <= 0 IS TRUE;
def bearish2 = signal < 0 and signal[1] >= 0 IS TRUE;
DEF TRENDINGREVERSAL = IF BULLISH2 IS TRUE OR BEARISH2 IS TRUE THEN .88 ELSE .88;
DEF TRENDREV = IF TRENDINGREVERSAL IS TRUE THEN .88 ELSE .88;

PLOT REV= IF TRENDREV IS TRUE THEN .88 ELSE .88;
REV.SETPaintingStrategy (PAINtingStrategy.LINE);
REV.ASSIGNValueColor(IF BULLISH2 THEN COLOR.GREEN ELSE IF BEARISH2 THEN COLOR.RED ELSE COLOR.GRAY);
REV.SETLineWeight (5);

DEF BULL =IF BULLISH2 IS TRUE THEN .88 ELSE DOUBLE.NAN;
DEF BEAR = IF BEARISH2 IS TRUE THEN .88 ELSE DOUBLE.NAN;;

PLOT BULLORBEAR =IF BULLISH2 IS TRUE OR BEARISH2 IS TRUE THEN .88 ELSE .88;;
BULLORBEAR.ASSIGNVAlueColor (IF BULLISH2 THEN COLOR.WHITE ELSE IF BEARISH2 THEN COLOR.MAGENTA ELSE IF REV THEN COLOR.GRAY ELSE COLOR.CURRENT);
BULLORBEAR.SETPAintingStrategy (PAINtingStrategy.SQUARES);
BULLORBEAR.SETLineWeight (5);
################################################
################## LABELS #######################
################################################
AddChartBubble(barNumber() == highestAll(x0)-100, REV, "REV", createcolor(0,100,255));
AddChartBubble(barNumber() == highestAll(x0)-90, GEOTREND, "GEO", createcolor(0,100,255));
AddChartBubble(barNumber() == highestAll(x0)-80, GRSI_TREND, "FRSI", createcolor(0,100,255));
AddChartBubble(barNumber() == highestAll(x0)-70, TMO_TREND, "TMO", createcolor(0,100,255));
AddChartBubble(barNumber() == highestAll(x0)-60, RIBBON_TREND, "REG",createcolor(0,100,255));
AddChartBubble(barNumber() == highestAll(x0)-50, EAVGRSI, "RSI",createcolor(0,100,255));
AddChartBubble(barNumber() == highestAll(x0)-40, YAHOOTREND, "ST", createcolor(0,100,255));

ADDLABEL( CLOSE > ST , "BULLISH", CREATECOLOR(20,160,10));
ADDLABEL( CLOSE < ST , "BEARISH", COLOR.RED);

ADDLABEL( LongAlert AND ST, "BUY" , CREATECOLOR(20,160,10));
ADDLABEL( SHORTALERT AND ST, "SELL" , COLOR.RED);

DEF TREND_FRIEND = G_RSI > G_RSI[2] IS TRUE AND Main1 > signal1 IS TRUE AND EMA_LINREG > LR IS TRUE AND CLOSE > ST IS TRUE AND PGMA3 > PGMA2 IS TRUE ;

DEF FRIENDLY = IF GRSI_UP IS TRUE AND TMO_UP IS TRUE AND REG_UP IS TRUE AND CLOSE > ST IS TRUE AND PGMA3 > PGMA2 IS TRUE THEN 1 ELSE DOUBLE.NAN;

DEF TREND_KILLER = G_RSI < G_RSI[2] IS TRUE AND Main1 < signal1 IS TRUE AND EMA_LINREG < LR IS TRUE AND CLOSE < ST IS TRUE AND PGMA3 < PGMA2 IS TRUE ;

DEF DEADLY = IF GRSI_DOWN IS TRUE AND TMO_DOWN IS TRUE AND REG_DOWN IS TRUE AND CLOSE < ST IS TRUE AND PGMA3 > PGMA2 IS TRUE THEN 1 ELSE DOUBLE.NAN;

ADDLABEL(TREND_KILLER, "TREND KILLER", COLOR.MAGENTA);
ADDLABEL(DEADLY, "TREND KILLER", COLOR.MAGENTA);

ADDLABEL(TREND_FRIEND, "TREND FRIEND ", COLOR.WHITE);
ADDLABEL(FRIENDLY, "TREND FRIEND ", COLOR.WHITE);
[/CODE]
Hi - getting the following error:

Invalid statement: [ at 292:1

And nothing shows on the chart except the lable "BEARISH" when I # out that error.
 
Hi - getting the following error:

Invalid statement: [ at 292:1

And nothing shows on the chart except the lable "BEARISH" when I # out that error.

i don't see an error from the code in post#1. maybe you didn't copy all of it?

the original seems to be an upper study. but it doesn't match the images.
it doesn't plot horizontal lines at the top of a chart.
it plots horizontal lines near 0, which compresses the candles


i have no opinion on this. i didn't study the math. i just made it work as a lower study.

i changed it to be a lower study
changed it so it doesn't plot lines past the last bar, which was also compressing the lines.


Ruby:
# trend_friend_00b

#https://usethinkscript.com/threads/trend-friend-chart-setup-for-thinkorswim.12313/

declare lower;
def x = !isnan(close);
def na = double.nan;


###############################################
################# INPUTS #######################
###############################################

#############################################
########## SUPERTREND INPUTS #################
############## LINE NO. 1 ######################
input YST_AtrMult = 1.00;
input YSTnATR = 6;
input YST_AvgType = AverageType.HULL;
input UseEmaCross = yes;
input YST_EMA1 = 2;
input YST_EMA2 = 20;
###########################################
############## RSI INPUTS ###################
############## LINE NO. 2 ####################
input RSI_PRICE = close;
input RSI_LENGTH = 13;
input RSI_averageType = AverageType.WILDERS;
input showHorRsiLine = yes;
input showAvgRsi = yes;
input RS_avgRsiLength = 3;
input RSI_avgRsiAverageType = AverageType.WILDERS;
#################################################
############ REG RIBBON INPUTS ###################
############## LINE NO. 3 #########################
input REG_PRICE = close;
input REG_DISPLACE = 0;
input REG_LinRegLength = 80;
input REG_EMAlength = 20;
############################################
############# TMO INPUTS ####################
############## LINE NO.4 #####################
input TMO_LENGTH = 14;
input TMO_CALC_LENGTH = 5;
input TMO_SMOOTH_LENGTH = 3;
#################################################
############# GAMMA RSI INPUTS ###################
################ LINE NO.5 ########################
input gamma = .8;
####################################################
########## GEOMETRIC MA INPUTS ######################
############## LINE NO.6 #############################
input GEOprice = CLOSE;
input GEOper = 50;
INPUT GEODISPLACE1 = -.14;
input GEOprice2 = CLOSE;
input GEOper2 = 50;
INPUT GEODISPLACE2 = .14;
input GEOprice3 = CLOSE;
input GEOper3 = 7;
####################################################
########## TREND REVERSAL INPUTS ####################
############## LINE NO.7 #############################
INPUT REV_PRICE = close;
INPUT REV_superfast_length = 9;
INPUT REV_fast_length = 14;
INPUT REV_slow_length = 21;
INPUT REV_DISPLACE = 0;
################################################
####### SUPERTREND TRENDLINE ####################
################################################
def x0 = if(isNaN(close[-1]) and !isNaN(close), barNumber(), x0[1]);
def YST_ATR = ATR("length" = YSTnATR, "average type" = YST_AvgType);
def UP_Band_Basic = HL2 + (YST_AtrMult * YST_ATR);
def LW_Band_Basic = HL2 + (-YST_AtrMult * YST_ATR);
def UP_Band = if ((UP_Band_Basic < UP_Band[1]) or (close[1] > UP_Band[1])) then UP_Band_Basic else UP_Band[1];
def LW_Band = if ((LW_Band_Basic > LW_Band[1]) or (close[1] < LW_Band[1])) then LW_Band_Basic else LW_Band[1];

def ST = if ((ST[1] == UP_Band[1]) and (close < UP_Band)) then UP_Band
else if ((ST[1] == UP_Band[1]) and (close > Up_Band)) then LW_Band
else if ((ST[1] == LW_Band[1]) and (close > LW_Band)) then LW_Band
else if ((ST[1] == LW_Band) and (close < LW_Band)) then UP_Band
else LW_Band;
def EMA1Val = MovAvgExponential(close, YST_EMA1);
def EMA2Val = MovAvgExponential(close, YST_EMA2);
def EMADirection = if EMA1Val > EMA2Val then 1 else if EMA1Val < EMA2Val then -1 else 0;
DEF Long = if close > ST then ST else Double.NaN;
DEF Short = if close < ST then ST else Double.NaN;
DEF YTREND= IF LONG IS TRUE OR SHORT IS TRUE THEN 1 ELSE DOUBLE.NAN;
def LongTrigger = isNaN(Long[1]) and !isNaN(Long);
def ShortTrigger = isNaN(Short[1]) and !isNaN(Short);
DEF LongDot = if LongTrigger then ST else Double.NaN;
DEF ShortDot = if ShortTrigger then ST else Double.NaN;
def LongConfirm = (UseEmaCross and close > ST and EMADirection == 1) or (!UseEmaCross and LongTrigger);
def ShortConfirm = (UseEmaCross and close < ST and EMADirection == -1) or (!UseEmaCross and ShortTrigger);
DEF LongAlert =IF LongConfirm IS TRUE and LongConfirm[1] != LongConfirm IS TRUE THEN 1 ELSE DOUBLE.NAN;
DEF ShortAlert = IF ShortConfirm IS TRUE and ShortConfirm[1] != ShortConfirm IS TRUE THEN 1 ELSE DOUBLE.NAN;
DEF ST_ALERTING = IF LONGALERT IS TRUE THEN 1 OR IF SHORTALERT IS TRUE THEN 1 ELSE DOUBLE.NAN ELSE DOUBLE.NAN;

PLOT YAHOOTREND = if x then YTREND IS TRUE else na;
YAHOOTREND.SETPaintingStrategy (paintingStrategy.HORIZONTAL);
YAHOOTREND.AssignVALUEColor( IF close < ST and (!UseEmaCross or EMADirection == -1) then Color.RED
else if close > ST and (!UseEmaCross or EMADirection == 1) then Color.GREEN
else COLOR.MAGENTA);
YAHOOTREND.SETLineWeight (5);
###########################################
########## RSI TRENDLINE ####################
###########################################
DEF over_Bought = 70;
DEF over_Sold = 30;
def NetChgAvg = MovingAverage(RSI_averageType, RSI_PRICE - RSI_PRICE[1], RSI_LENGTH);
def TotChgAvg = MovingAverage(RSI_averageType, AbsValue(RSI_PRICE - RSI_PRICE[1]), RSI_LENGTH);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
DEF EXTREME = 50 * (ChgRatio + 1);
DEF OverSold = over_Sold;
DEF OverBought = over_Bought;
DEF UpSignal = if EXTREME <= OverSold then OverSold else Double.NaN;
DEF DownSignal = if EXTREME >= OverBought then OverBought else Double.NaN;
def avgRsi = MovingAverage(RSI_avgRsiAverageType, EXTREME, RS_avgRsiLength) ;
DEF RSI_UP = AVGRSI > AVGRSI[1] IS TRUE OR UPSIGNAL IS TRUE;
DEF RSI_DOWN = AVGRSI < AVGRSI[1] IS TRUE OR DOWNSIGNAL IS TRUE;
DEF RSI_TRENDING = IF RSI_UP IS TRUE OR RSI_DOWN IS TRUE THEN .98 ELSE DOUBLE.NAN;

PLOT EAVGRSI = if x then RSI_TRENDING else na;
EavgRsi.AssignValueColor(if avgRsi > avgRsi[1] then COLOR.GREEN else IF avgRsi < avgRsi[1] THEN COLOR.RED ELSE COLOR.GRAY );
EavgRsi.SetPaintingStrategy(PAINtingStrategy.LINE);
EavgRsi.SetLineWeight(5);
##############################################
####### REG RIBBON TRENDLINE ###################
##############################################
def LinReg = Inertia(REG_PRICE[-REG_DISPLACE], REG_LinRegLength);
def EMA_LR = ExpAverage(LinReg[-REG_DISPLACE], REG_EMAlength);
def Body = (open + close)/2;
DEF LR = LinReg;
DEF EMA_LinReg= EMA_LR;
DEF REG_UP = IF EMA_LINREG > LR IS TRUE THEN .96 ELSE DOUBLE.NAN;
DEF REG_DOWN= IF EMA_LINREG < LR IS TRUE THEN .96 ELSE DOUBLE.NAN;
DEF REG_TREND = IF REG_UP IS TRUE OR REG_DOWN IS TRUE THEN .96 ELSE DOUBLE.NAN;

PLOT RIBBON_TREND = if x then REG_TREND else na;
RIBBON_TREND.SETPAintingStrategy (PAINtingStrategy.line);
RIBBON_TREND.SETLineWeight (5);
RIBBON_TREND.ASSIGNValueColor (IF EMA_LINREG < LR THEN COLOR.GREEN ELSE COLOR.RED);
###############################################
############# TMO TRENDLINE ####################
###############################################
def o2 = open;
def c2 = close;
def data = fold i = 0 to TMO_LENGTH with s do s + (if c2> GetValue(o2, i) then 2 else if c2 < GetValue(o2, i) then- 1 else 0);
def EMA5 = ExpAverage(data, TMO_CALC_LENGTH);
def Main1 = ExpAverage(EMA5, TMO_CALC_LENGTH);
def signal1 = ExpAverage(Main1, TMO_CALC_LENGTH);
def TMO_UP = IF Main1 > signal1 IS TRUE THEN .94 ELSE DOUBLE.NAN;
def TMO_DOWN = IF Main1 < signal1 IS TRUE THEN .94 ELSE DOUBLE.NAN;
DEF TMO_TRENDING = IF TMO_UP IS TRUE OR TMO_DOWN IS TRUE THEN .94 ELSE DOUBLE.NAN;

plot TMO_TREND = if x then TMO_TRENDING else na;
TMO_TREND.SetPaintingStrategy (PAINtingStrategy.LINE);
TMO_TREND.AssignValueColor(if Main1 > signal1 then Color.LIME else IF Main1 < signal1 THEN COLOR.RED ELSE COLOR.GRAY);
TMO_TREND.SetLineWeight (5);
#################################################
############# GAMMA RSI TRENDLINE ################
#################################################
def o;def h;def l;def c;def CU1;def CU2;def CU;def CD1;
def CD2;def CD;def L0;def L1;def L2;def L3;

o = (open + close[1]) / 2;
h = Max(high, close[1]);
l = Min(low, close[1]);
c = (o + h + l + close) / 4;

L0 = (1 – gamma) * c + gamma * L0[1];
L1 = -gamma * L0 + L0[1] + gamma * L1[1];
L2 = -gamma * L1 + L1[1] + gamma * L2[1];
L3 = -gamma * L2 + L2[1] + gamma * L3[1];

if L0 >= L1 then {CU1 = L0 - L1; CD1 = 1; } else { CD1 = L1 - L0; CU1 = 1; } if L1 >= L2 then { CU2 = CU1 + L1 - L2; CD2 =CD1; } else { CD2 = CD1 + L2 - L1; CU2 = CU1; } if L2 >= L3 Then { CU = CU2 + L2 - L3; CD = CD2; } else { CU = CU2; CD = CD2 + L3 - L2; }

def G_RSI = if CU + CD <> 0 then CU / (CU + CD) ELSE 1;
DEF GRSI_UP = IF G_RSI > G_RSI[2] IS TRUE THEN .92 ELSE DOUBLE.NAN;
DEF GRSI_DOWN = IF G_RSI < G_RSI[2] IS TRUE THEN .92 ELSE DOUBLE.NAN;
DEF G_RSI_TRENDING= IF GRSI_UP IS TRUE OR GRSI_DOWN IS TRUE THEN .92 ELSE DOUBLE.NAN;

plot GRSI_TREND = if x then G_RSI_TRENDING else na;
GRSI_TREND.SetPaintingStrategy (PAINtingStrategy.LINE);
GRSI_TREND.SetLineWeight(5);
GRSI_TREND.AssignValueColor(if G_RSI > G_RSI[2] THEN COLOR.GREEN ELSE COLOR.RED);
################################################################
################## GEOMETRIC MA TRENDLINE #######################
################################################################
def lmean = log(GEOprice) ;
def smean = sum(lmean,GEOper) ;
def gma = exp(smean/GEOper)-GEODISPLACE1 ;
def lmean2 = log(GEOprice2) ;
def smean2 = sum(lmean2,GEOper2) ;
def gma2 = exp(smean2/GEOper2)-GEODISPLACE2 ;
def lmean3= log(GEOprice3) ;
def smean3= sum(lmean3,GEOper3) ;
def gma3= exp(smean3/GEOper3) ;

DEF pGMA = gma ;
DEF pGMA2 = gma2;
DEF pGMA3 = gma3;
DEF GEOTREND = IF PGMA3 > PGMA2 IS TRUE THEN .9 ELSE .9;

PLOT TRENDGEO = if x then GEOTREND else na;
TRENDGEO.SETPAintingStrategy (PAINTingStrategy.LINE);
TRENDGEO.ASSIGNValueColor (IF PGMA3 > PGMA2 OR PGMA3 > PGMA THEN COLOR.GREEN ELSE COLOR.RED);
TRENDGEO.SETLineWeight (5);
##############################################
########### REVERSAL TRENDLINE #################
##############################################
def mov_avg9 = ExpAverage(REV_PRICE[-REV_DISPLACE], REV_superfast_length);
def mov_avg14 = ExpAverage(REV_PRICE[-REV_DISPLACE], REV_fast_length);
def mov_avg21 = ExpAverage(REV_PRICE[-REV_DISPLACE], REV_slow_length);
def Superfast = mov_avg9;
def Fast = mov_avg14;
def Slow = mov_avg21;
def buy = mov_avg9 > mov_avg14 and mov_avg14 > mov_avg21 and low > mov_avg9;
def stopbuy = mov_avg9 <= mov_avg14;
def buynow = !buy[1] and buy;
def buysignal = CompoundValue(1, if buynow and !stopbuy then 1 else if buysignal[1] == 1 and stopbuy then 0 else buysignal[1], 0);
def Buy_Signal = buysignal[1] == 0 and buysignal == 1;
def Momentum_Down = buysignal[1] == 1 and buysignal == 0;
def sell = mov_avg9 < mov_avg14 and mov_avg14 < mov_avg21 and high < mov_avg9;
def stopsell = mov_avg9 >= mov_avg14;
def sellnow = !sell[1] and sell;
def sellsignal = CompoundValue(1, if sellnow and !stopsell then 1 else if sellsignal[1] == 1 and stopsell then 0 else sellsignal[1], 0);
def Sell_Signal = sellsignal[1] == 0 and sellsignal;

input REV_method = {default average, high_low};
def bubbleoffset = .0005;
def percentamount = .01;
def revAmount = .05;
def atrreversal = 2.0;
def atrlength = 5;
def pricehigh = high;
def pricelow = low;
def averagelength = 5;
def averagetype = AverageType.EXPONENTIAL;
def mah = MovingAverage(averagetype, pricehigh, averagelength);
def mal = MovingAverage(averagetype, pricelow, averagelength);
def priceh = if REV_method == REV_method.high_low then pricehigh else mah;
def pricel = if REV_method == REV_method.high_low then pricelow else mal;
def EI = ZigZagHighLow("price h" = priceh, "price l" = pricel, "percentage reversal" = percentamount, "absolute reversal" = revAmount, "atr length" = atrlength, "atr reversal" = atrreversal);
rec EISave = if !IsNaN(EI) then EI else GetValue(EISave, 1);
def chg = (if EISave == priceh then priceh else pricel) - GetValue(EISave, 1);
def isUp = chg >= 0;
def EIL = if !IsNaN(EI) and !isUp then pricel else GetValue(EIL, 1);
def EIH = if !IsNaN(EI) and isUp then priceh else GetValue(EIH, 1);
def dir = CompoundValue(1, if EIL != EIL[1] or pricel == EIL[1] and pricel == EISave then 1 else if EIH != EIH[1] or priceh == EIH[1] and priceh == EISave then -1 else dir[1], 0);
def signal = CompoundValue(1, if dir > 0 and pricel > EIL then if signal[1] <= 0 then 1 else signal[1] else if dir < 0 and priceh < EIH then if signal[1] >= 0 then -1 else signal[1] else signal[1], 0);

DEF bullish2 = signal > 0 and signal[1] <= 0 IS TRUE;
def bearish2 = signal < 0 and signal[1] >= 0 IS TRUE;
DEF TRENDINGREVERSAL = IF BULLISH2 IS TRUE OR BEARISH2 IS TRUE THEN .88 ELSE .88;
DEF TRENDREV = IF TRENDINGREVERSAL IS TRUE THEN .88 ELSE .88;

PLOT REV= if !x then na else IF TRENDREV IS TRUE THEN .88 ELSE .88;
REV.SETPaintingStrategy (PAINtingStrategy.LINE);
REV.ASSIGNValueColor(IF BULLISH2 THEN COLOR.GREEN ELSE IF BEARISH2 THEN COLOR.RED ELSE COLOR.GRAY);
REV.SETLineWeight (5);

DEF BULL =IF BULLISH2 IS TRUE THEN .88 ELSE DOUBLE.NAN;
DEF BEAR = IF BEARISH2 IS TRUE THEN .88 ELSE DOUBLE.NAN;;

PLOT BULLORBEAR = if !x then na else IF BULLISH2 IS TRUE OR BEARISH2 IS TRUE THEN .88 ELSE .88;;
BULLORBEAR.ASSIGNVAlueColor (IF BULLISH2 THEN COLOR.WHITE ELSE IF BEARISH2 THEN COLOR.MAGENTA ELSE IF REV THEN COLOR.GRAY ELSE COLOR.CURRENT);
BULLORBEAR.SETPAintingStrategy (PAINtingStrategy.SQUARES);
BULLORBEAR.SETLineWeight (5);
################################################
################## LABELS #######################
################################################
AddChartBubble(barNumber() == highestAll(x0)-100, REV, "REV", createcolor(0,100,255));
AddChartBubble(barNumber() == highestAll(x0)-90, GEOTREND, "GEO", createcolor(0,100,255));
AddChartBubble(barNumber() == highestAll(x0)-80, GRSI_TREND, "FRSI", createcolor(0,100,255));
AddChartBubble(barNumber() == highestAll(x0)-70, TMO_TREND, "TMO", createcolor(0,100,255));
AddChartBubble(barNumber() == highestAll(x0)-60, RIBBON_TREND, "REG",createcolor(0,100,255));
AddChartBubble(barNumber() == highestAll(x0)-50, EAVGRSI, "RSI",createcolor(0,100,255));
AddChartBubble(barNumber() == highestAll(x0)-40, YAHOOTREND, "ST", createcolor(0,100,255));

ADDLABEL( CLOSE > ST , "BULLISH", CREATECOLOR(20,160,10));
ADDLABEL( CLOSE < ST , "BEARISH", COLOR.RED);

ADDLABEL( LongAlert AND ST, "BUY" , CREATECOLOR(20,160,10));
ADDLABEL( SHORTALERT AND ST, "SELL" , COLOR.RED);

DEF TREND_FRIEND = G_RSI > G_RSI[2] IS TRUE AND Main1 > signal1 IS TRUE AND EMA_LINREG > LR IS TRUE AND CLOSE > ST IS TRUE AND PGMA3 > PGMA2 IS TRUE ;

DEF FRIENDLY = IF GRSI_UP IS TRUE AND TMO_UP IS TRUE AND REG_UP IS TRUE AND CLOSE > ST IS TRUE AND PGMA3 > PGMA2 IS TRUE THEN 1 ELSE DOUBLE.NAN;

DEF TREND_KILLER = G_RSI < G_RSI[2] IS TRUE AND Main1 < signal1 IS TRUE AND EMA_LINREG < LR IS TRUE AND CLOSE < ST IS TRUE AND PGMA3 < PGMA2 IS TRUE ;

DEF DEADLY = IF GRSI_DOWN IS TRUE AND TMO_DOWN IS TRUE AND REG_DOWN IS TRUE AND CLOSE < ST IS TRUE AND PGMA3 > PGMA2 IS TRUE THEN 1 ELSE DOUBLE.NAN;

ADDLABEL(TREND_KILLER, "TREND KILLER", COLOR.MAGENTA);
ADDLABEL(DEADLY, "TREND KILLER", COLOR.MAGENTA);

ADDLABEL(TREND_FRIEND, "TREND FRIEND ", COLOR.WHITE);
ADDLABEL(FRIENDLY, "TREND FRIEND ", COLOR.WHITE);
#
 
Does any of the indicators within the script repaint? Particularly, the Trend Reversal line signals. It seems to predict price movement correctly almost 99% of the time...
 
Last edited by a moderator:
Does any of the indicators within the script repaint? Particularly, the Trend Reversal line signals. It seems to predict price movement correctly almost 99% of the time...
Indicators in this chart setup:

1. SuperTrend - does not repaint
2. RSI -- does not repaint
3. EMA -- does not repaint
4. TMO -- does not repaint
5. Trend Reversal -- repaints big time

FYI, any thread on the forum with a prefix of "repaints" really does repaint in some sort of fashion.
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
371 Online
Create Post

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