0% found this document useful (0 votes)
120 views2 pages

Trading Strategy

The document describes a Bollinger Band breakout trading strategy. It defines the calculations for the upper and lower Bollinger Bands based on a simple moving average and standard deviations. It includes logic to enter long positions when the price closes above the upper band and short positions when it closes below the lower band. Profits are taken by exiting positions when the price crosses the opposite band.

Uploaded by

Jamison Carson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
120 views2 pages

Trading Strategy

The document describes a Bollinger Band breakout trading strategy. It defines the calculations for the upper and lower Bollinger Bands based on a simple moving average and standard deviations. It includes logic to enter long positions when the price closes above the upper band and short positions when it closes below the lower band. Profits are taken by exiting positions when the price crosses the opposite band.

Uploaded by

Jamison Carson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

//@version=5

// Bollinger Bands: Madrid : 14/SEP/2014 11:07 : 2.0


// This displays the traditional Bollinger Bands, the difference is
// that the 1st and 2nd StdDev are outlined with two colors and two
// different levels, one for each Standard Deviation

strategy(shorttitle='Trade Tactics BB Breakout', title='Trade Tactics Bollinger


Band Breakout', overlay=true, currency=currency.NONE, initial_capital = 1000,
default_qty_type = strategy.percent_of_equity, default_qty_value = 100,
commission_value = 0.05)
src = input(close)
length = input.int(34, 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))

ma(source, length, type) =>


switch type
"SMA" => ta.sma(source, length)
"Bollinger Bands" => 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)

rsiLengthInput = input.int(14, minval=1, title="RSI Length", group="RSI Settings")


rsiSourceInput = input.source(close, "Source", group="RSI Settings")
maTypeInput = input.string("SMA", title="MA Type", options=["SMA", "Bollinger
Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="MA Settings")
maLengthInput = input.int(14, title="MA Length", group="MA Settings")
bbMultInput = input.float(2.0, minval=0.001, maxval=50, title="BB StdDev",
group="MA Settings")

up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)


down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
rsiMA = ma(rsi, maLengthInput, maTypeInput)

//Enter a long position when price closes above the upper Bollinger Band
if ta.crossover(close, upper1)
strategy.entry("Long", strategy.long)

//Enter a short position when price closes below the lower Bollinger Band
if ta.crossunder(close, lower1)
strategy.entry("Short", strategy.short)

// Exit the long position when the short condition is met


if ta.crossover(close, lower1) or close < basis
strategy.close("Long")

// Exit the short position when the long condition is met


if ta.crossunder(close, upper1) or close > basis
strategy.close("Short")

You might also like