Skip to content

Instantly share code, notes, and snippets.

@iCodeForBananas
Created November 25, 2023 18:35
Show Gist options
  • Save iCodeForBananas/6322cf1398b2492b54661edf4318b8ac to your computer and use it in GitHub Desktop.
Save iCodeForBananas/6322cf1398b2492b54661edf4318b8ac to your computer and use it in GitHub Desktop.
Bollinger Mean Reversion [iCodeForBananas]
//@version=5
strategy("Bollinger Mean Reversion [iCodeForBananas]", overlay=true, initial_capital = 5000, default_qty_value = 10, pyramiding = 30, default_qty_type= strategy.percent_of_equity, slippage=1, process_orders_on_close=true)
bbLength = input(45, 'MA length', group = 'Entry')
stdLength = input.float(2, 'Std dev', group = 'Entry')
trailStopMALength = input(80, 'Trail stop EMA length', group = 'Exit')
trailStopMA = ta.ema(close, trailStopMALength)
[middle, upper, lower] = ta.bb(close, bbLength, stdLength)
plot(middle, color=color.yellow)
plot(upper, color=color.yellow)
plot(lower, color=color.yellow)
longEntryCondition = ta.crossover(close, lower)
longExitCondition = ta.crossunder(close, trailStopMA)
if (longEntryCondition)
strategy.entry("LE", strategy.long, comment = "LE")
if (longExitCondition)
strategy.close("LE", 'LX')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment