Trend Flow Profile [AlgoAlpha]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AlgoAlpha X © Sushiboi77

//@version=5
indicator(title='Trend Flow Profile [AlgoAlpha]', shorttitle='📈 TFP [AlgoAlpha]', overlay=false)

// Input parameters
orderFlowPeriod = input.int(12, minval=1, title='Trend Flow Period')
emashow = input.bool(true, "Show EMA band?")
emalen = input(8, "EMA Length")
green = input.color(#00ffbb, "Up Color") //#00ffbb
red = input.color(#ff1100, "Down Color") //#ff1100


//Trend Flow
orderFlow = math.sum(close > close[1] ? volume : (close < close[1] ? -volume : 0), orderFlowPeriod)
orderFlow := orderFlow /1000

//Rate of Change
lenr = input(14, "ROC Length")
roc = ta.roc(close, lenr)

//Calculation
trendflow = (roc + orderFlow) / 2
ematrend = ta.ema(trendflow, emalen)

//Colors
gcol1 = color.new(green, 20)
gcol2 = color.new(green, 50)
rcol1 = color.new(red, 20)
rcol2 = color.new(red, 50)
col = (trendflow > 0 ? (trendflow > trendflow[1] ? gcol1 : gcol2) : (trendflow < trendflow[1] ? rcol1 : rcol2))

// Plotting
plot(trendflow, title='Combined Indicator', color= col, linewidth=2, style=plot.style_columns)
plot(orderFlow, style = plot.style_columns, color=orderFlow > 0 ? color.new(green, 80) : color.new(red, 80))
plot(emashow ? ematrend: na, color = color.white)
