FUNCTION: Limited Historical Data Workaround
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © theheirophant

//@version=5
indicator("FUNCTION: Limited Historical Data Workaround")

// an SMA function that accepts series as a length
Sma(src,p) => 
    a = ta.cum(src) 
    ret = (a - a[p]) / p


limit(length) =>
    lengthR = length
    if bar_index < length
        lengthR := bar_index
    lengthR
    

plot(ta.sma(close, 200), color=color.red, linewidth=3)
plot(Sma(close, limit(200)), color=color.lime)
