TradingView
dc4free
31 янв 2020 г., 20:02

NoScoobies Bollinger Bands 

Bitcoin / US Dollar Perpetual Inverse Swap ContractBitMEX

Описание

Bollinger Bands strategy that I am trying out, however I can't get my strategy.close to work. Looking for help.

Информация о релизе

Bollinger Bands Long-only strategy. Recurring alerts that I am having trouble getting rid of.
Комментарии
Jomy
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)
Jomy
When I copy/pasted it took out the indents after the if statements, so you'll just have to add those back.
dc4free
@Jomy, thank you! You're great!
drutrading88
@noscoobies_drew, Hey ! Was it updated ? Can i try it ? :D
dc4free
@drutrading88, just updated it.
dc4free
@Jomy, You wouldn't know how to remove the recurring alerts, would you?
Jomy
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:
Jomy
longswitch=0
longswitch:=long?1:nz(longswitch[1])
longswitch:=close_long?0:longswitch

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

alertcondition(longswitch==1 and longswitch[1]==0, title="LONG", message="FCEL")
alertcondition(longswitch==0 and longswitch[1]==1, title="CLOSE LONG", message="FCEL")
//alertcondition(shortswitch==1 and shortswitch[1]==0, title="LONG", message="FCEL")
//alertcondition(shortswitch==0 and shortswitch[1]==1, title="CLOSE LONG", message="FCEL")
Jomy
I screwed that up. hang on.
Jomy
I didn't screw it up, it just didn't paste properly... I'll try something else.
Ещё