Declare lower; 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; 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; plot scan = pivotLowMACD and highest(oversoldRSI[1], 4) > 0 or pivotHighMACD and lowest (overboughtRSI[1], 4) < 0;