input fastLength = 12; input slowLength = 26; input MacdLength = 9; input MacdAverageType = AverageType.EXPONENTIAL; def Diff = MACD(fastLength, slowLength, MACDLength, MACDaverageType).Diff; input RsiLength = 14; input RsiPrice = close; input RsiAverageType = AverageType.WILDERS; input RsiOverbought = 70; input RsiOversold = 30; input lookBackPeriod = 4; input alertOn = {default "Live Bar", "Closed Bar"}; def NetChgAvg = MovingAverage(RSIaverageType, RSIprice - RSIprice[1], RSIlength); def TotChgAvg = MovingAverage(RSIaverageType, AbsValue(RSIprice - RSIprice[1]), RSIlength); def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0; def RSI = 50 * (ChgRatio + 1); def pivotLowMACD = Diff > Diff[1] and Diff[1] > Diff[2] and Diff[2] < Diff[3] and Diff[3] < Diff [4]; def pivotHighMACD = Diff < Diff[1] and Diff[1] < Diff[2] and Diff[2] > Diff[3] and Diff[3] > Diff[4]; def oversoldRSI = RSI <= RSIoversold; def overboughtRSI = RSI >= RSIoverbought; def signalOS = pivotLowMACD and highest(oversoldRSI[1], lookBackPeriod) > 0;; def signalOB = pivotHighMACD and highest(overboughtRSI[1], lookBackPeriod) > 0;; plot data = close; data.setPaintingStrategy(paintingStrategy.POINTS); data.setDefaultColor(color.CURRENT); data.hide(); def alertSignalOS; def alertSignalOB; switch (alertOn) { case "Live Bar": alertSignalOS = signalOS; alertSignalOB = signalOB; case "Closed Bar": alertSignalOS = signalOS[1]; alertSignalOB = signalOB[1]; } Alert(alertSignalOS, "Over Sold", Alert.BAR, Sound.Bell); Alert(alertSignalOB, "Over Bought", Alert.BAR, Sound.RING); AssignPriceColor( if signalOS then Color.MAGENTA else if signalOB then Color.CYAN else color.GRAY );