The script works fine in the Daily time frame but not in the intraday time frame. In the intraday it must draw me the same levels that it finds in the Daily time frame.
//@version=5
indicator("Max e Min Range Spazio e Tempo Intraday", shorttitle='MaxMinP Prova Intra', overlay=true)
// Parametri
SMAX = input(true, title="SMAX")
SMIN = input(true, title="SMIN")
nMM = input.int(120, title="Numero di massimi giornalieri")
RangeX = input.float(0.15, title="Range")
//calcolo scarto intervallo
ATRD = request.security(syminfo.tickerid, "D", ta.atr(5))
SFMin = ATRD * RangeX
// Trova il massimo e minimo di oggi
dailyHigh = request.security(syminfo.tickerid, "D", high[0], lookahead=barmerge.lookahead_on)
dailyLow = request.security(syminfo.tickerid, "D", low[0], lookahead=barmerge.lookahead_on)
// Riferimento ai massimi e minimi Daily
Dhigh = request.security(syminfo.tickerid, "D", high, lookahead=barmerge.lookahead_on)
Dlow = request.security(syminfo.tickerid, "D", low, lookahead=barmerge.lookahead_on)
// Calcola i limiti dell'intervallo solo per la giornata attuale
lowerBoundU = na(dailyHigh) ? na : dailyHigh - SFMin
upperBoundU = na(dailyHigh) ? na : dailyHigh
lowerBoundD = na(dailyLow) ? na : dailyLow
upperBoundD = na(dailyLow) ? na : dailyLow + SFMin
// Traccia per verifica gli intervalli
plot(lowerBoundU, color=color.red, style=plot.style_linebr)
plot(upperBoundU, color=color.orange, style=plot.style_linebr)
plot(lowerBoundD, color=color.orange, style=plot.style_linebr)
plot(upperBoundD, color=color.red, style=plot.style_linebr)
if barstate.islast // (bar_index == last_bar_index)
// Segmenti massimi
for i = 0 to nMM
if Dhigh[i] > lowerBoundU and Dhigh[i] < upperBoundU and SMAX
line.new(x1=bar_index, y1=Dhigh[i], x2=bar_index + 10, y2=Dhigh[i], color=color.new(color.black, 0), width = 3)
label.new(x=bar_index + 5, y=Dhigh[i], text=str.tostring(Dhigh[i]), style=label.style_label_down, color=color.green, size=size.normal)
// Segmenti minimi
for i = 0 to nMM
if Dlow[i] > lowerBoundD and Dlow[i] < upperBoundD and SMIN
line.new(x1=bar_index, y1=Dlow[i], x2=bar_index + 10, y2=Dlow[i], color=color.new(color.black, 0), width = 3)
label.new(x=bar_index + 5, y=Dlow[i], text=str.tostring(Dlow[i]), style=label.style_label_down, color=color.green, size=size.normal)
For each DAILY high and low of the last 120 candles, we want to check whether they are included in the range given by TODAY’S high and low minus and plus SFMin, respectively. If any of the DAILY highs or lows falls within this range, then a corresponding line will be drawn on the INTRADAY CHART. The above code works perfectly in DAILY CHART but NOT in INTRADAY CHART. The same levels that are identified in the Daily chart must be drawn in the INTRADAY CHART. I assume it’s a problem with FOR.
Grespo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.