Count number of active RSI chart bubbles and create alert

msmmlee

New member
Plus
Hi all,

I am working on the below RSI indicator that gives me up and down chart bubbles for all five of the average types (Wilders, exponential, weighted, simple and hull). I want to add a counter and an alert if 3 or 4 of the 5 average types are up or down within a bar. Building multiple indicators within one study is new for me so I might have more coding than needed but the chart bubbles are working... I just don't know how to add a counter. Here's what I've got so far. I appreciate any help you can provide.


#declare lower;

input length = 14;
input over_Bought = 70;
input over_Sold = 30;
input price = close;

#input showBreakoutSignals = no;

input averageTypeWL = AverageType.WILDERS;
input averageTypeEX = AverageType.EXPONENTIAL;
input averageTypeWT = AverageType.WEIGHTED;
input averageTypeS = AverageType.SIMPLE;
input averageTypeHL = AverageType.HULL;

def NetChgAvgWL = MovingAverage(averageTypeWL, price - price[1], length);
def NetChgAvgEX = MovingAverage(averageTypeEX, price - price[1], length);
def NetChgAvgWT = MovingAverage(averageTypeWT, price - price[1], length);
def NetChgAvgS = MovingAverage(averageTypeS, price - price[1], length);
def NetChgAvgHL = MovingAverage(averageTypeHL, price - price[1], length);

def TotChgAvgWL = MovingAverage(averageTypeWL, AbsValue(price - price[1]), length);
def TotChgAvgEX = MovingAverage(averageTypeEX, AbsValue(price - price[1]), length);
def TotChgAvgWT = MovingAverage(averageTypeWT, AbsValue(price - price[1]), length);
def TotChgAvgS = MovingAverage(averageTypeS, AbsValue(price - price[1]), length);
def TotChgAvgHL = MovingAverage(averageTypeHL, AbsValue(price - price[1]), length);

def ChgRatioWL = if TotChgAvgWL != 0 then NetChgAvgWL / TotChgAvgWL else 0;
def ChgRatioEX = if TotChgAvgEX != 0 then NetChgAvgEX / TotChgAvgEX else 0;
def ChgRatioWT = if TotChgAvgWT != 0 then NetChgAvgWT / TotChgAvgWT else 0;
def ChgRatioS = if TotChgAvgS != 0 then NetChgAvgS / TotChgAvgS else 0;
def ChgRatioHL = if TotChgAvgHL != 0 then NetChgAvgHL / TotChgAvgHL else 0;

def WLRSI = 50 * (ChgRatioWL + 1);
def EXRSI = 50 * (ChgRatioEX + 1);
def WTRSI = 50 * (ChgRatioWT + 1);
def SRSI = 50 * (ChgRatioS + 1);
def HLRSI = 50 * (ChgRatioHL + 1);

def OverSold = over_Sold;
def OverBought = over_Bought;

def WLUpSignal = if WLRSI crosses above OverSold then OverSold else Double.NaN;
def EXUpSignal = if EXRSI crosses above OverSold then OverSold else Double.NaN;
def WTUpSignal = if WTRSI crosses above OverSold then OverSold else Double.NaN;
def SUpSignal = if SRSI crosses above OverSold then OverSold else Double.NaN;
def HLUpSignal = if HLRSI crosses above OverSold then OverSold else Double.NaN;

def WLDownSignal = if WLRSI crosses below OverBought then OverBought else Double.NaN;
def EXDownSignal = if EXRSI crosses below OverBought then OverBought else Double.NaN;
def WTDownSignal = if WTRSI crosses below OverBought then OverBought else Double.NaN;
def SDownSignal = if SRSI crosses below OverBought then OverBought else Double.NaN;
def HLDownSignal = if HLRSI crosses below OverBought then OverBought else Double.NaN;

plot mid = 50;
plot WLmidUpSignal = if WLRSI crosses above mid then mid else Double.NaN;
plot EXmidUpSignal = if EXRSI crosses above mid then mid else Double.NaN;
plot WTmidUpSignal = if WTRSI crosses above mid then mid else Double.NaN;
plot SmidUpSignal = if SRSI crosses above mid then mid else Double.NaN;
plot HLmidUpSignal = if HLRSI crosses above mid then mid else Double.NaN;

plot WLmidDownSignal = if WLRSI crosses below mid then mid else Double.NaN;
plot EXmidDownSignal = if EXRSI crosses below mid then mid else Double.NaN;
plot WTmidDownSignal = if WTRSI crosses below mid then mid else Double.NaN;
plot SmidDownSignal = if SRSI crosses below mid then mid else Double.NaN;
plot HLmidDownSignal = if HLRSI crosses below mid then mid else Double.NaN;

WLmidUpSignal.SetDefaultColor(Color.UPTICK);
EXmidUpSignal.SetDefaultColor(Color.UPTICK);
WTmidUpSignal.SetDefaultColor(Color.UPTICK);
SmidUpSignal.SetDefaultColor(Color.UPTICK);
HLmidUpSignal.SetDefaultColor(Color.UPTICK);

WLmidUpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
EXmidUpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
WTmidUpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
SmidUpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
HLmidUpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);

WLmidDownSignal.SetDefaultColor(Color.DOWNTICK);
EXmidDownSignal.SetDefaultColor(Color.DOWNTICK);
WTmidDownSignal.SetDefaultColor(Color.DOWNTICK);
SmidDownSignal.SetDefaultColor(Color.DOWNTICK);
HLmidDownSignal.SetDefaultColor(Color.DOWNTICK);

WLmidDownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
EXmidDownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
WTmidDownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SmidDownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
HLmidDownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);


AddChartBubble(WLmidUpSignal, low, "WL", Color.GREEN, no);
AddChartBubble(EXmidUpSignal, low, "E", Color.GREEN, no);
AddChartBubble(WTmidUpSignal, low, "WT", Color.GREEN, no);
AddChartBubble(SmidUpSignal, low, "S", Color.GREEN, no);
AddChartBubble(HLmidUpSignal, low, "H", Color.GREEN, no);

AddChartBubble(WLmidDownSignal, high, "WL", Color.RED);
AddChartBubble(EXmidDownSignal, high, "E", Color.RED);
AddChartBubble(WTmidDownSignal, high, "WT", Color.RED);
AddChartBubble(SmidDownSignal, high, "S", Color.RED);
AddChartBubble(HLmidDownSignal, high, "H", Color.RED);

#End of code
 
Solution
I think it's this section here where the RSI crosses above/below the OverSold/OverBought... am I missing something?:

def OverSold = over_Sold;
def OverBought = over_Bought;

def WLUpSignal = if WLRSI crosses above OverSold then OverSold else Double.NaN;
def EXUpSignal = if EXRSI crosses above OverSold then OverSold else Double.NaN;
def WTUpSignal = if WTRSI crosses above OverSold then OverSold else Double.NaN;
def SUpSignal = if SRSI crosses above OverSold then OverSold else Double.NaN;
def HLUpSignal = if HLRSI crosses above OverSold then OverSold else Double.NaN;

def WLDownSignal = if WLRSI crosses below OverBought then OverBought else Double.NaN;
def EXDownSignal = if EXRSI crosses below OverBought then OverBought else...
Hi all,

I am working on the below RSI indicator that gives me up and down chart bubbles for all five of the average types (Wilders, exponential, weighted, simple and hull). I want to add a counter and an alert if 3 or 4 of the 5 average types are up or down within a bar. Building multiple indicators within one study is new for me so I might have more coding than needed but the chart bubbles are working... I just don't know how to add a counter. Here's what I've got so far. I appreciate any help you can provide.


#declare lower;

input length = 14;
input over_Bought = 70;
input over_Sold = 30;
input price = close;

#input showBreakoutSignals = no;

input averageTypeWL = AverageType.WILDERS;
input averageTypeEX = AverageType.EXPONENTIAL;
input averageTypeWT = AverageType.WEIGHTED;
input averageTypeS = AverageType.SIMPLE;
input averageTypeHL = AverageType.HULL;

def NetChgAvgWL = MovingAverage(averageTypeWL, price - price[1], length);
def NetChgAvgEX = MovingAverage(averageTypeEX, price - price[1], length);
def NetChgAvgWT = MovingAverage(averageTypeWT, price - price[1], length);
def NetChgAvgS = MovingAverage(averageTypeS, price - price[1], length);
def NetChgAvgHL = MovingAverage(averageTypeHL, price - price[1], length);

def TotChgAvgWL = MovingAverage(averageTypeWL, AbsValue(price - price[1]), length);
def TotChgAvgEX = MovingAverage(averageTypeEX, AbsValue(price - price[1]), length);
def TotChgAvgWT = MovingAverage(averageTypeWT, AbsValue(price - price[1]), length);
def TotChgAvgS = MovingAverage(averageTypeS, AbsValue(price - price[1]), length);
def TotChgAvgHL = MovingAverage(averageTypeHL, AbsValue(price - price[1]), length);

def ChgRatioWL = if TotChgAvgWL != 0 then NetChgAvgWL / TotChgAvgWL else 0;
def ChgRatioEX = if TotChgAvgEX != 0 then NetChgAvgEX / TotChgAvgEX else 0;
def ChgRatioWT = if TotChgAvgWT != 0 then NetChgAvgWT / TotChgAvgWT else 0;
def ChgRatioS = if TotChgAvgS != 0 then NetChgAvgS / TotChgAvgS else 0;
def ChgRatioHL = if TotChgAvgHL != 0 then NetChgAvgHL / TotChgAvgHL else 0;

def WLRSI = 50 * (ChgRatioWL + 1);
def EXRSI = 50 * (ChgRatioEX + 1);
def WTRSI = 50 * (ChgRatioWT + 1);
def SRSI = 50 * (ChgRatioS + 1);
def HLRSI = 50 * (ChgRatioHL + 1);

def OverSold = over_Sold;
def OverBought = over_Bought;

def WLUpSignal = if WLRSI crosses above OverSold then OverSold else Double.NaN;
def EXUpSignal = if EXRSI crosses above OverSold then OverSold else Double.NaN;
def WTUpSignal = if WTRSI crosses above OverSold then OverSold else Double.NaN;
def SUpSignal = if SRSI crosses above OverSold then OverSold else Double.NaN;
def HLUpSignal = if HLRSI crosses above OverSold then OverSold else Double.NaN;

def WLDownSignal = if WLRSI crosses below OverBought then OverBought else Double.NaN;
def EXDownSignal = if EXRSI crosses below OverBought then OverBought else Double.NaN;
def WTDownSignal = if WTRSI crosses below OverBought then OverBought else Double.NaN;
def SDownSignal = if SRSI crosses below OverBought then OverBought else Double.NaN;
def HLDownSignal = if HLRSI crosses below OverBought then OverBought else Double.NaN;

plot mid = 50;
plot WLmidUpSignal = if WLRSI crosses above mid then mid else Double.NaN;
plot EXmidUpSignal = if EXRSI crosses above mid then mid else Double.NaN;
plot WTmidUpSignal = if WTRSI crosses above mid then mid else Double.NaN;
plot SmidUpSignal = if SRSI crosses above mid then mid else Double.NaN;
plot HLmidUpSignal = if HLRSI crosses above mid then mid else Double.NaN;

plot WLmidDownSignal = if WLRSI crosses below mid then mid else Double.NaN;
plot EXmidDownSignal = if EXRSI crosses below mid then mid else Double.NaN;
plot WTmidDownSignal = if WTRSI crosses below mid then mid else Double.NaN;
plot SmidDownSignal = if SRSI crosses below mid then mid else Double.NaN;
plot HLmidDownSignal = if HLRSI crosses below mid then mid else Double.NaN;

WLmidUpSignal.SetDefaultColor(Color.UPTICK);
EXmidUpSignal.SetDefaultColor(Color.UPTICK);
WTmidUpSignal.SetDefaultColor(Color.UPTICK);
SmidUpSignal.SetDefaultColor(Color.UPTICK);
HLmidUpSignal.SetDefaultColor(Color.UPTICK);

WLmidUpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
EXmidUpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
WTmidUpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
SmidUpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
HLmidUpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);

WLmidDownSignal.SetDefaultColor(Color.DOWNTICK);
EXmidDownSignal.SetDefaultColor(Color.DOWNTICK);
WTmidDownSignal.SetDefaultColor(Color.DOWNTICK);
SmidDownSignal.SetDefaultColor(Color.DOWNTICK);
HLmidDownSignal.SetDefaultColor(Color.DOWNTICK);

WLmidDownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
EXmidDownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
WTmidDownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SmidDownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
HLmidDownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);


AddChartBubble(WLmidUpSignal, low, "WL", Color.GREEN, no);
AddChartBubble(EXmidUpSignal, low, "E", Color.GREEN, no);
AddChartBubble(WTmidUpSignal, low, "WT", Color.GREEN, no);
AddChartBubble(SmidUpSignal, low, "S", Color.GREEN, no);
AddChartBubble(HLmidUpSignal, low, "H", Color.GREEN, no);

AddChartBubble(WLmidDownSignal, high, "WL", Color.RED);
AddChartBubble(EXmidDownSignal, high, "E", Color.RED);
AddChartBubble(WTmidDownSignal, high, "WT", Color.RED);
AddChartBubble(SmidDownSignal, high, "S", Color.RED);
AddChartBubble(HLmidDownSignal, high, "H", Color.RED);

#End of code
define what has to happen for an average to be 'up'
 

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

define what has to happen for an average to be 'up'

I think it's this section here where the RSI crosses above/below the OverSold/OverBought... am I missing something?:

def OverSold = over_Sold;
def OverBought = over_Bought;

def WLUpSignal = if WLRSI crosses above OverSold then OverSold else Double.NaN;
def EXUpSignal = if EXRSI crosses above OverSold then OverSold else Double.NaN;
def WTUpSignal = if WTRSI crosses above OverSold then OverSold else Double.NaN;
def SUpSignal = if SRSI crosses above OverSold then OverSold else Double.NaN;
def HLUpSignal = if HLRSI crosses above OverSold then OverSold else Double.NaN;

def WLDownSignal = if WLRSI crosses below OverBought then OverBought else Double.NaN;
def EXDownSignal = if EXRSI crosses below OverBought then OverBought else Double.NaN;
def WTDownSignal = if WTRSI crosses below OverBought then OverBought else Double.NaN;
def SDownSignal = if SRSI crosses below OverBought then OverBought else Double.NaN;
def HLDownSignal = if HLRSI crosses below OverBought then OverBought else Double.NaN;
 
I think it's this section here where the RSI crosses above/below the OverSold/OverBought... am I missing something?:

def OverSold = over_Sold;
def OverBought = over_Bought;

def WLUpSignal = if WLRSI crosses above OverSold then OverSold else Double.NaN;
def EXUpSignal = if EXRSI crosses above OverSold then OverSold else Double.NaN;
def WTUpSignal = if WTRSI crosses above OverSold then OverSold else Double.NaN;
def SUpSignal = if SRSI crosses above OverSold then OverSold else Double.NaN;
def HLUpSignal = if HLRSI crosses above OverSold then OverSold else Double.NaN;

def WLDownSignal = if WLRSI crosses below OverBought then OverBought else Double.NaN;
def EXDownSignal = if EXRSI crosses below OverBought then OverBought else Double.NaN;
def WTDownSignal = if WTRSI crosses below OverBought then OverBought else Double.NaN;
def SDownSignal = if SRSI crosses below OverBought then OverBought else Double.NaN;
def HLDownSignal = if HLRSI crosses below OverBought then OverBought else Double.NaN;

sorry, i should have looked at this before commenting.
i sometimes try to get people to describe their code to get them thinking about it and maybe a solution.

----------------------

added bubbles with counts of the bubbles
changed several things,
it's not a good idea to reference plot variables. if you want to turn off the plot, then the value isn't available. added def's for some plot formulas. then created new plots , that can be turned on or off.
moved arrows to be near bars, not at 50.
added price shifts to arrows and bubbles, so no overlaps.

can choose a minimum quantity of bubbles. default is 3. if there are at least 3 , then bubbles are shown.
can choose to show, arrows, bubbles, totals.
can show all or just those above the minimum.

input ooooooooooooo = 0;
this is a dummy input. it acts as a separator, between some yes/no and the average types. if you have many inputs together, it gets hard to find a specific input. i like to separate different groups of inputs.

Code:
#rsi_5x_count_ups

#https://usethinkscript.com/threads/count-number-of-active-rsi-chart-bubbles-and-create-alert.20058/
#Count number of active RSI chart bubbles and create alert

def na = double.nan;
def bn = barnumber();

input length = 14;
input over_Bought = 70;
input over_Sold = 30;
input price = close;
#input showBreakoutSignals = no;
input show_bubbles = yes;
input show_bubble_totals = yes;
input show_arrows = yes;
input min_count = 3;
input show_only_min_count_items = yes;
input ooooooooooooo = 0;

input averageTypeWL = AverageType.WILDERS;
input averageTypeEX = AverageType.EXPONENTIAL;
input averageTypeWT = AverageType.WEIGHTED;
input averageTypeS = AverageType.SIMPLE;
input averageTypeHL = AverageType.HULL;

def NetChgAvgWL = MovingAverage(averageTypeWL, price - price[1], length);
def NetChgAvgEX = MovingAverage(averageTypeEX, price - price[1], length);
def NetChgAvgWT = MovingAverage(averageTypeWT, price - price[1], length);
def NetChgAvgS = MovingAverage(averageTypeS, price - price[1], length);
def NetChgAvgHL = MovingAverage(averageTypeHL, price - price[1], length);

def TotChgAvgWL = MovingAverage(averageTypeWL, AbsValue(price - price[1]), length);
def TotChgAvgEX = MovingAverage(averageTypeEX, AbsValue(price - price[1]), length);
def TotChgAvgWT = MovingAverage(averageTypeWT, AbsValue(price - price[1]), length);
def TotChgAvgS = MovingAverage(averageTypeS, AbsValue(price - price[1]), length);
def TotChgAvgHL = MovingAverage(averageTypeHL, AbsValue(price - price[1]), length);

def ChgRatioWL = if TotChgAvgWL != 0 then NetChgAvgWL / TotChgAvgWL else 0;
def ChgRatioEX = if TotChgAvgEX != 0 then NetChgAvgEX / TotChgAvgEX else 0;
def ChgRatioWT = if TotChgAvgWT != 0 then NetChgAvgWT / TotChgAvgWT else 0;
def ChgRatioS = if TotChgAvgS != 0 then NetChgAvgS / TotChgAvgS else 0;
def ChgRatioHL = if TotChgAvgHL != 0 then NetChgAvgHL / TotChgAvgHL else 0;

def WLRSI = 50 * (ChgRatioWL + 1);
def EXRSI = 50 * (ChgRatioEX + 1);
def WTRSI = 50 * (ChgRatioWT + 1);
def SRSI = 50 * (ChgRatioS + 1);
def HLRSI = 50 * (ChgRatioHL + 1);

def OverSold = over_Sold;
def OverBought = over_Bought;

def WLUpSignal = if WLRSI crosses above OverSold then OverSold else na;
def EXUpSignal = if EXRSI crosses above OverSold then OverSold else na;
def WTUpSignal = if WTRSI crosses above OverSold then OverSold else na;
def SUpSignal = if SRSI crosses above OverSold then OverSold else na;
def HLUpSignal = if HLRSI crosses above OverSold then OverSold else na;

def WLDownSignal = if WLRSI crosses below OverBought then OverBought else na;
def EXDownSignal = if EXRSI crosses below OverBought then OverBought else na;
def WTDownSignal = if WTRSI crosses below OverBought then OverBought else na;
def SDownSignal = if SRSI crosses below OverBought then OverBought else na;
def HLDownSignal = if HLRSI crosses below OverBought then OverBought else na;

def y1 = 0.004;
def a_up = low * (1-y1);;
def a_dwn = high * (1+y1);
def mid = 50;

def WLmidUp = if WLRSI crosses above mid then a_up else na;
def EXmidUp = if EXRSI crosses above mid then a_up else na;
def WTmidUp = if WTRSI crosses above mid then a_up else na;
def SmidUp = if SRSI crosses above mid then a_up else na;
def HLmidUp = if HLRSI crosses above mid then a_up else na;

def WLmidDown = if WLRSI crosses below mid then a_dwn else na;
def EXmidDown = if EXRSI crosses below mid then a_dwn else na;
def WTmidDown = if WTRSI crosses below mid then a_dwn else na;
def SmidDown = if SRSI crosses below mid then a_dwn else na;
def HLmidDown = if HLRSI crosses below mid then a_dwn else na;

# count bubbles
def upcnt = !isnan(WLmidUp) + !isnan(EXmidUp) + !isnan(WTmidUp) + !isnan(SmidUp) + !isnan(HLmidUp);
def dwncnt = !isnan(WLmidDown) + !isnan(EXmidDown) + !isnan(WTmidDown) + !isnan(SmidDown) + !isnan(HLmidDown);

def showupmin = if !show_only_min_count_items then (upcnt > 0) else (upcnt >= min_count);
def showdwnmin = if !show_only_min_count_items then (dwncnt > 0) else (dwncnt >= min_count);

#---------------------

# outputs
plot WLmidUpSignal = if show_arrows and showupmin then WLmidUp else na;
plot EXmidUpSignal = if show_arrows and showupmin then EXmidUp else na;
plot WTmidUpSignal = if show_arrows and showupmin then WTmidUp else na;
plot SmidUpSignal = if show_arrows and showupmin then SmidUp else na;
plot HLmidUpSignal = if show_arrows and showupmin then HLmidUp else na;

plot WLmidDownSignal = if show_arrows and showdwnmin then WLmidDown else na;
plot EXmidDownSignal = if show_arrows and showdwnmin then EXmidDown else na;
plot WTmidDownSignal = if show_arrows and showdwnmin then WTmidDown else na;
plot SmidDownSignal = if show_arrows and showdwnmin then SmidDown else na;
plot HLmidDownSignal = if show_arrows and showdwnmin then HLmidDown else na;

WLmidUpSignal.SetDefaultColor(Color.UPTICK);
EXmidUpSignal.SetDefaultColor(Color.UPTICK);
WTmidUpSignal.SetDefaultColor(Color.UPTICK);
SmidUpSignal.SetDefaultColor(Color.UPTICK);
HLmidUpSignal.SetDefaultColor(Color.UPTICK);

WLmidUpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
EXmidUpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
WTmidUpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
SmidUpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
HLmidUpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);

WLmidDownSignal.SetDefaultColor(Color.DOWNTICK);
EXmidDownSignal.SetDefaultColor(Color.DOWNTICK);
WTmidDownSignal.SetDefaultColor(Color.DOWNTICK);
SmidDownSignal.SetDefaultColor(Color.DOWNTICK);
HLmidDownSignal.SetDefaultColor(Color.DOWNTICK);

WLmidDownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
EXmidDownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
WTmidDownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SmidDownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
HLmidDownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

def y2 = 0.015;
def bub_up = low * (1-y2);
def bub_dwn = high * (1+y2);
AddChartBubble(show_bubbles and showupmin and WLmidUp, bub_up, "WL", Color.GREEN, no);
AddChartBubble(show_bubbles and showupmin and EXmidUp, bub_up, "E", Color.GREEN, no);
AddChartBubble(show_bubbles and showupmin and WTmidUp, bub_up, "WT", Color.GREEN, no);
AddChartBubble(show_bubbles and showupmin and SmidUp, bub_up, "S", Color.GREEN, no);
AddChartBubble(show_bubbles and showupmin and HLmidUp, bub_up, "H", Color.GREEN, no);

AddChartBubble(show_bubbles and showdwnmin and WLmidDown, bub_dwn, "WL", Color.RED);
AddChartBubble(show_bubbles and showdwnmin and EXmidDown, bub_dwn, "E", Color.RED);
AddChartBubble(show_bubbles and showdwnmin and WTmidDown, bub_dwn, "WT", Color.RED);
AddChartBubble(show_bubbles and showdwnmin and SmidDown, bub_dwn, "S", Color.RED);
AddChartBubble(show_bubbles and showdwnmin and HLmidDown, bub_dwn, "H", Color.RED);

addchartbubble(show_bubble_totals and showupmin, bub_up, upcnt, color.cyan,no);
addchartbubble(show_bubble_totals and showdwnmin, bub_dwn, dwncnt, color.magenta,yes);

#End of code
#
 

Attachments

  • img1.JPG
    img1.JPG
    46.6 KB · Views: 49
Last edited:
Solution
#rsi_5x_count_ups #https://usethinkscript.com/threads/count-number-of-active-rsi-chart-bubbles-and-create-alert.20058/ #Count number of active RSI chart bubbles and create alert def na = double.nan; def bn = barnumber(); input length = 14; input over_Bought = 70; input over_Sold = 30; input price = close; #input showBreakoutSignals = no; input show_bubbles = yes; input show_bubble_totals = yes; input show_arrows = yes; input min_count = 3; input show_only_min_count_items = yes; input ooooooooooooo = 0; input averageTypeWL = AverageType.WILDERS; input averageTypeEX = AverageType.EXPONENTIAL; input averageTypeWT = AverageType.WEIGHTED; input averageTypeS = AverageType.SIMPLE; input averageTypeHL = AverageType.HULL; def NetChgAvgWL = MovingAverage(averageTypeWL, price - price[1], length); def NetChgAvgEX = MovingAverage(averageTypeEX, price - price[1], length); def NetChgAvgWT = MovingAverage(averageTypeWT, price - price[1], length); def NetChgAvgS = MovingAverage(averageTypeS, price - price[1], length); def NetChgAvgHL = MovingAverage(averageTypeHL, price - price[1], length); def TotChgAvgWL = MovingAverage(averageTypeWL, AbsValue(price - price[1]), length); def TotChgAvgEX = MovingAverage(averageTypeEX, AbsValue(price - price[1]), length); def TotChgAvgWT = MovingAverage(averageTypeWT, AbsValue(price - price[1]), length); def TotChgAvgS = MovingAverage(averageTypeS, AbsValue(price - price[1]), length); def TotChgAvgHL = MovingAverage(averageTypeHL, AbsValue(price - price[1]), length); def ChgRatioWL = if TotChgAvgWL != 0 then NetChgAvgWL / TotChgAvgWL else 0; def ChgRatioEX = if TotChgAvgEX != 0 then NetChgAvgEX / TotChgAvgEX else 0; def ChgRatioWT = if TotChgAvgWT != 0 then NetChgAvgWT / TotChgAvgWT else 0; def ChgRatioS = if TotChgAvgS != 0 then NetChgAvgS / TotChgAvgS else 0; def ChgRatioHL = if TotChgAvgHL != 0 then NetChgAvgHL / TotChgAvgHL else 0; def WLRSI = 50 * (ChgRatioWL + 1); def EXRSI = 50 * (ChgRatioEX + 1); def WTRSI = 50 * (ChgRatioWT + 1); def SRSI = 50 * (ChgRatioS + 1); def HLRSI = 50 * (ChgRatioHL + 1); def OverSold = over_Sold; def OverBought = over_Bought; def WLUpSignal = if WLRSI crosses above OverSold then OverSold else na; def EXUpSignal = if EXRSI crosses above OverSold then OverSold else na; def WTUpSignal = if WTRSI crosses above OverSold then OverSold else na; def SUpSignal = if SRSI crosses above OverSold then OverSold else na; def HLUpSignal = if HLRSI crosses above OverSold then OverSold else na; def WLDownSignal = if WLRSI crosses below OverBought then OverBought else na; def EXDownSignal = if EXRSI crosses below OverBought then OverBought else na; def WTDownSignal = if WTRSI crosses below OverBought then OverBought else na; def SDownSignal = if SRSI crosses below OverBought then OverBought else na; def HLDownSignal = if HLRSI crosses below OverBought then OverBought else na; def y1 = 0.004; def a_up = low * (1-y1);; def a_dwn = high * (1+y1); def mid = 50; def WLmidUp = if WLRSI crosses above mid then a_up else na; def EXmidUp = if EXRSI crosses above mid then a_up else na; def WTmidUp = if WTRSI crosses above mid then a_up else na; def SmidUp = if SRSI crosses above mid then a_up else na; def HLmidUp = if HLRSI crosses above mid then a_up else na; def WLmidDown = if WLRSI crosses below mid then a_dwn else na; def EXmidDown = if EXRSI crosses below mid then a_dwn else na; def WTmidDown = if WTRSI crosses below mid then a_dwn else na; def SmidDown = if SRSI crosses below mid then a_dwn else na; def HLmidDown = if HLRSI crosses below mid then a_dwn else na; # count bubbles def upcnt = !isnan(WLmidUp) + !isnan(EXmidUp) + !isnan(WTmidUp) + !isnan(SmidUp) + !isnan(HLmidUp); def dwncnt = !isnan(WLmidDown) + !isnan(EXmidDown) + !isnan(WTmidDown) + !isnan(SmidDown) + !isnan(HLmidDown); def showupmin = if !show_only_min_count_items then (upcnt > 0) else (upcnt >= min_count); def showdwnmin = if !show_only_min_count_items then (dwncnt > 0) else (dwncnt >= min_count); #--------------------- # outputs plot WLmidUpSignal = if show_arrows and showupmin then WLmidUp else na; plot EXmidUpSignal = if show_arrows and showupmin then EXmidUp else na; plot WTmidUpSignal = if show_arrows and showupmin then WTmidUp else na; plot SmidUpSignal = if show_arrows and showupmin then SmidUp else na; plot HLmidUpSignal = if show_arrows and showupmin then HLmidUp else na; plot WLmidDownSignal = if show_arrows and showdwnmin then WLmidDown else na; plot EXmidDownSignal = if show_arrows and showdwnmin then EXmidDown else na; plot WTmidDownSignal = if show_arrows and showdwnmin then WTmidDown else na; plot SmidDownSignal = if show_arrows and showdwnmin then SmidDown else na; plot HLmidDownSignal = if show_arrows and showdwnmin then HLmidDown else na; WLmidUpSignal.SetDefaultColor(Color.UPTICK); EXmidUpSignal.SetDefaultColor(Color.UPTICK); WTmidUpSignal.SetDefaultColor(Color.UPTICK); SmidUpSignal.SetDefaultColor(Color.UPTICK); HLmidUpSignal.SetDefaultColor(Color.UPTICK); WLmidUpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP); EXmidUpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP); WTmidUpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP); SmidUpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP); HLmidUpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP); WLmidDownSignal.SetDefaultColor(Color.DOWNTICK); EXmidDownSignal.SetDefaultColor(Color.DOWNTICK); WTmidDownSignal.SetDefaultColor(Color.DOWNTICK); SmidDownSignal.SetDefaultColor(Color.DOWNTICK); HLmidDownSignal.SetDefaultColor(Color.DOWNTICK); WLmidDownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN); EXmidDownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN); WTmidDownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN); SmidDownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN); HLmidDownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN); def y2 = 0.015; def bub_up = low * (1-y2); def bub_dwn = high * (1+y2); AddChartBubble(show_bubbles and showupmin and WLmidUp, bub_up, "WL", Color.GREEN, no); AddChartBubble(show_bubbles and showupmin and EXmidUp, bub_up, "E", Color.GREEN, no); AddChartBubble(show_bubbles and showupmin and WTmidUp, bub_up, "WT", Color.GREEN, no); AddChartBubble(show_bubbles and showupmin and SmidUp, bub_up, "S", Color.GREEN, no); AddChartBubble(show_bubbles and showupmin and HLmidUp, bub_up, "H", Color.GREEN, no); AddChartBubble(show_bubbles and showdwnmin and WLmidDown, bub_dwn, "WL", Color.RED); AddChartBubble(show_bubbles and showdwnmin and EXmidDown, bub_dwn, "E", Color.RED); AddChartBubble(show_bubbles and showdwnmin and WTmidDown, bub_dwn, "WT", Color.RED); AddChartBubble(show_bubbles and showdwnmin and SmidDown, bub_dwn, "S", Color.RED); AddChartBubble(show_bubbles and showdwnmin and HLmidDown, bub_dwn, "H", Color.RED); addchartbubble(show_bubble_totals and showupmin, bub_up, upcnt, color.cyan,no); addchartbubble(show_bubble_totals and showdwnmin, bub_dwn, dwncnt, color.magenta,yes); #End of code
Thanks @halcyonguy for helping with this. I see the arrows but not the bubbles or the counts. Also, what is this input for... "input ooooooooooooo = 0;"?
 
Thanks @halcyonguy for helping with this. I see the arrows but not the bubbles or the counts. Also, what is this input for... "input ooooooooooooo = 0;"?

not sure on not seeing some shapes. the defaults are yes, to show them.
try different stocks and times. copy the code again and paste it in.
i just copied the code above and pasted it in TOS and it works.

that input is just a separator, a dummy. just a way to separate 2 groups of inputs, to make it easier to read them.
 
not sure on not seeing some shapes. the defaults are yes, to show them.
try different stocks and times. copy the code again and paste it in.
i just copied the code above and pasted it in TOS and it works.

that input is just a separator, a dummy. just a way to separate 2 groups of inputs, to make it easier to read them.
Ok, thanks so much and have a happy Thanksgiving!
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
444 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