DEEPWATER_THE ONE For ThinkOrSwim

I call this study THE ONE. It is basically throw everything but the kitchen sink into one study ...........
i copied the code in post #1 and modified a couple of sections, to show other ways to write the formulas, using sum()
.... plot TrendReversalstrongbuy =
....the 30 rsicalc formulas
( i left the original code in , some commented out, some not). look for a string of #######
Python:
#DEEPWATER_THE_ONE_01

# -------------------
# 21-05-27
# halcyonguy
# simplify 2 sections  ( look for  ######## )
#   plot TrendReversalstrongbuy =
#   replace 30 rsicalc formulas to a few
# -------------------


#  5/20/2021 revision
#https://usethinkscript.com/threads/deepwater_the-one.6518/
declare lower;
input length = 20;
input length2 = 15;
input price = close;
input averageType = AverageType.WILDERS;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageTypeMACD = AverageType.EXPONENTIAL;

def Diff = MACD(fastLength, slowLength, MACDLength, averageTypeMACD).Diff;

def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

def RSI = 50 * (ChgRatio + 1);
def RSIAvg3 = MovingAverage(averageType, (RSI), 3);
def RSIAvg5 = MovingAverage(averageType, (RSI), 5);
def RSI3OverSoldpivit = RSIAvg3 > RSIAvg3[1] and RSIAvg3[1] > RSIAvg3[2] and RSIAvg3[2] < RSIAvg3[3] and RSIAvg3[3] < RSIAvg3 [4];
def RSI3OverBoughtpivit = RSIAvg3 < RSIAvg3[1] and RSIAvg3[1] < RSIAvg3[2] and RSIAvg3[2] > RSIAvg3[3] and RSIAvg3[3] > RSIAvg3 [4];
#--------------------5 day MA
input displace = 0;
input showBreakoutSignals = no;
def MAvgExp14 = ExpAverage(price[-displace], 14);
#--------------------oversold
def twoBarPivotMACD = Diff > Diff[1] and Diff[1] > Diff[2] and Diff[2] < Diff[3] and Diff[3] < Diff [4];

def overSoldRSI = RSI <= 32;
def overSoldRSIHeavy = RSI <= 30 and Diff < 0 and (close < close[7]);
def TrendReversalalert = (twoBarPivotMACD and Highest(overSoldRSI, 6) > 0) / 3;

Alert(TrendReversalalert, "Buy Alert");
plot TrendReversal1 = (twoBarPivotMACD and RSIAvg3 < 45 and Highest(overSoldRSIHeavy, 6) > 0) / 1.4;

# #####################

# simplify formula
#plot TrendReversalstrongbuy = ((TrendReversal1[1] > 0 or TrendReversal1[2] > 0 or TrendReversal1[3] > 0 or TrendReversal1[4] > 0 or TrendReversal1[5] > 0 or TrendReversal1[6] > 0 or TrendReversal1[7] > 0 or TrendReversal1[8] > 0 or TrendReversal1[9] > 0 or TrendReversal1[10] > 0 or TrendReversal1[11] > 0 or TrendReversal1[12] > 0 or TrendReversal1[13] > 0 or TrendReversal1[14] > 0) and twoBarPivotMACD and RSIAvg3 < 45 and Highest(overSoldRSIHeavy, 6) > 0) / 1.1;

# replace most of prev formula with   (sum(TrendReversal1[1], 14) > 0)

plot TrendReversalstrongbuy = (
(sum(TrendReversal1[1], 14) > 0)
and twoBarPivotMACD and RSIAvg3 < 45 and Highest(overSoldRSIHeavy, 6) > 0) / 1.1;

# #####################

plot TrendReversal = (twoBarPivotMACD and TrendReversalstrongbuy < 1 and Highest(overSoldRSI, 6) > 0) / 3;

TrendReversal.SetDefaultColor(GetColor(4));#yellow
TrendReversal1.SetDefaultColor(GetColor(6));#green
TrendReversalstrongbuy.SetDefaultColor(GetColor(6));#green
TrendReversalstrongbuy.SetLineWeight(3);
TrendReversal1.SetLineWeight(2);


AddLabel(yes, if  TrendReversal > 0 then "Buy" else "");
Alert( TrendReversalalert > 0,  "Chart is now Oversold ", Alert.BAR, Sound.Ring);
AddLabel(TrendReversalalert > 0
, "Chart is now Oversold ", Color.LIME);
#-----------------------Overbought
def twoBarPivotMACD1 = Diff < Diff[1] and Diff[1] < Diff[2] and Diff[2] > Diff[3] and Diff[3] > Diff [4];

def overboughtRSI = RSIAvg3 >= 65 and Diff > 0;
def TrendReversalalert20 = (twoBarPivotMACD1 and Highest(overboughtRSI[1], 7) > 0);
plot TrendReversal20 = 1 - (((RSIAvg3 >= 68 and RSI < RSIAvg3[2]) and RSI3OverBoughtpivit)/ 1.5) ;
plot TrendReversal20a = 1 - ((((RSIAvg3 >= 60 and RSIAvg3 < 68 )and RSI < RSIAvg3[2]) and RSI3OverBoughtpivit) / 4) ;

TrendReversal20.SetDefaultColor(GetColor(5)); #Red
TrendReversal20a.SetDefaultColor(GetColor(2)); #lt Red
TrendReversal20a.SetLineWeight(2);
TrendReversal20.SetLineWeight(3);
plot TrendReversal50 = 1 - ((RSIAvg5 >= 70 and close < MAvgExp14) / 2) ;
TrendReversal50.SetDefaultColor(GetColor(0)); #Red
TrendReversal50.SetLineWeight(3);
AddLabel(yes, if  TrendReversal20 < 1 then "Sell" else "");
Alert( TrendReversal20 < 1 ,  "Chart is now Overbought ", Alert.BAR, Sound.Ring);
AddLabel(TrendReversal20 < 1, "Chart is now Overbought ", Color.LIME);
input show_label = yes;
input show_bubble = no;
#--------------------------- Large 5X and 10X Volume Alert
input AverageLength = 100;
input VolumeMultiplier = 8;
input VolumeMultiplier2 = 5;
input MinutesAfterOpen = 30;

def AvgVol = Average(volume, AverageLength);
def VolX = (volume > AvgVol * VolumeMultiplier) ;
def Vol10X = (volume > AvgVol * 10) ;

Alert(VolX, Concat(GetSymbolPart(), " has a large volume spike." ), Alert.BAR, Sound.Chimes);
AddLabel(VolX > 0,  " Has 5X Volume Spike ", Color.LIGHT_GREEN);
Alert(Vol10X, Concat(GetSymbolPart(), " has a large volume spike." ), Alert.BAR, Sound.Chimes);
AddLabel(Vol10X > 0,  " Has 10X Volume Spike ", Color.LIGHT_GREEN);
#-------------------------------------GAP UP Price
def IsUp = close > open;
def IsDown = close < open;
def IsDoji = IsDoji();
def avgRange = 0.05 * Average(high - low, 20);
def GapUp =
    IsUp[1] and
    IsUp[0] and
    high[1] < low[0] and
    high[1] < open[0] and
(volume > AvgVol * 5) ;
Alert(GapUp, Concat(GetSymbolPart(), " GAPUP" ), Alert.BAR, Sound.Ring);
AddLabel(GapUp > 0,  " GAP Up  ", Color.LIGHT_GREEN);

#---------------------------------Large Price change 3%
def Priceup =
    IsUp[1] and
    IsUp[0] and
    high[1] < high[0] and
    high[2] * 1.02 < high[0] and
    high[3] * 1.03 < high[0] and
(volume > AvgVol * 3) ;
Alert(Priceup, Concat(GetSymbolPart(), " Price JUMP" ), Alert.BAR, Sound.Bell);
AddLabel(Priceup > 0,  " Price JUMP  ", Color.CYAN);

#---------------------------------HugePrice change 6%
def Priceup2 =
    IsUp[1] and
    IsUp[0] and
    high[1] < high[0] and
    high[3] * 1.04 < high[0] and
    high[4] * 1.06 < high[0] and
(volume > AvgVol * 3) ;
Alert(Priceup2, Concat(GetSymbolPart(), " JUMP! JUMP! JUMP" ), Alert.BAR, Sound.Chimes);
AddLabel(Priceup2 > 0,  " JUMP! JUMP! JUMP  ", Color.LIGHT_RED);

#-----------------------------------------------------------------------------------------
#-----------RSI cumulative running total
def MAvgExp7 = ExpAverage(price[-displace], 7);
def RSICalc = 50 * (ChgRatio + 1);

# ####################################################

# redo the following 30 formulas and the total formula, into just a few formulas
# these could be done in 2 formulas, but i left them separated, to make it easier to read
#  chg constants to variables
def rsiupper = 70;
def rsilower = 30;
# instead of defining 30 variables on each bar, set 1 var, then read it later and modify as needed
#  set a value for each bar,  -1 or 1
def RSICalcx = if RSI[0] > rsiupper then 1 else if RSI[0] < rsilower then  -1 else 0;
# calc a new calc value from rsicalcx, depending on offset
#  if bar offset is [0] , then 3x the value
#  if bar offset is [1] , then 2x
#  if bar offset  > [1] , then 1x, value stays the same
def rsicalc_adj0 = RSICalcx[0] * 3;
def rsicalc_adj1 = RSICalcx[1] * 2;
# count the remaining calc #'s
#  30 total formulas, -2 for [0] and [1] special formulas , 30-2 = 28 bars to count
#  use offset of [2] to start at 2 bars back, to skip over [0] and [1]
def rsicalc_adjz = sum(rsicalcx[2], 28);
# chg name from avg to sum (number is a sum, not an average)
#  add up 30 var values, current bar and 29 previous bars
def RSI30Daysum = rsicalc_adj0 + rsicalc_adj1 + rsicalc_adjz;

# assign the new variable to old variable, so addlabels and plots function
def RSI30DayAvg = RSI30Daysum;


# ####################################################

# these original formulas aren't used
#def RSICalc1 = if RSI > 70 then  3 else if RSI < 30 then  -3 else 0;
def RSICalc1 = if RSI[0] > 70 then  3 else if RSI[0] < 30 then  -3 else 0;
def RSICalc2 = if RSI[1] > 70 then  2 else if RSI[1] < 30 then  -2 else 0;
def RSICalc3 = if RSI[2] > 70 then  1 else if RSI[2] < 30 then  -1 else 0;
def RSICalc4 = if RSI[3] > 70 then  1 else if RSI[3] < 30 then  -1 else 0;
def RSICalc5 = if RSI[4] > 70 then  1 else if RSI[4] < 30 then  -1 else 0;
def RSICalc6 = if RSI[5] > 70 then  1 else if RSI[5] < 30 then  -1 else 0;
def RSICalc7 = if RSI[6] > 70 then  1 else if RSI[6] < 30 then  -1 else 0;
def RSICalc8 = if RSI[7] > 70 then  1 else if RSI[7] < 30 then  -1 else 0;
def RSICalc9 = if RSI[8] > 70 then  1 else if RSI[8] < 30 then  -1 else 0;
def RSICalc10 = if RSI[9] > 70 then  1 else if RSI[9] < 30 then  -1 else 0;
def RSICalc11 = if RSI[10] > 70 then  1 else if RSI[10] < 30 then  -1 else 0;
def RSICalc12 = if RSI[11] > 70 then  1 else if RSI[11] < 30 then  -1 else 0;
def RSICalc13 = if RSI[12] > 70 then  1 else if RSI[12] < 30 then  -1 else 0;
def RSICalc14 = if RSI[13] > 70 then  1 else if RSI[13] < 30 then  -1 else 0;
def RSICalc15 = if RSI[14] > 70 then  1 else if RSI[14] < 30 then  -1 else 0;
def RSICalc16 = if RSI[15] > 70 then  1 else if RSI[15] < 30 then  -1 else 0;
def RSICalc17 = if RSI[16] > 70 then  1 else if RSI[16] < 30 then  -1 else 0;
def RSICalc18 = if RSI[17] > 70 then  1 else if RSI[17] < 30 then  -1 else 0;
def RSICalc19 = if RSI[18] > 70 then  1 else if RSI[18] < 30 then  -1 else 0;
def RSICalc20 = if RSI[19] > 70 then  1 else if RSI[19] < 30 then  -1 else 0;
def RSICalc21 = if RSI[20] > 70 then  1 else if RSI[20] < 30 then  -1 else 0;
def RSICalc22 = if RSI[21] > 70 then  1 else if RSI[21] < 30 then  -1 else 0;
def RSICalc23 = if RSI[22] > 70 then  1 else if RSI[22] < 30 then  -1 else 0;
def RSICalc24 = if RSI[23] > 70 then  1 else if RSI[23] < 30 then  -1 else 0;
def RSICalc25 = if RSI[24] > 70 then  1 else if RSI[24] < 30 then  -1 else 0;
def RSICalc26 = if RSI[25] > 70 then  1 else if RSI[25] < 30 then  -1 else 0;
def RSICalc27 = if RSI[26] > 70 then  1 else if RSI[26] < 30 then  -1 else 0;
def RSICalc28 = if RSI[27] > 70 then  1 else if RSI[27] < 30 then  -1 else 0;
def RSICalc29 = if RSI[28] > 70 then  1 else if RSI[28] < 30 then  -1 else 0;
def RSICalc30 = if RSI[29] > 70 then  1 else if RSI[29] < 30 then  -1 else 0;


# original code. replaced above
#def RSI30DayAvg = RSICalc1 + RSICalc2 + RSICalc3 + RSICalc4 + RSICalc5 + RSICalc6 + RSICalc7 + RSICalc8 + RSICalc9 + RSICalc10 + RSICalc11 + RSICalc12 + RSICalc13 + RSICalc14 + RSICalc15 + RSICalc16 + RSICalc17 + RSICalc18 + RSICalc19 + RSICalc20 + RSICalc21 + RSICalc22 + RSICalc23 + RSICalc24 + RSICalc25 + RSICalc26 + RSICalc27 + RSICalc28 + RSICalc29 + RSICalc30;

# test data.  compare original total number and the value from new formulas
#input show_test_calc_values = no;
#addchartbubble(show_test_calc_values, 0, "av " + RSI30DayAvg + "\nsum " + RSI30Daysum, color.cyan, yes);


# ####################################################

AddLabel(RSI30DayAvg >= 10 and RSI30DayAvg < 20, " RSI SELL: " + RSI30DayAvg + "   ",  Color.ORANGE);
AddLabel(RSI30DayAvg >= 20, " RSI SELL: " + RSI30DayAvg + "   ",  Color.RED);
AddLabel(RSI30DayAvg <= -10 and RSI30DayAvg > -20, " RSI BUY: " + RSI30DayAvg + "   ",  Color.LIME);
AddLabel(RSI30DayAvg <= -20, " RSI BUY: " + RSI30DayAvg + "   ",  Color.DARK_GREEN);
plot TrendReversal5 = 1 - (((RSI30DayAvg >= 10 and RSI30DayAvg < 15) and close < MAvgExp7) / 2) ;
TrendReversal5.SetDefaultColor(GetColor(0)); #magenta
plot TrendReversal5a = 1 - (((RSI30DayAvg >= 16  and RSI30DayAvg < 25) and close < MAvgExp7) / 1.3) ;
TrendReversal5a.SetDefaultColor(GetColor(0)); #magenta
plot TrendReversal5b = 1 - ((RSI30DayAvg >= 25 and close < MAvgExp7) / 1.05) ;
TrendReversal5b.SetDefaultColor(GetColor(0)); #magenta
plot TrendReversal6 = ((RSI30DayAvg <= -15 and close > MAvgExp7 ) * .3) ;
TrendReversal6.SetDefaultColor(GetColor(6)); #green
plot TrendReversal6a = (((RSI30DayAvg <= -20 and RSI30DayAvg > -30) and close > MAvgExp7) * .85) ;
TrendReversal6a.SetDefaultColor(GetColor(6)); #green
TrendReversal6a.SetLineWeight(3);
TrendReversal5b.SetLineWeight(3);
TrendReversal6.SetLineWeight(2);
TrendReversal5a.SetLineWeight(2);
#End Code
 
i copied the code in post #1 and modified a couple of sections, to show other ways to write the formulas, using sum()
.... plot TrendReversalstrongbuy =
....the 30 rsicalc formulas
( i left the original code in , some commented out, some not). look for a string of #######
Python:
#DEEPWATER_THE_ONE_01

# -------------------
# 21-05-27
# halcyonguy
# simplify 2 sections  ( look for  ######## )
#   plot TrendReversalstrongbuy =
#   replace 30 rsicalc formulas to a few
# -------------------


#  5/20/2021 revision
#https://usethinkscript.com/threads/deepwater_the-one.6518/
declare lower;
input length = 20;
input length2 = 15;
input price = close;
input averageType = AverageType.WILDERS;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageTypeMACD = AverageType.EXPONENTIAL;

def Diff = MACD(fastLength, slowLength, MACDLength, averageTypeMACD).Diff;

def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

def RSI = 50 * (ChgRatio + 1);
def RSIAvg3 = MovingAverage(averageType, (RSI), 3);
def RSIAvg5 = MovingAverage(averageType, (RSI), 5);
def RSI3OverSoldpivit = RSIAvg3 > RSIAvg3[1] and RSIAvg3[1] > RSIAvg3[2] and RSIAvg3[2] < RSIAvg3[3] and RSIAvg3[3] < RSIAvg3 [4];
def RSI3OverBoughtpivit = RSIAvg3 < RSIAvg3[1] and RSIAvg3[1] < RSIAvg3[2] and RSIAvg3[2] > RSIAvg3[3] and RSIAvg3[3] > RSIAvg3 [4];
#--------------------5 day MA
input displace = 0;
input showBreakoutSignals = no;
def MAvgExp14 = ExpAverage(price[-displace], 14);
#--------------------oversold
def twoBarPivotMACD = Diff > Diff[1] and Diff[1] > Diff[2] and Diff[2] < Diff[3] and Diff[3] < Diff [4];

def overSoldRSI = RSI <= 32;
def overSoldRSIHeavy = RSI <= 30 and Diff < 0 and (close < close[7]);
def TrendReversalalert = (twoBarPivotMACD and Highest(overSoldRSI, 6) > 0) / 3;

Alert(TrendReversalalert, "Buy Alert");
plot TrendReversal1 = (twoBarPivotMACD and RSIAvg3 < 45 and Highest(overSoldRSIHeavy, 6) > 0) / 1.4;

# #####################

# simplify formula
#plot TrendReversalstrongbuy = ((TrendReversal1[1] > 0 or TrendReversal1[2] > 0 or TrendReversal1[3] > 0 or TrendReversal1[4] > 0 or TrendReversal1[5] > 0 or TrendReversal1[6] > 0 or TrendReversal1[7] > 0 or TrendReversal1[8] > 0 or TrendReversal1[9] > 0 or TrendReversal1[10] > 0 or TrendReversal1[11] > 0 or TrendReversal1[12] > 0 or TrendReversal1[13] > 0 or TrendReversal1[14] > 0) and twoBarPivotMACD and RSIAvg3 < 45 and Highest(overSoldRSIHeavy, 6) > 0) / 1.1;

# replace most of prev formula with   (sum(TrendReversal1[1], 14) > 0)

plot TrendReversalstrongbuy = (
(sum(TrendReversal1[1], 14) > 0)
and twoBarPivotMACD and RSIAvg3 < 45 and Highest(overSoldRSIHeavy, 6) > 0) / 1.1;

# #####################

plot TrendReversal = (twoBarPivotMACD and TrendReversalstrongbuy < 1 and Highest(overSoldRSI, 6) > 0) / 3;

TrendReversal.SetDefaultColor(GetColor(4));#yellow
TrendReversal1.SetDefaultColor(GetColor(6));#green
TrendReversalstrongbuy.SetDefaultColor(GetColor(6));#green
TrendReversalstrongbuy.SetLineWeight(3);
TrendReversal1.SetLineWeight(2);


AddLabel(yes, if  TrendReversal > 0 then "Buy" else "");
Alert( TrendReversalalert > 0,  "Chart is now Oversold ", Alert.BAR, Sound.Ring);
AddLabel(TrendReversalalert > 0
, "Chart is now Oversold ", Color.LIME);
#-----------------------Overbought
def twoBarPivotMACD1 = Diff < Diff[1] and Diff[1] < Diff[2] and Diff[2] > Diff[3] and Diff[3] > Diff [4];

def overboughtRSI = RSIAvg3 >= 65 and Diff > 0;
def TrendReversalalert20 = (twoBarPivotMACD1 and Highest(overboughtRSI[1], 7) > 0);
plot TrendReversal20 = 1 - (((RSIAvg3 >= 68 and RSI < RSIAvg3[2]) and RSI3OverBoughtpivit)/ 1.5) ;
plot TrendReversal20a = 1 - ((((RSIAvg3 >= 60 and RSIAvg3 < 68 )and RSI < RSIAvg3[2]) and RSI3OverBoughtpivit) / 4) ;

TrendReversal20.SetDefaultColor(GetColor(5)); #Red
TrendReversal20a.SetDefaultColor(GetColor(2)); #lt Red
TrendReversal20a.SetLineWeight(2);
TrendReversal20.SetLineWeight(3);
plot TrendReversal50 = 1 - ((RSIAvg5 >= 70 and close < MAvgExp14) / 2) ;
TrendReversal50.SetDefaultColor(GetColor(0)); #Red
TrendReversal50.SetLineWeight(3);
AddLabel(yes, if  TrendReversal20 < 1 then "Sell" else "");
Alert( TrendReversal20 < 1 ,  "Chart is now Overbought ", Alert.BAR, Sound.Ring);
AddLabel(TrendReversal20 < 1, "Chart is now Overbought ", Color.LIME);
input show_label = yes;
input show_bubble = no;
#--------------------------- Large 5X and 10X Volume Alert
input AverageLength = 100;
input VolumeMultiplier = 8;
input VolumeMultiplier2 = 5;
input MinutesAfterOpen = 30;

def AvgVol = Average(volume, AverageLength);
def VolX = (volume > AvgVol * VolumeMultiplier) ;
def Vol10X = (volume > AvgVol * 10) ;

Alert(VolX, Concat(GetSymbolPart(), " has a large volume spike." ), Alert.BAR, Sound.Chimes);
AddLabel(VolX > 0,  " Has 5X Volume Spike ", Color.LIGHT_GREEN);
Alert(Vol10X, Concat(GetSymbolPart(), " has a large volume spike." ), Alert.BAR, Sound.Chimes);
AddLabel(Vol10X > 0,  " Has 10X Volume Spike ", Color.LIGHT_GREEN);
#-------------------------------------GAP UP Price
def IsUp = close > open;
def IsDown = close < open;
def IsDoji = IsDoji();
def avgRange = 0.05 * Average(high - low, 20);
def GapUp =
    IsUp[1] and
    IsUp[0] and
    high[1] < low[0] and
    high[1] < open[0] and
(volume > AvgVol * 5) ;
Alert(GapUp, Concat(GetSymbolPart(), " GAPUP" ), Alert.BAR, Sound.Ring);
AddLabel(GapUp > 0,  " GAP Up  ", Color.LIGHT_GREEN);

#---------------------------------Large Price change 3%
def Priceup =
    IsUp[1] and
    IsUp[0] and
    high[1] < high[0] and
    high[2] * 1.02 < high[0] and
    high[3] * 1.03 < high[0] and
(volume > AvgVol * 3) ;
Alert(Priceup, Concat(GetSymbolPart(), " Price JUMP" ), Alert.BAR, Sound.Bell);
AddLabel(Priceup > 0,  " Price JUMP  ", Color.CYAN);

#---------------------------------HugePrice change 6%
def Priceup2 =
    IsUp[1] and
    IsUp[0] and
    high[1] < high[0] and
    high[3] * 1.04 < high[0] and
    high[4] * 1.06 < high[0] and
(volume > AvgVol * 3) ;
Alert(Priceup2, Concat(GetSymbolPart(), " JUMP! JUMP! JUMP" ), Alert.BAR, Sound.Chimes);
AddLabel(Priceup2 > 0,  " JUMP! JUMP! JUMP  ", Color.LIGHT_RED);

#-----------------------------------------------------------------------------------------
#-----------RSI cumulative running total
def MAvgExp7 = ExpAverage(price[-displace], 7);
def RSICalc = 50 * (ChgRatio + 1);

# ####################################################

# redo the following 30 formulas and the total formula, into just a few formulas
# these could be done in 2 formulas, but i left them separated, to make it easier to read
#  chg constants to variables
def rsiupper = 70;
def rsilower = 30;
# instead of defining 30 variables on each bar, set 1 var, then read it later and modify as needed
#  set a value for each bar,  -1 or 1
def RSICalcx = if RSI[0] > rsiupper then 1 else if RSI[0] < rsilower then  -1 else 0;
# calc a new calc value from rsicalcx, depending on offset
#  if bar offset is [0] , then 3x the value
#  if bar offset is [1] , then 2x
#  if bar offset  > [1] , then 1x, value stays the same
def rsicalc_adj0 = RSICalcx[0] * 3;
def rsicalc_adj1 = RSICalcx[1] * 2;
# count the remaining calc #'s
#  30 total formulas, -2 for [0] and [1] special formulas , 30-2 = 28 bars to count
#  use offset of [2] to start at 2 bars back, to skip over [0] and [1]
def rsicalc_adjz = sum(rsicalcx[2], 28);
# chg name from avg to sum (number is a sum, not an average)
#  add up 30 var values, current bar and 29 previous bars
def RSI30Daysum = rsicalc_adj0 + rsicalc_adj1 + rsicalc_adjz;

# assign the new variable to old variable, so addlabels and plots function
def RSI30DayAvg = RSI30Daysum;


# ####################################################

# these original formulas aren't used
#def RSICalc1 = if RSI > 70 then  3 else if RSI < 30 then  -3 else 0;
def RSICalc1 = if RSI[0] > 70 then  3 else if RSI[0] < 30 then  -3 else 0;
def RSICalc2 = if RSI[1] > 70 then  2 else if RSI[1] < 30 then  -2 else 0;
def RSICalc3 = if RSI[2] > 70 then  1 else if RSI[2] < 30 then  -1 else 0;
def RSICalc4 = if RSI[3] > 70 then  1 else if RSI[3] < 30 then  -1 else 0;
def RSICalc5 = if RSI[4] > 70 then  1 else if RSI[4] < 30 then  -1 else 0;
def RSICalc6 = if RSI[5] > 70 then  1 else if RSI[5] < 30 then  -1 else 0;
def RSICalc7 = if RSI[6] > 70 then  1 else if RSI[6] < 30 then  -1 else 0;
def RSICalc8 = if RSI[7] > 70 then  1 else if RSI[7] < 30 then  -1 else 0;
def RSICalc9 = if RSI[8] > 70 then  1 else if RSI[8] < 30 then  -1 else 0;
def RSICalc10 = if RSI[9] > 70 then  1 else if RSI[9] < 30 then  -1 else 0;
def RSICalc11 = if RSI[10] > 70 then  1 else if RSI[10] < 30 then  -1 else 0;
def RSICalc12 = if RSI[11] > 70 then  1 else if RSI[11] < 30 then  -1 else 0;
def RSICalc13 = if RSI[12] > 70 then  1 else if RSI[12] < 30 then  -1 else 0;
def RSICalc14 = if RSI[13] > 70 then  1 else if RSI[13] < 30 then  -1 else 0;
def RSICalc15 = if RSI[14] > 70 then  1 else if RSI[14] < 30 then  -1 else 0;
def RSICalc16 = if RSI[15] > 70 then  1 else if RSI[15] < 30 then  -1 else 0;
def RSICalc17 = if RSI[16] > 70 then  1 else if RSI[16] < 30 then  -1 else 0;
def RSICalc18 = if RSI[17] > 70 then  1 else if RSI[17] < 30 then  -1 else 0;
def RSICalc19 = if RSI[18] > 70 then  1 else if RSI[18] < 30 then  -1 else 0;
def RSICalc20 = if RSI[19] > 70 then  1 else if RSI[19] < 30 then  -1 else 0;
def RSICalc21 = if RSI[20] > 70 then  1 else if RSI[20] < 30 then  -1 else 0;
def RSICalc22 = if RSI[21] > 70 then  1 else if RSI[21] < 30 then  -1 else 0;
def RSICalc23 = if RSI[22] > 70 then  1 else if RSI[22] < 30 then  -1 else 0;
def RSICalc24 = if RSI[23] > 70 then  1 else if RSI[23] < 30 then  -1 else 0;
def RSICalc25 = if RSI[24] > 70 then  1 else if RSI[24] < 30 then  -1 else 0;
def RSICalc26 = if RSI[25] > 70 then  1 else if RSI[25] < 30 then  -1 else 0;
def RSICalc27 = if RSI[26] > 70 then  1 else if RSI[26] < 30 then  -1 else 0;
def RSICalc28 = if RSI[27] > 70 then  1 else if RSI[27] < 30 then  -1 else 0;
def RSICalc29 = if RSI[28] > 70 then  1 else if RSI[28] < 30 then  -1 else 0;
def RSICalc30 = if RSI[29] > 70 then  1 else if RSI[29] < 30 then  -1 else 0;


# original code. replaced above
#def RSI30DayAvg = RSICalc1 + RSICalc2 + RSICalc3 + RSICalc4 + RSICalc5 + RSICalc6 + RSICalc7 + RSICalc8 + RSICalc9 + RSICalc10 + RSICalc11 + RSICalc12 + RSICalc13 + RSICalc14 + RSICalc15 + RSICalc16 + RSICalc17 + RSICalc18 + RSICalc19 + RSICalc20 + RSICalc21 + RSICalc22 + RSICalc23 + RSICalc24 + RSICalc25 + RSICalc26 + RSICalc27 + RSICalc28 + RSICalc29 + RSICalc30;

# test data.  compare original total number and the value from new formulas
#input show_test_calc_values = no;
#addchartbubble(show_test_calc_values, 0, "av " + RSI30DayAvg + "\nsum " + RSI30Daysum, color.cyan, yes);


# ####################################################

AddLabel(RSI30DayAvg >= 10 and RSI30DayAvg < 20, " RSI SELL: " + RSI30DayAvg + "   ",  Color.ORANGE);
AddLabel(RSI30DayAvg >= 20, " RSI SELL: " + RSI30DayAvg + "   ",  Color.RED);
AddLabel(RSI30DayAvg <= -10 and RSI30DayAvg > -20, " RSI BUY: " + RSI30DayAvg + "   ",  Color.LIME);
AddLabel(RSI30DayAvg <= -20, " RSI BUY: " + RSI30DayAvg + "   ",  Color.DARK_GREEN);
plot TrendReversal5 = 1 - (((RSI30DayAvg >= 10 and RSI30DayAvg < 15) and close < MAvgExp7) / 2) ;
TrendReversal5.SetDefaultColor(GetColor(0)); #magenta
plot TrendReversal5a = 1 - (((RSI30DayAvg >= 16  and RSI30DayAvg < 25) and close < MAvgExp7) / 1.3) ;
TrendReversal5a.SetDefaultColor(GetColor(0)); #magenta
plot TrendReversal5b = 1 - ((RSI30DayAvg >= 25 and close < MAvgExp7) / 1.05) ;
TrendReversal5b.SetDefaultColor(GetColor(0)); #magenta
plot TrendReversal6 = ((RSI30DayAvg <= -15 and close > MAvgExp7 ) * .3) ;
TrendReversal6.SetDefaultColor(GetColor(6)); #green
plot TrendReversal6a = (((RSI30DayAvg <= -20 and RSI30DayAvg > -30) and close > MAvgExp7) * .85) ;
TrendReversal6a.SetDefaultColor(GetColor(6)); #green
TrendReversal6a.SetLineWeight(3);
TrendReversal5b.SetLineWeight(3);
TrendReversal6.SetLineWeight(2);
TrendReversal5a.SetLineWeight(2);
#End Code
I was always kind of a spaghetti coder. It works but it ain't always pretty
 
Ok if I reduce the screen size they show up more. If I expand they disappear. Is there a certain setting it should be set on? TY for answering i really appreciate it.
 
Ok if I reduce the screen size they show up more. If I expand they disappear. Is there a certain setting it should be set on? TY for answering i really appreciate it.
Different people set up their charts different ways. Best friend you got for TOS learning is Youtube. I prefer a 2Min 1 D or 2D chart but I also linked my main chart to side charts of different times like a 90 day chart. I will also zoom in on my 1D 2min chart or go to a !D 1 Min Chart and zoom. Not sure that answers your question but the spikes once set don't disappear. They may be off to the side out of view depending on your zoom timeframe area you selected.
 

Watch List​

of STRONG BUY and STRONG SELL PORTION OF DEEPWATER_THE_ONE

By Default the Watchlist Selects Daily Charts. You will need to change from 'D' to '2m' or '1m' charts within the watchlist setup or whatever time period you prefer​

WatchList Version of DEEPWATER_THE_ONE Strong Buy/Strong sell Code is on Page 1 second Entry.
 
Great work, and thank you @Deepwater for sharing your wisdom with all of us. I have this indicator on every chart that I use and has been a GREAT predictor of the direction and trends. I just got the watchlist column set up yesterday and after a few scans I found a "1" and immediately was able to scalp a quick profit (thanks again).

One request/question... Is there any way to set up a scan to search for the big green spike? That would be an awesome addition.
 
Great work, and thank you @Deepwater for sharing your wisdom with all of us. I have this indicator on every chart that I use and has been a GREAT predictor of the direction and trends. I just got the watchlist column set up yesterday and after a few scans I found a "1" and immediately was able to scalp a quick profit (thanks again).

One request/question... Is there any way to set up a scan to search for the big green spike? That would be an awesome addition.
I created a Buy scan and placed the code on Page 1 the 4th entry is now the scan for the strong buy signal. You need to add other discriminator filters like volume, price etc. Youtube will help you set up custom scans if you can't figure it out.

https://usethinkscript.com/threads/deepwater_the-one.6518/
 
Sell signal SCAN. Follow Page 1 entry 4 for guidance but this is the code for a sell signal scan instead of buy signal scan,.

Code:
#DEEPWATER_THE ONE 5/20/2021 WATCHLIST STRONG SELL
#https://usethinkscript.com/threads/deepwater_the-one.6518/

input length = 20;
input length2 = 15;
input price = close;
input averageType = AverageType.WILDERS;
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageTypeMACD = AverageType.EXPONENTIAL;
def Diff = MACD(fastLength, slowLength, MACDLength, averageTypeMACD).Diff;
def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);
def RSIAvg3 = MovingAverage(averageType, (RSI), 3);
def RSIAvg5 = MovingAverage(averageType, (RSI), 5);
def RSI3OverSoldpivit = RSIAvg3 > RSIAvg3[1] and RSIAvg3[1] > RSIAvg3[2] and RSIAvg3[2] < RSIAvg3[3] and RSIAvg3[3] < RSIAvg3 [4];
def RSI3OverBoughtpivit = RSIAvg3 < RSIAvg3[1] and RSIAvg3[1] < RSIAvg3[2] and RSIAvg3[2] > RSIAvg3[3] and RSIAvg3[3] > RSIAvg3 [4];
#--------------------5 day MA
input displace = 0;
input showBreakoutSignals = no;
def MAvgExp14 = ExpAverage(price[-displace], 14);
#--------------------oversold
def twoBarPivotMACD = Diff > Diff[1] and Diff[1] > Diff[2] and Diff[2] < Diff[3] and Diff[3] < Diff [4];
def overSoldRSI = RSI <= 32;
def overSoldRSIHeavy = RSI <= 30 and Diff < 0 and (close < close[7]);
def TrendReversalalert = (twoBarPivotMACD and Highest(overSoldRSI, 6) > 0) / 3;
def StrongBuy = (twoBarPivotMACD and RSIAvg3 < 45 and Highest(overSoldRSIHeavy, 6) > 0);

#-----------------------Overbought
def twoBarPivotMACD1 = Diff < Diff[1] and Diff[1] < Diff[2] and Diff[2] > Diff[3] and Diff[3] > Diff [4];

def overboughtRSI = RSIAvg3 >= 65 and Diff > 0;
def TrendReversalalert20 = (twoBarPivotMACD1 and Highest(overboughtRSI[1], 7) > 0);
def StrongSell = (((RSIAvg3 >= 68 and RSI < RSIAvg3[2]) and RSI3OverBoughtpivit)) ;

plot TrendReversal1 = (StrongSell + StrongSell[1] + StrongSell[2] );


#End Code
 
Last edited:
Sell signal SCAN. Follow Page 1 entry 4 for guidance but this is the code for a sell signal scan instead of buy signal scan,.

Code:
#DEEPWATER_THE ONE 5/20/2021 WATCHLIST STRONG SELL
#https://usethinkscript.com/threads/deepwater_the-one.6518/

input length = 20;
input length2 = 15;
input price = close;
input averageType = AverageType.WILDERS;
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageTypeMACD = AverageType.EXPONENTIAL;
def Diff = MACD(fastLength, slowLength, MACDLength, averageTypeMACD).Diff;
def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);
def RSIAvg3 = MovingAverage(averageType, (RSI), 3);
def RSIAvg5 = MovingAverage(averageType, (RSI), 5);
def RSI3OverSoldpivit = RSIAvg3 > RSIAvg3[1] and RSIAvg3[1] > RSIAvg3[2] and RSIAvg3[2] < RSIAvg3[3] and RSIAvg3[3] < RSIAvg3 [4];
def RSI3OverBoughtpivit = RSIAvg3 < RSIAvg3[1] and RSIAvg3[1] < RSIAvg3[2] and RSIAvg3[2] > RSIAvg3[3] and RSIAvg3[3] > RSIAvg3 [4];
#--------------------5 day MA
input displace = 0;
input showBreakoutSignals = no;
def MAvgExp14 = ExpAverage(price[-displace], 14);
#--------------------oversold
def twoBarPivotMACD = Diff > Diff[1] and Diff[1] > Diff[2] and Diff[2] < Diff[3] and Diff[3] < Diff [4];
def overSoldRSI = RSI <= 32;
def overSoldRSIHeavy = RSI <= 30 and Diff < 0 and (close < close[7]);
def TrendReversalalert = (twoBarPivotMACD and Highest(overSoldRSI, 6) > 0) / 3;
def StrongBuy = (twoBarPivotMACD and RSIAvg3 < 45 and Highest(overSoldRSIHeavy, 6) > 0);

#-----------------------Overbought
def twoBarPivotMACD1 = Diff < Diff[1] and Diff[1] < Diff[2] and Diff[2] > Diff[3] and Diff[3] > Diff [4];

def overboughtRSI = RSIAvg3 >= 65 and Diff > 0;
def TrendReversalalert20 = (twoBarPivotMACD1 and Highest(overboughtRSI[1], 7) > 0);
def StrongSell = (((RSIAvg3 >= 68 and RSI < RSIAvg3[2]) and RSI3OverBoughtpivit)) ;

plot TrendReversal1 = (StrongSell + StrongSell[1] + StrongSell[2] );


#End Code
Thank you very much for the sell signal scan! It works for me!
 
Sell signal SCAN. Follow Page 1 entry 4 for guidance but this is the code for a sell signal scan instead of buy signal scan,.

Code:
#DEEPWATER_THE ONE 5/20/2021 WATCHLIST STRONG SELL
#https://usethinkscript.com/threads/deepwater_the-one.6518/

input length = 20;
input length2 = 15;
input price = close;
input averageType = AverageType.WILDERS;
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageTypeMACD = AverageType.EXPONENTIAL;
def Diff = MACD(fastLength, slowLength, MACDLength, averageTypeMACD).Diff;
def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);
def RSIAvg3 = MovingAverage(averageType, (RSI), 3);
def RSIAvg5 = MovingAverage(averageType, (RSI), 5);
def RSI3OverSoldpivit = RSIAvg3 > RSIAvg3[1] and RSIAvg3[1] > RSIAvg3[2] and RSIAvg3[2] < RSIAvg3[3] and RSIAvg3[3] < RSIAvg3 [4];
def RSI3OverBoughtpivit = RSIAvg3 < RSIAvg3[1] and RSIAvg3[1] < RSIAvg3[2] and RSIAvg3[2] > RSIAvg3[3] and RSIAvg3[3] > RSIAvg3 [4];
#--------------------5 day MA
input displace = 0;
input showBreakoutSignals = no;
def MAvgExp14 = ExpAverage(price[-displace], 14);
#--------------------oversold
def twoBarPivotMACD = Diff > Diff[1] and Diff[1] > Diff[2] and Diff[2] < Diff[3] and Diff[3] < Diff [4];
def overSoldRSI = RSI <= 32;
def overSoldRSIHeavy = RSI <= 30 and Diff < 0 and (close < close[7]);
def TrendReversalalert = (twoBarPivotMACD and Highest(overSoldRSI, 6) > 0) / 3;
def StrongBuy = (twoBarPivotMACD and RSIAvg3 < 45 and Highest(overSoldRSIHeavy, 6) > 0);

#-----------------------Overbought
def twoBarPivotMACD1 = Diff < Diff[1] and Diff[1] < Diff[2] and Diff[2] > Diff[3] and Diff[3] > Diff [4];

def overboughtRSI = RSIAvg3 >= 65 and Diff > 0;
def TrendReversalalert20 = (twoBarPivotMACD1 and Highest(overboughtRSI[1], 7) > 0);
def StrongSell = (((RSIAvg3 >= 68 and RSI < RSIAvg3[2]) and RSI3OverBoughtpivit)) ;

plot TrendReversal1 = (StrongSell + StrongSell[1] + StrongSell[2] );


#End Code
Very Interesting! I find it better to pass on any trade with conflicting signals, do you agree? For example, if I get a pump, pump, pump breakout but momentum decreasing = pass.
 
some examples would be awesome!
Some of you may be following the WSB Reddit group. One of their favorites is AMC. I bought on the Green Spike Pre-Markey (Strong Buy signal) but because of FOMO and Short Squeeze possibilities I did not sell even though I got two strong sell signals (PM RED Stalactite formation) during the day but I would of made money had I sold then. I can tell you that ignoring these RED Stalactite signals is usually a BAD IDEA but I had my reasons) I then got a Strong Sell Signal Afterhours and decided to take profits. 1D 1M Chart below.

XaBaEj4.jpg
 
Last edited:
Here is another of CLOV. Strong Buy signal at Open followed by 2 more Stronger Buy signals. Then Sell signals later in the morning. You start getting that RED Stalactite formation the chart is screaming for you to sell. It may not be the top but it usually is.

6Jc2iaR.jpg
 
Last edited:

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
245 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