Hi there
Can someone please help me with understanding why am I getting the error message above in line 18: for i = 0 to array.size(djia_tickers) - 1
=========
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=6
indicator(DIA ETF: 25% or Fewer Stocks Below 20-Day SMA
, overlay=true)
// List of the 30 DJIA stocks
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
// Calculate the 20-day SMA for each stock
sma_length = 20
// Count the number of stocks below their 20-day SMA
stocks_below_sma = 0
for i = 0 to array.size(djia_tickers) - 1
// Get the current ticker from the array
ticker = array.get(djia_tickers, i)
// Calculate the 20-day SMA for each stock
sma_stock = request.security(ticker, D
, ta.sma(close, sma_length))
// If the stock's close is below its 20-day SMA, increment the counter
if close < sma_stock
stocks_below_sma := stocks_below_sma + 1
// Calculate the percentage of stocks below the 20-day SMA
percent_below_sma = (stocks_below_sma / array.size(djia_tickers)) * 100
// Condition: If 25% or fewer of the stocks are below their 20-day SMA
condition = percent_below_sma <= 25
// Plot a label below the bar when the condition is met
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
)
// Paint the DIA candle red when the condition is met
barcolor(condition ? color.red : na)