Trend & Momentum V2
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © pvrcharts
// Simple indicator combining trend and momentum using Moving Average and RSI.

//@version=5
indicator(title="Profitable Trader Pro V2", shorttitle="Profitable Trader Pro V2",overlay=true)

//input
src = input(close, title="Price Source")
string maType = input.string("EMA", "MA type", options = ["EMA", "SMA", "RMA", "WMA"])
malen = input.int(9, minval=1, title="Trend Lookback Period (MA Length)")
rsilen=input.int(5, minval=1, title="Momentum Lookback Period (RSI Length)")
signal   = input.bool(true, title="Display long/short signals on the chart.")
tradingzone   = input.bool(false, title="You can now filter out price action noise with custom bar colors. Green for bullish bias, red for bearish bias and white for neutral.")

//Trend
mavalue = switch maType
    "EMA" => ta.ema(src, malen)
    "SMA" => ta.sma(src, malen)
    "RMA" => ta.rma(src, malen)
    "WMA" => ta.wma(src, malen)

bullish_trend= close > mavalue
bearish_trend= close < mavalue

//Momentum
rsi=ta.rsi(close, rsilen)
bullish_mom = rsi>50
bearish_mom = rsi<50

longbias = bullish_mom ? bullish_trend  : false
shortbias = bearish_mom ? bearish_trend  : false
switchlong=longbias[1]==false and longbias
switchshort=shortbias[1]==false and shortbias
golongtrigger= (close > high[1]) and longbias
goshorttrigger= (close < low[1]) and shortbias

alertcondition(golongtrigger,title='Long Signal (Set Once Per Bar)',message='Long trade signal for {{ticker}} at alert price {{close}} | T&M Trader Pro V2')
alertcondition(goshorttrigger,title='Short Signal (Set Once Per Bar)',message='Short trade signal for {{ticker}} at alert price {{close}} | T&M Trader Pro V2')


plot(mavalue,"MA_VAL", color=(longbias ? color.green : shortbias ? color.red : color.gray),linewidth=2)
barcolor(tradingzone ? (longbias ? color.green : shortbias ? color.red : color.gray) : na)
plotshape(signal and switchlong,style=shape.labelup,text='🐂',location=location.belowbar, color=color.green)
plotshape(signal and switchshort,style=shape.labeldown,text='🐻',location=location.abovebar, color=color.red)