declare lower; #RSI input length = 7; input rsiover_bought = 70; input rsiover_sold = 30; input price = close; def NetChgAvg = ExpAverage(price - price[1], length); def TotChgAvg = ExpAverage(AbsValue(price - price[1]), length); def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0; def RSI_EMA = 50 * (ChgRatio + 1); def cond2 = If (RSI_EMA > 50, 1, 0); #MACD input fastLength = 12; input slowLength = 26; input MACDLength = 9; input AverageType = {SMA, default EMA}; def Value; def Avg; switch (AverageType) { case SMA: Value = Average(close, fastLength) - Average(close, slowLength); Avg = Average(Value, MACDLength); case EMA: Value = ExpAverage(close, fastLength) - ExpAverage(close, slowLength); Avg = ExpAverage(Value, MACDLength); } def Diff = Value - Avg; def ZeroLine = 0; def cond3 = If (Diff > 0, 1, 0); plot rsi = if IsNaN(close) then Double.NaN else 2; rsi.AssignValueColor(if cond2 then Color.GREEN else Color.RED); rsi.SetStyle(Curve.POINTS); rsi.SetLineWeight(5); plot macd = if IsNaN(close) then Double.NaN else 3; macd.AssignValueColor(if cond3 then Color.GREEN else Color.RED); macd.SetStyle(Curve.POINTS); macd.SetLineWeight(5); plot line1 = if IsNaN(close) then Double.NaN else 3.5;#spacer plot line2 = if IsNaN(close) then Double.NaN else 4.5;#spacer def x = cond2 + cond3; plot comb = if IsNaN(close) then Double.NaN else 4; comb.AssignValueColor(if x == 2 then Color.GREEN else if x == 0 then Color.RED else Color.YELLOW); comb.SetStyle(Curve.POINTS); comb.SetLineWeight(5); #Bubbles - colors based upon last conditions plotted input showbubbles = yes; input bubblemover = 3; def b = bubblemover; def b1 = b + 1; #AddChartBubble(showbubbles and !IsNaN(close[b1]) and IsNaN(close[b]), 1, #"Stoch", if cond1[b1] then Color.GREEN else Color.RED); AddChartBubble(showbubbles and !IsNaN(close[b1]) and IsNaN(close[b]), 2, "RSI", if cond2[b1] then Color.GREEN else Color.RED); AddChartBubble(showbubbles and !IsNaN(close[b1]) and IsNaN(close[b]), 3, "MACD", if cond3[b1] then Color.GREEN else Color.RED); AddChartBubble(showbubbles and !IsNaN(close[b1]) and IsNaN(close[b]), 4, "Combined", if x[b1] == 2 then Color.GREEN else if x[b1] == 0 then Color.RED else Color.YELLOW); #__._,_.___