Coppock Unchanged
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TraderLeibniz

//@version=5
indicator("Coppock Unchanged",  overlay=true, timeframe="", timeframe_gaps=true)

coppock_curve(_expr, _roc_short, _roc_long, _wma_len, _tf) =>
    sum_expr = (ta.roc(_expr, _roc_short) + ta.roc(_expr, _roc_long))/100
    out_expr = ta.wma(sum_expr, _wma_len)
    _out = request.security(symbol=syminfo.tickerid, timeframe=_tf, expression=out_expr)

    sma_expr = ta.sma(sum_expr, _wma_len)
    _sma = request.security(symbol=syminfo.tickerid, timeframe=_tf, expression=sma_expr)
    unch_data_expr = _expr[_roc_short]*_expr[_roc_long]*(2.0+_sma[1])/(_expr[_roc_short]+_expr[_roc_long])
    _unch_data = request.security(symbol=syminfo.tickerid, timeframe=_tf, expression=unch_data_expr)

    [_out, _unch_data]

cc_src = input.source(defval=close, title='Coppock Curve Input')
roc1 = input.int(defval=11, title='RoC 1')
roc2 = input.int(defval=14, title='RoC 2')
wma_len = input.int(defval=10, title='WMA Length')

[cc_out, data_cc_unch] = coppock_curve(cc_src, roc1, roc2, wma_len, timeframe.period)

ar_tf = input.timeframe("3M", "Alt Coppock Resolution", options=["65","130","195","300","1D","2D","3D","1W","2W","1M","3M","12M"])

cc_src_AR = input.source(defval=close, title='Coppock Curve Input Alt Res')
roc1_AR = input.int(defval=11, title='RoC 1 Alt Res')
roc2_AR = input.int(defval=14, title='RoC 2 Alt Res')
wma_len_AR = input.int(defval=10, title='WMA Length Alt Res')

[cc_out_AR, data_cc_unch_AR] = coppock_curve(cc_src_AR, roc1_AR, roc2_AR, wma_len_AR, ar_tf)


// -------------

plot(data_cc_unch, color=color.blue, title="Coppock Unchanged")
plot(data_cc_unch_AR, color=color.orange, title="Coppock Unchanged Alt Resolution")
