0bps

Strategy vault / Other

Bollinger lows

Pine Script strategy by Zer3192.

Author
Zer3192
Complexity
Intermediate · 167 lines
Parameters
5
Backtest bar
4h · intraday
Tested on
BTC/USDT · spot

The original spec has no written description. Read the source below.

Parameters

NameDefaultWhat it controls
v_input_130len5
v_input_2_close0src: close | high | low | open | hl2 | hlc3 | hlcc4 | ohlc4
v_input_32Multiplier
v_input_420len
v_input_520Period

Source Pine Script

/*backtest
start: 2021-05-08 00:00:00
end: 2022-05-07 23:59:00
period: 4h
basePeriod: 15m
exchanges: [{"eid":"Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RafaelZioni

//@version=4

study(title="Bollinger lows", overlay=true)

len5 = input(30)

src=input(close)

//
multi = input(2, title="Multiplier", minval=0.001, maxval=2) 

mean = ema(src, len5)  
stddev = multi * stdev(src, len5)  
b = mean + stddev
s = mean - stddev


var bool long = na
var bool short = na

long :=crossover(src, s) 
short :=  crossunder(src, b)

var float last_open_long = na
var float last_open_short = na

last_open_long := long ? close : nz(last_open_long[1])
last_open_short := short ? close : nz(last_open_short[1])


entry_value =last_open_long
entry_value1=last_open_short

r=100
//
highb = highest(entry_value1, r)  
lowb = lowest(entry_value, r)  

//

hilow = ((high - low)*100)
openclose = ((close - open)*100)
vol = (src / hilow)
spreadvol = (openclose * src)
VPT = spreadvol + cum(spreadvol)
window_len = 28

v_len = 14
price_spread = stdev(high-low, window_len)

vp =  spreadvol + cum(spreadvol)
smooth = sma(vp, v_len)
v_spread = stdev(vp - smooth, window_len)
shadow = (vp - smooth) / v_spread * price_spread

out = shadow > 0 ? high + shadow : low + shadow
//

len = input(20)



yp=ema(out,len)

// INPUTS //
mult   =1
period = input(20, title = ' Period',     minval = 1)

// CALCULATIONS //
up= yp - (mult * atr(period))
dn = yp + (mult * atr(period))
c5=close
//

factor =0.001

hb = 0.00 ,hb := nz(hb[1])
hl = 0.000, hl := nz(hl[1])

lb = 0.00 ,lb := nz(lb[1])
l1 = 0.000,l1 := nz(l1[1])

c = 0
c := nz(c[1]) + 1

trend = 0,trend := nz(trend[1]),n = dn,x =up


if barstate.isfirst
    c := 0
    lb := n
    hb := x                      
    l1 := c5  
    hl := c5
    hl
if c == 1
    if x >= hb[1]
        hb := x
        hl := c5
        trend := 1  
        trend
    else
        lb := n
        l1 := c5 
        trend := -1 
        trend

if c > 1

    if trend[1] > 0  
        hl := max(hl[1], c5)
        if x >= hb[1] 
            hb := x
            hb
        else

            
            if n < hb[1] - hb[1] * factor 
                lb := n
                l1 := c5

                trend := -1  
                trend
    else

       
        l1 := min(l1[1], c5 )

        if n <= lb[1] 
            lb := n 
            lb
        else

           
            if x > lb[1] + lb[1] * factor
                hb := x 
                hl := c5

                trend := 1  
                trend



v = trend == 1 ? hb : trend == -1 ? lb : na
plot(v, color=trend == 1 ? color.blue : color.yellow, style=plot.style_circles, linewidth=1, title="trend", transp=0, join=true)
// Plotting
plot(v, color = trend == 1 ? color.green : color.red , style = plot.style_line, linewidth = 2, title = "SuperTrend")
low1 = crossover(v, lowb) 
high1 = crossunder(v, highb) 
showcross=true
plotshape( showcross and low1 , title="low", text="Low Bollinger", color=color.red, style=shape.labelup, location=location.belowbar, size=size.tiny, textcolor=color.white, transp=0)  
//plotshape(showcross and high1, title="high", text="H", color=color.green, style=shape.labeldown, location=location.abovebar, size=size.tiny, textcolor=color.white, transp=0)  
if low1
   strategy.entry("Alert on Bottom", strategy.long)
else if high1
    strategy.entry("Alert on Top", strategy.short)

Published by Zer3192 on the FMZ strategy square · last modified 2022-05-29. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.

Build this with AgenKit

A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Bollinger-lows.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. Get tests, backtest, risk controls and a paper-trading switch

Understand it first

Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.

Related specs

esc

Try , , or .

↑↓ move↵ open