Search code examples
pine-scriptpine-script-v4pine-script-v5

How can I calculate Average of Moving Average points in pine script?


can you please help me with this? I want to find the average of the points that are plotted by simple moving average. How can I do find this? please help me with this


Solution

  • len = input.int(30, title = "length")
    
    ma = ta.sma(close, len)
    var float ma_sum = 0
    var float n = 0
    
    if not na(ma)
        ma_sum += ma
        n += 1
    
    avg = ma_sum / n