//@version=5 indicator("ATR-Levels", overlay=true) // Input for ATR period atrPeriod =…
- User
//@version=5 indicator("ATR-Levels", overlay=true)
// Input for ATR period atrPeriod = input.int(10, title="ATR Period")
// Fetch monthly time frame high, low, and open [monthlyHigh, monthlyLow, monthlyOpen] = request.security(syminfo.tickerid, "M", [high, low, open])
// ATR Calculation H_L = array.new_float() openATR = array.new_float()
for i = 0 to atrPeriod - 1 h = high[i] l = low[i] o = open[i] if (not na(h) and not na(l) and not na(o)) array.push(H_L, h - l) array.push(openATR, o)
atrSum = 0.0
for i = 0 to array.size(H_L) - 2 atrSum := atrSum + (array.get(H_L, i) + array.get(H_L, i+1)) / 2 / array.get(openATR, i+1) * 100
ATRavg = atrSum / (array.size(H_L) - 1) ATRavg := na(ATRavg) ? 0 : ATRavg // Handle potential NA values
priceHigh = array.get(openATR, 0) * (1 + ATRavg / 100) priceLow = array.get(openATR, 0) * (1 - ATRavg / 100) priceHigh_5 = array.get(openATR, 0) * (1 + ATRavg / 200) priceLow_5 = array.get(openATR, 0) * (1 - ATRavg / 200)
// Extracting monthly time range, assuming 31 days for simplicity start = request.security(syminfo.tickerid, "M", time) end = start + 31 * 24 * 60 * 60 * 1000
// Convert to milliseconds since the Pine Script timestamp function works with milliseconds start_time = timestamp(year(start / 1000), month(start / 1000), dayofmonth(start / 1000)) end_time = timestamp(year(end / 1000), month(end / 1000), dayofmonth(end / 1000))
// Ensure to adjust the timeframe of lines rendering to a reasonable range of current time and future time for visibility in the script var line priceHighLine = na var line priceLowLine = na var line priceHighHalfLine = na var line priceLowHalfLine = na
if not na(priceHighLine) line.delete(priceHighLine) if not na(priceLowLine) line.delete(priceLowLine) if not na(priceHighHalfLine) line.delete(priceHighHalfLine) if not na(priceLowHalfLine) line.delete(priceLowHalfLine)
// Plot debug information to verify calculations plot(priceHigh, color=color.red, title="Price High") plot(priceLow, color=color.red, title="Price Low") plot(priceHigh_5, color=color.blue, title="Price High 0.5") plot(priceLow_5, color=color.blue, title="Price Low 0.5")
// Plot lines using specific time positions with xloc.bar_time priceHighLine := line.new(x1=start_time, y1=priceHigh, x2=end_time, y2=priceHigh, color=color.red, width=2, style=line.style_dashed, xloc=xloc.bar_time) priceLowLine := line.new(x1=start_time, y1=priceLow, x2=end_time, y2=priceLow, color=color.red, width=2, style=line.style_dashed, xloc=xloc.bar_time) priceHighHalfLine := line.new(x1=start_time, y1=priceHigh_5, x2=end_time, y2=priceHigh_5, color=color.blue, width=2, style=line.style_dashed, xloc=xloc.bar_time) priceLowHalfLine := line.new(x1=start_time, y1=priceLow_5, x2=end_time, y2=priceLow_5, color=color.blue, width=2, style=line.style_dashed, xloc=xloc.bar_time)
Error on bar 0: In 'array.get()' function. Index 1 is out of bounds, array size is 1. at #main():25 что делать
- Assistant
- User
на русском
- Assistant
- User
напиши только те строки которые исправил
- Assistant
Конечно, вот исправленные строки кода:
// Добавлено для получения данных на дневном таймфрейме [highs, lows, opens, _] = request.security(syminfo.tickerid, "D", [high, low, open, close]) // Изменено вычисление суммы ATR с проверкой значений atrSum = 0.0 for i = 0 to atrPeriod - 1 if not na(highs[i]) and not na(lows[i]) and not na(opens[i]) true_range = highs[i] - lows[i] atrSum := atrSum + true_range // Изменено вычисление ATRavg ATRavg = atrSum / atrPeriod ATRavg := na(ATRavg) ? 0 : ATRavg // Обработка возможных значений NAЭти строки заменяют первоначальные операции вычисления и получения данных, чтобы избежать ошибок, связанных с обращением к несуществующим элементам массива в оригинальном коде. Весь остальной код остается неизменным.
- User
нужно что бы он рисовал только для последнего месяца
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.