0% found this document useful (0 votes)
318 views

Squeeze Indicator Pinescript (With Long Alerts)

The document describes a trading strategy that uses three indicators - bollinger bands, keltner channels, and momentum. It generates buy signals when the upper bollinger band crosses above the upper keltner band or the lower bollinger band crosses below the lower keltner band, as long as momentum is positive. The strategy also includes inputs to customize parameters and backtest over a specified date range.

Uploaded by

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

Squeeze Indicator Pinescript (With Long Alerts)

The document describes a trading strategy that uses three indicators - bollinger bands, keltner channels, and momentum. It generates buy signals when the upper bollinger band crosses above the upper keltner band or the lower bollinger band crosses below the lower keltner band, as long as momentum is positive. The strategy also includes inputs to customize parameters and backtest over a specified date range.

Uploaded by

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

//@version=4

study(shorttitle="SQZ", title="Squeeze", overlay=false)

length = input(20, minval=1)

src = input(close, title="Source")

mult = input(2.0, minval=0.001, maxval=50)

basis = sma(src, length)

dev = mult * stdev(src, length)

upper = basis + dev

lower = basis - dev

plot(basis, color=color.gray)

p1 = plot(upper, color=color.blue)

p2 = plot(lower, color=color.blue)

fill(p1, p2)

useTrueRange = input(true)

length2 = input(20, minval=1)

mult2 = input(1.5)

src2 = input(close, title="Source2")

ma = ema(src2, length2)

range = useTrueRange ? tr : high - low

rangema = ema(range, length2)

upper2 = ma + rangema * mult

lower2 = ma - rangema * mult

c = color.red

plot(ma, color=color.gray, title="Basis2")

u = plot(upper2, color=c, title="Upper2")

l = plot(lower2, color=c, title="Lower2")

fill(u, l, color=c)
len = input(12, minval=1, title="Length3")

src3 = input(close, title="Source3")

mom = src3 - src3[len]

plot(mom, color=color.olive, title="Mom")

long_cond = crossover(upper, upper2) and mom > 0

long_cond2 = crossunder(lower, lower2) and mom > 0

plotchar(long_cond, char="L", color = color.green)

plotchar(long_cond2, char="l", color = color.green)

alertcondition(long_cond, "Buy", "upper bollinger band crossed over the upper keltner band, momentum is
positive")

alertcondition(long_cond2, "Buy", "lower bollinger band crossed under the lower keltner band, momentum
is positive")
//@version=4

strategy(title="Squeeze", overlay=false, pyramiding=20)

//bollinger bands

length = input(20, minval=1)

src = input(close, title="Source")

mult = input(2.0, minval=0.001, maxval=50)

basis = sma(src, length)

dev = mult * stdev(src, length)

upper = basis + dev

lower = basis - dev

plot(basis, color=color.gray)

p1 = plot(upper, color=color.blue)

p2 = plot(lower, color=color.blue)

fill(p1, p2)

//keltner channel

useTrueRange = input(true)

length2 = input(20, minval=1)

mult2 = input(1.5)

src2 = input(close, title="Source2")

ma = ema(src2, length2)

range = useTrueRange ? tr : high - low

rangema = ema(range, length2)

upper2 = ma + rangema * mult

lower2 = ma - rangema * mult

c = color.red

plot(ma, color=color.gray, title="Basis2")

u = plot(upper2, color=c, title="Upper2")

l = plot(lower2, color=c, title="Lower2")

fill(u, l, color=c)
//momentum

len = input(12, minval=1, title="Length3")

src3 = input(close, title="Source3")

mom = src3 - src3[len]

plot(mom, color=color.olive, title="Mom")

// BACKTESTING RANGE

// From Date Inputs

fromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)

fromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)

fromYear = input(defval = 2018, title = "From Year", minval = 1970)

// To Date Inputs

toDay = input(defval = 1, title = "To Day", minval = 1, maxval = 31)

toMonth = input(defval = 1, title = "To Month", minval = 1, maxval = 12)

toYear = input(defval = 2019, title = "To Year", minval = 1970)

// Calculate start/end date and time condition

startDate = timestamp(fromYear, fromMonth, fromDay, 00, 00)

finishDate = timestamp(toYear, toMonth, toDay, 00, 00)

time_cond = time >= startDate and time <= finishDate

//trading conditions

long_entry1 = crossover(upper, upper2) and mom > 0

long_entry2 = crossunder(lower, lower2) and mom > 0

//submit orders

if (long_entry1)

strategy.entry(id="Bollinger-Keltner Crossover", long=true, when = time_cond)


if (long_entry2)

strategy.entry(id="Bollinger-Keltner Crossunder", long=true, when = time_cond)

strategy.exit("long exit", "Bollinger-Keltner Crossover", profit = close * 0.4 / syminfo.mintick, loss= close *
0.2 / syminfo.mintick)

strategy.exit("long exit", "Bollinger-Keltner Crossunder",profit = close * 0.4 / syminfo.mintick, loss= close *


0.2 / syminfo.mintick)

//plotchar(long_cond2, char="l", color = color.green)

//alertcondition(long_cond, "Buy", "upper bollinger band crossed over the upper keltner band, momentum
is positive")

//alertcondition(long_cond2, "Buy", "lower bollinger band crossed under the lower keltner band,
momentum is positive")

You might also like