Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- strategy(shorttitle='ChatGPT Strategy by Kralow', title='Bollinger Bands', overlay=true, currency=currency.NONE, initial_capital=1000, default_qty_type=strategy.percent_of_equity, default_qty_value = 100)
- // Bollinger Bands
- src = input(close)
- length = input.int(12, minval=1)
- mult = input.float(2.0, minval=0.001, maxval=50)
- basis = ta.sma(src, length)
- dev = ta.stdev(src, length)
- dev2 = mult * dev
- upper1 = basis + dev
- lower1 = basis - dev
- upper2 = basis + dev2
- lower2 = basis - dev2
- colorBasis = src >= basis ? color.blue : color.orange
- pBasis = plot(basis, linewidth=2, color=colorBasis)
- pUpper1 = plot(upper1, color=color.new(color.blue, 0), style=plot.style_circles)
- pUpper2 = plot(upper2, color=color.new(color.blue, 0))
- pLower1 = plot(lower1, color=color.new(color.orange, 0), style=plot.style_circles)
- pLower2 = plot(lower2, color=color.new(color.orange, 0))
- fill(pBasis, pUpper2, color=color.new(color.blue, 80))
- fill(pUpper1, pUpper2, color=color.new(color.blue, 80))
- fill(pBasis, pLower2, color=color.new(color.orange, 80))
- fill(pLower1, pLower2, color=color.new(color.orange, 80))
- // RSI
- rsiLength = input(14, title="RSI Length")
- rsiThreshold = input(30, title="RSI Threshold")
- rsiValue = ta.rsi(src, rsiLength)
- // Strategy Entry and Exit Conditions
- longCondition = close > upper2 and rsiValue > rsiThreshold
- if longCondition
- strategy.entry("Long", strategy.long)
- shortCondition = close < lower2 or rsiValue <= rsiThreshold
- if shortCondition
- strategy.close("Long")
- // Trailing Stop
- trailing_offset = input.float(0.01, "Trailing Stop Offset")
- trailing_stop_loss = strategy.position_avg_price * (1 - trailing_offset)
- strategy.exit("Long", "Close Long", stop = trailing_stop_loss)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement