Big Money Flow & Drift Oscillator [Spiritualhealer117]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © spiritualhealer117

//@version=5
indicator("BM&D Oscillator")
src = input.source(close,"Source")
len = input(14,"Length")
ret = (src-src[1])/src[1]
vol_cond = volume>ta.ema(volume, len)

drift_arr = array.new<float>(len)
bmf_arr = array.new<float>(len)

for i = 0 to len
    if vol_cond[i]
        array.insert(bmf_arr,i,ret[i])
    else   
        array.insert(drift_arr,i,ret[i])

drift = array.avg(drift_arr)
bmf = array.avg(bmf_arr)

line1=plot(drift*100, "Drift", #003049)
hline(0)
line2=plot(bmf*100,"Big Money Flow", #003049)

clr = drift>bmf?(drift>0?#eae2b7:#d62828):(bmf>0?#fcbf49:#f77f00)
fill(line1,line2, clr)

