admin管理员组

文章数量:1192366

Hi there in line 11 (for i = 0 to array.size(djia_tickers) - 1) I am getting the error mentioned in the title. I am brand new in pine script, can someone please advise ?

indicator("DIA ETF: 25% or Fewer Stocks Below 20-Day SMA", overlay=true)

djia_tickers = "AAPL", "MSFT", "JPM", "V", "GS", "DIS", "HD", "INTC", "MCD", "BA","UNH", "KO", "WMT", "PG", "AXP", "CAT", "CVX", "IBM", "MRK", "CSCO","XOM", "COST", "PFE", "TRV", "MMM", "AMGN", "WBA", "HON", "CRM", "NKE", "DD"

sma_length = 20


stocks_below_sma = 0

for i = 0 to array.size(djia_tickers) - 1

   ticker = array.get(djia_tickers, i)
  
   sma_stock = request.security(ticker, "D", ta.sma(close, sma_length))

   if close < sma_stock
       stocks_below_sma := stocks_below_sma + 1

percent_below_sma = (stocks_below_sma / array.size(djia_tickers)) * 100

condition = percent_below_sma <= 25

plotshape(series=condition, location=location.belowbar, color=color.red, style=shape.labeldown, title="25% or Fewer Stocks Below 20-Day SMA", text="25% Below SMA")

barcolor(condition ? color.red : na)

Hi there in line 11 (for i = 0 to array.size(djia_tickers) - 1) I am getting the error mentioned in the title. I am brand new in pine script, can someone please advise ?

indicator("DIA ETF: 25% or Fewer Stocks Below 20-Day SMA", overlay=true)

djia_tickers = "AAPL", "MSFT", "JPM", "V", "GS", "DIS", "HD", "INTC", "MCD", "BA","UNH", "KO", "WMT", "PG", "AXP", "CAT", "CVX", "IBM", "MRK", "CSCO","XOM", "COST", "PFE", "TRV", "MMM", "AMGN", "WBA", "HON", "CRM", "NKE", "DD"

sma_length = 20


stocks_below_sma = 0

for i = 0 to array.size(djia_tickers) - 1

   ticker = array.get(djia_tickers, i)
  
   sma_stock = request.security(ticker, "D", ta.sma(close, sma_length))

   if close < sma_stock
       stocks_below_sma := stocks_below_sma + 1

percent_below_sma = (stocks_below_sma / array.size(djia_tickers)) * 100

condition = percent_below_sma <= 25

plotshape(series=condition, location=location.belowbar, color=color.red, style=shape.labeldown, title="25% or Fewer Stocks Below 20-Day SMA", text="25% Below SMA")

barcolor(condition ? color.red : na)
Share Improve this question edited Jan 25 at 9:48 Yash Mehta 2,0063 gold badges12 silver badges21 bronze badges asked Jan 24 at 6:00 GuzGuz 12 bronze badges 1
  • Hi there in line 11 (for i = 0 to array.size(djia_tickers) - 1) I am getting the error mentioned in the title. I am brand new in pine script, can someone please advise ? Thanks – Guz Commented Jan 24 at 6:11
Add a comment  | 

1 Answer 1

Reset to default -1
indicator("DIA ETF: 25% or Fewer Stocks Below 20-Day SMA", overlay=true)

djia_tickers = array.from("AAPL", "MSFT", "JPM", "V", "GS", "DIS", "HD", "INTC", "MCD", "BA","UNH", "KO", "WMT", "PG", "AXP", "CAT", "CVX", "IBM", "MRK", "CSCO","XOM", "COST", "PFE", "TRV", "MMM", "AMGN", "WBA", "HON", "CRM", "NKE", "DD")

sma_length = 20
stocks_below_sma = 0

for i = 0 to array.size(djia_tickers) - 1
    ticker = array.get(djia_tickers, i)
    sma_stock = request.security(ticker, "D", ta.sma(close, sma_length))

    if close < sma_stock
        stocks_below_sma += 1

percent_below_sma = (stocks_below_sma / array.size(djia_tickers)) * 100

condition = percent_below_sma <= 25

plotshape(condition, location=location.belowbar, color=color.red, style=shape.labeldown, title="25% or Fewer Stocks Below 20-Day SMA", text="25% Below SMA")

barcolor(condition ? color.red : na)

本文标签: pine script error Incorrect 39for39 statement Expecting 39to ltexpressiongt39 (line 11)Stack Overflow