noscoobies_drew

NoScoobies Bollinger Bands

Bollinger Bands strategy that I am trying out, however I can't get my strategy.close to work. Looking for help.
Release Notes: Bollinger Bands Long-only strategy. Recurring alerts that I am having trouble getting rid of.
Remove from Favorite Scripts Add to Favorite Scripts

Comments

Try this:
//@version=4
strategy(title="NoScoobies Bollinger Bands", overlay=true)
source = close
length = input(20, minval=1, title = "Period") //Length of the Bollinger Band
mult = input(1.5, minval=0.001, maxval=50, title = "Standard Deviation") // Use 1.5 SD for 20 period MA; Use 2 SD for 10 period MA

basis = sma(source, length)
dev = mult * stdev(source, length)

upper = basis + dev
lower = basis - dev

long=crossover(source, basis)
short=crossunder(source, basis)
close_long=crossunder(source, upper)
close_short=crossover(source, lower)

if long
strategy.entry("Long", strategy.long)

if close_long
strategy.close("Long", when = strategy.position_size>0)

if short
strategy.entry("Short", strategy.short)

if close_short
strategy.close("Short", when = strategy.position_size<0)

plot(basis, color=color.red,title= "SMA")
p1 = plot(upper, color=color.blue,title= "UB")
p2 = plot(lower, color=color.blue,title= "LB")
fill(p1, p2)
Reply
When I copy/pasted it took out the indents after the if statements, so you'll just have to add those back.
Reply
@Jomy, thank you! You're great!
Reply
drutrading88 noscoobies_drew
@noscoobies_drew, Hey ! Was it updated ? Can i try it ? :D
Reply
noscoobies_drew drutrading88
@drutrading88, just updated it.
Reply
@Jomy, You wouldn't know how to remove the recurring alerts, would you?
Reply
Jomy noscoobies_drew
I use what I call an "on-until-off" switch to stop multiple alerts. I'll paste a chunk of code below which should work. Take out your alertcondition lines, and try replacing with this chunk of code:
Reply
longswitch=0
longswitch:=long?1:nz(longswitch)
longswitch:=close_long?0:longswitch

shortswitch=0
shortswitch:=short?1:nz(shortswitch)
longswitch:=close_short?0:shortswitch

alertcondition(longswitch==1 and longswitch==0, title="LONG", message="FCEL")
alertcondition(longswitch==0 and longswitch==1, title="CLOSE LONG", message="FCEL")
//alertcondition(shortswitch==1 and shortswitch==0, title="LONG", message="FCEL")
//alertcondition(shortswitch==0 and shortswitch==1, title="CLOSE LONG", message="FCEL")
Reply
I screwed that up. hang on.
Reply
I didn't screw it up, it just didn't paste properly... I'll try something else.
Reply
Home Stock Screener Forex Screener Crypto Screener Economic Calendar How It Works Chart Features Pricing Refer a friend House Rules Help Center Website & Broker Solutions Widgets Charting Solutions Lightweight Charting Library Blog & News Twitter
Profile Profile Settings Account and Billing Refer a friend My Support Tickets Help Center Ideas Published Followers Following Private Messages Chat Sign Out