help with code, fix and convert

spartandir

New member
Hello, i saw this code and I'm trying to figure out what's wrong in my code. I'd also like to convert it thinkscript as well. any help is greatly appreciated.

length = input (20,minval= 1)
mult = input (2.0, minval = .1, maxval=5.0)
band_top = sma(close, length) + mult * stdev(close, length)
band_bottom = sma(close, length) - mult * stdev(close, length)
rl618 = fib(high,low, 61.8)
rl50 = fibonacci(high,low, 50)
rl382 = fibonacci(high,low, 38.2)
buy = close > band_top and close < rl618
sell = close < band_bottom and close > rl382
plot (band_top, color =orange,linewidth = 1, title="BBTop")
plot (band_bottom, color =orange, linewidth = 1, title = "BBBot")
plot (rl618,color = purple, linewidth = 1, title = "61%")
plot (rl50,color = purple, linewidth = 1, title = "50%")
plot (rl382,color = purple, linewidth = 1, title = "38%")
buy = close > band_top and close < rl618
sell = close < band_bottom and close > rl382
plotshape(buy, color=green,style=shape.triangleup, title="Buy")
plotshape(sell, color=green,style=shape.triangleup, title="sell")


TV is currently complaining about fibonacci function and variables not being declared.

thanks in advance.
 

spartandir

New member
You are missing the pinescript version at the beginning. Depending on the pinescript version, you will need to restructure the code.
Thank you. I've updated to 5, but still need to find a solution for fib. not sure how to simulate the (high,low, 50) of the fib coding it the long way. any suggestions?
 
Last edited:

spartandir

New member
Code above is not for v5.
right... i made the updates and tried an alternate fib method, but don't think it's working as expect. hoping you can make sense of it. thanks

Code:
//@version=5
strategy("BBRETRACE")
//study("BBRETRACE")
length = input.int (20)
mult = input.float (2.0)

band_top = ta.sma(close, length) + mult * ta.stdev(close, length)
band_bottom = ta.sma(close, length) - mult * ta.stdev(close, length)

//rl618 = retracement(high,low, 61.8)
//rl50 = retracement(high,low, 50)
//rl382 = retracement(high,low, 38.2)

PP = (high + low + close) / 3
rl382 = PP - 0.382 * (high - low )
rl618 = PP + 0.618 * (high - low)
 
plot (band_top, "BBTop",color.orange,linewidth = 1 )
plot (band_bottom, "BBBot",color.orange, linewidth = 1 )

plot (rl618,"61%",color.purple, linewidth = 1  )
//plot (rl50,"50%", color.purple, linewidth = 1 )
plot (rl382,"38%",color.purple, linewidth = 1  )

buy = close > band_top and close < rl618
sell = close < band_bottom and close > rl382
 
plotshape(buy, "buy", shape.arrowup, location.belowbar, color.yellow,size=size.huge  )
plotshape(sell, "sell", shape.arrowdown, location.abovebar,color.yellow,size=size.huge )
 

spartandir

New member
I don't fully understand what the end goal is
i presume the theory is based on signals on a pullback to fib levels
buy = close > band_top and close < rl618
sell = close < band_bottom and close > rl382

my interpretation is ..
when price is above BB upper band and price retraces to 618 level, buy
when price below lower band and price closes retraces to 318 level sell

i think the question lies on the retracement level period, none is identified in the code sample
 
Top