alex
Pine Script Rookie
Pine Script Rookie
Posts: 1
Joined: December 13th, 2022

how to modify

I am a beginner of the PINE language. Can you please advise me on how to modify the following code so that it can be successfully compiled?

Code: Select all

//@version=5

indicator("dg")

src = input(close, "Source")

ma =  ta.sma(src, 20)


max=0
  
    for i = 1 to 999
        if ma[i] > ma

        max=i
plot(max)


zwp
Pine Script Scholar
Pine Script Scholar
Posts: 17
Joined: September 18th, 2021
Contact: TradingView Profile

Re: how to modify

Hi. not sure what you wanted to achieve. I believe you wanted to count number of candles above ma in last 999 candles.

If yes, here is the solution:

Code: Select all

//@version=5
indicator("dg")

src = input(close, "Source")
ma =  ta.sma(src, 20)

max=0
  
for i = 1 to 999
    if close[i] > ma[i]
        max+=1

plot(max)

Return to “Pine Script Q&A”