noscoobies_drew

NoScoobies Bollinger Bands

809 görüntülenme
29
Bollinger Bands strategy that I am trying out, however I can't get my strategy.close to work. Looking for help.
Sürüm Notları: Bollinger Bands Long-only strategy. Recurring alerts that I am having trouble getting rid of.
Favori Komutlardan Çıkart Favori Komutlara Ekle

Yorumlar

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)
Cevap Gönder
When I copy/pasted it took out the indents after the if statements, so you'll just have to add those back.
Cevap Gönder
@Jomy, thank you! You're great!
Cevap Gönder
drutrading88 noscoobies_drew
@noscoobies_drew, Hey ! Was it updated ? Can i try it ? :D
Cevap Gönder
noscoobies_drew drutrading88
@drutrading88, just updated it.
Cevap Gönder
@Jomy, You wouldn't know how to remove the recurring alerts, would you?
Cevap Gönder
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:
Cevap Gönder
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")
Cevap Gönder
I screwed that up. hang on.
Cevap Gönder
I didn't screw it up, it just didn't paste properly... I'll try something else.
Cevap Gönder
Ana Sayfa Hisse Senedi Takipçisi Forex Takipçisi Kripto Takipçisi Ekonomik Takvim Nasıl Çalışır Grafik Özellikleri Ücretlendirme Tanıdık yönlendirme Kurallarımız Destek Merkezi Web Sitesi & Aracı Kurum Çözümleri Görsel Bileşenler(Widget) Grafik Çözümleri Hafif Grafik Kitaplığı Blog ve Haberler Twitter
Profil Profil Ayarları Hesap ve Ödemeler Tanıdık yönlendirme Destek Kayıtlarım Destek Merkezi Yayınlanmış Fikirler Takip Edenler Takip ediliyor Özel Mesajlar Sohbet Çıkış