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.
Feb 11
版本注释: Bollinger Bands Long-only strategy. Recurring alerts that I am having trouble getting rid of.
从收藏脚本中删除 添加到收藏脚本

评论

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)
回复
When I copy/pasted it took out the indents after the if statements, so you'll just have to add those back.
回复
@Jomy, thank you! You're great!
回复
drutrading88 noscoobies_drew
@noscoobies_drew, Hey ! Was it updated ? Can i try it ? :D
回复
noscoobies_drew drutrading88
@drutrading88, just updated it.
回复
@Jomy, You wouldn't know how to remove the recurring alerts, would you?
回复
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:
回复
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")
回复
I screwed that up. hang on.
回复
I didn't screw it up, it just didn't paste properly... I'll try something else.
回复
首页 股票筛选器 外汇筛选器 加密货币筛选器 财经日历 如何运作 图表功能 价格 推荐朋友 网站规则 帮助中心 网站 & 经纪商解决方案 插件 图表解决方案 轻量图表库 博客 & 新闻 Twitter
概览 个人资料设置 账户和账单 推荐朋友 我的客服工单 帮助中心 已发表观点 粉丝 正在关注 私人消息 在线聊天 退出