Try removing ONCE from line 1, just write q = 1.
This an indicator I wrote, where I am dealing with your problem with a FOR…NEXT loop:
DEFPARAM CalculateOnLastBars = 300
DEFPARAM DrawOnLastBarOnly = True
p = 100
HH = highest[p](high)
LL = lowest[p](low)
Diff = HH - LL
Fib0236 = Diff * 0.236
Fib0382 = Diff * 0.382
Fib0500 = Diff * 0.500
Fib0618 = Diff * 0.618
Fib0764 = Diff * 0.764
Up = 0
Dn = 0
FOR i = 0 TO (p - 1)
IF high[i] = HH THEN
Up = 1
BREAK
ENDIF
IF low[i] = LL THEN
Dn = 1
BREAK
ENDIF
NEXT
DRAWHLINE(HH) coloured(238,122,233,255)//(0,128,0,255)
DRAWHLINE(LL) coloured(238,122,233,255)//(0,128,0,255)
IF Up THEN
Fib0236 = HH - Fib0236
Fib0382 = HH - Fib0382
Fib0500 = HH - Fib0500
Fib0618 = HH - Fib0618
Fib0764 = HH - Fib0764
ELSIF Dn THEN
Fib0236 = LL + Fib0236
Fib0382 = LL + Fib0382
Fib0500 = LL + Fib0500
Fib0618 = LL + Fib0618
Fib0764 = LL + Fib0764
ENDIF
DRAWTEXT(" ------#Fib0236#---(23.6%)",barindex,Fib0236,SansSerif,Bold,10)coloured(238,122,233,255)
DRAWTEXT(" ------#Fib0382#---(38.2%)",barindex,Fib0382,SansSerif,Bold,10)coloured(238,122,233,255)
DRAWTEXT(" ------#Fib0500#---(50.0%)",barindex,Fib0500,SansSerif,Bold,10)coloured(238,122,233,255)
DRAWTEXT(" ------#Fib0618#---(61.8%)",barindex,Fib0618,SansSerif,Bold,10)coloured(238,122,233,255)
DRAWTEXT(" ------#Fib0764#---(76.4%)",barindex,Fib0764,SansSerif,Bold,10)coloured(238,122,233,255)
RETURN