UB Profit Signal Indicator
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © mohanpblogger

//@version=5
indicator("UB Profit Signal", overlay=true)

// Define input variables
macdFastLength = input.int(title="MACD Fast Length", defval=12)
macdSlowLength = input.int(title="MACD Slow Length", defval=26)
macdSignalLength = input.int(title="MACD Signal Length", defval=9)
rsiLength = input.int(title="RSI Length", defval=9)
volumeEMA = ta.ema(volume, 9)
ma100 = ta.sma(close, 9)

// Calculate MACD
[macdLine, signalLine, _] = ta.macd(hl2, macdFastLength, macdSlowLength, macdSignalLength)
macdHLCC4 = (high + low + 2*close)/4

// Calculate RSI
rsiValue = ta.rsi(close, rsiLength)

// Calculate Bollinger Bands
sma = ta.sma(close, 21)
stdev = ta.stdev(close, 21)
upperBand1 = sma + stdev
upperBand3 = sma + 3 * stdev
lowerBand1 = sma - stdev
lowerBand3 = sma - 3 * stdev

// Calculate Buy and Sell signals
buySignal = rsiValue > 30 and volume > volumeEMA and close > ma100 and close > upperBand1 and close < upperBand3 and close[1] < open[1]
sellSignal = rsiValue < 40 and volume > volumeEMA and close < ma100 and close < lowerBand1 and close > lowerBand3 and close[1] > open[1]

// Plot Buy and Sell signals
plotshape(buySignal, title="Buy", location=location.belowbar, style=shape.triangleup, color=color.green, text="Buy", size=size.small)
plotshape(sellSignal, title="Sell", location=location.abovebar, style=shape.triangledown, color=color.red, text="Sell", size=size.small)



