TASC 2022.10 RS VA EMA
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © PineCodersTASC

//  TASC Issue: October 2022 - Vol. 40, Issue 11
//     Article: Relative Strength Moving Averages
//              Part 2: The Relative Strength Volume-Adjusted
//              Exponential Moving Average (RS VA EMA)
//  Article By: Vitali Apirine
//    Language: TradingView's Pine Script v5
// Provided By: PineCoders, for tradingview.com

//@version=5
indicator('TASC 2022.10 RS VA EMA', overlay=true)

float   src = input.source(close,  'Source:')
int periods = input.int(10,    'EMA Length:', minval=1)
int     pds = input.int(10,     'VS Length:', minval=1)
float  mltp = input.int(10, 'VS Multiplier:', minval=0)

rsvaema(float    source = close, 
  simple int  emaPeriod = 50, 
  simple int   vsPeriod = 50, 
       float multiplier = 10.0
       ) =>
    var float mltp1 = 2.0 / (emaPeriod + 1.0)
    var float coef1 = 2.0 /  (vsPeriod + 1.0)
    var float coef2 = 1.0 - coef1
    float pv   = source > source[1] ? volume : 0.0
    float nv   = source < source[1] ? volume : 0.0
    float apv  = na, apv := coef1 * pv + coef2 * nz(apv[1])
    float anv  = na, anv := coef1 * nv + coef2 * nz(anv[1])
    float vs   = math.abs(apv - anv) / (apv + anv)
    float rate = mltp1 * (1.0 + nz(vs, 0.00001) * multiplier)
    float rsma = na
    rsma := rate * source + (1.0 - rate) * nz(rsma[1],source)
    rsma

float rsvaema = rsvaema(src, periods, pds, mltp)

plot(rsvaema, title='RS VA EMA', color=#B21BD8, linewidth=2)