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