Hello everyone,
I'm trying to implement the following in Pine Script 5, but unfortunately, it's not working: I want to place a Buy Limit Order on the lower band of the Bollinger Bands. Whenever the price touches the lower band, a limited buy order should be triggered. Unfortunately, I can't seem to get it right. Here's my test code and an image for clarification. How can I make sure that a Buy Limit Order is placed for every bar that is above the lower band?
//@version=5
strategy("Bollinger Bands Limit Order", overlay = true)
length = input.int(20, minval=1)
mult = input.float(2.0)
src = close
basis = ta.sma(src, length)
dev = mult * ta.stdev(src, length)
lowerBand = basis - dev
upperBand = basis + dev
plot(basis, "Basis", color=color.blue)
p1 = plot(lowerBand, "Lower Band", color=color.red)
p2 = plot(upperBand, "Upper Band", color=color.green)
fill(p1, p2, color=color.new(color.purple, 80))
if (close < lowerBand or open < lowerBand)
strategy.entry("Buy", strategy.long, limit=lowerBand)
label.new(bar_index, low, text = "Buy", color = color.green, style = label.style_label_down, yloc = yloc.belowbar)