Skip to content

Instantly share code, notes, and snippets.

@Pymmdrza
Last active May 4, 2025 18:03
Show Gist options
  • Select an option

  • Save Pymmdrza/1828ceefbc37ef98799eb3cee3a231bd to your computer and use it in GitHub Desktop.

Select an option

Save Pymmdrza/1828ceefbc37ef98799eb3cee3a231bd to your computer and use it in GitHub Desktop.
Mmdrza Bolinger Meta (Pine Script) for tradingview Strategy Auto Class Entry
//@version=5
strategy(shorttitle="MMDRZA Bollinger Meta 0.1.0", title="Mmdrza - Bollinger Bands Strategy with New Algorithm for any chart", overlay=true, commission_type=strategy.commission.percent, commission_value=0.1, slippage=0, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
// Inputs
length = input.int(20, minval=1, title="Length")
maType = input.string("SMA", "Basis MA Type", options = ["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"])
src = input(close, title="Source")
mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")
offset = input.int(0, "Offset", minval = -500, maxval = 500)
// Date Range Filter
startDate = input.time(title="Start Date", defval=timestamp("2018-01-01"), confirm=false)
endDate = input.time(title="End Date", defval=timestamp("2069-12-31"), confirm=false)
timeAllowed = time >= startDate and time <= endDate
// MA Type Selector
ma(source, length, _type) =>
switch _type
"SMA" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)
// Calculations
basis = ma(src, length, maType)
dev = mult * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev
// Preserve Indicator Plots
plot(basis, "Basis", color=color.rgb(194, 193, 192, 21), offset=offset)
p1 = plot(upper, "Upper", color=color.rgb(27, 202, 71, 38), offset=offset)
p2 = plot(lower, "Lower", color=color.rgb(172, 19, 19, 25), offset=offset)
fill(p1, p2, title="Background", color=color.rgb(233, 233, 233, 95))
// Strategy Logic
enterLong = ta.crossover(close, lower) and timeAllowed // Modified: Price crosses above lower band
exitLong = ta.crossunder(close, lower) and timeAllowed // Exit when price crosses back below lower band
if enterLong
strategy.entry("Long", strategy.long)
if exitLong
strategy.close("Long")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment