微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 Pinescript 中生成交叉条件

如何解决在 Pinescript 中生成交叉条件

我想创建一个简单的交叉条件,我想在交叉时有一个买入卖出信号,我已经尝试过没有resoultion,但我希望它有resoultion,以便我可以为我的VWMA设置不同的时间范围。这是我的代码,请编辑它并告诉我,这会很有帮助。

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

//@version=4
strategy(title="VWMA",shorttitle="VWMA",overlay=true)

len = input(33,"Length",minval=1)
src = input(close,"Source",type = input.source)
resolution = input(title="Resolution",type=input.resolution,defval="5")

outer = vwma(src,len)
ss1 = security(syminfo.tickerid,resolution,outer,gaps=true)
mm2 = plot(ss1,color=#3A6CA8)


length = input(20,minval=1)
srce = input(close,type = input.source)
res = input(title="Resolution",defval="15")

//ma = vwma(src,len)
//offset = input(0,"Offset",type = input.integer,minval = -500,maxval = 500)
//plot(ma,title="VWMA",color=#3A6CA8,offset = offset)

out = vwma(srce,length)
s1 = security(syminfo.tickerid,res,out,gaps=true)
m2 = plot(s1,color=#3A6CA8)

我对 pinescrpit 不太熟悉,所以我尽力添加条件,但总是令人失望。所以我只需要在我的代码中设置一个条件。

解决方法

//@version=4
study(title="VWMA",shorttitle="VWMA",overlay=true)

//vwma 1
len = input(9,"Length",minval=1)
src = input(close,"Source",type = input.source)
ma = vwma(src,len)
plot(ma,title="VWMA",color=color.blue)

//vwma 2
len2 = input(20,minval=1)
src2 = input(close,type = input.source)
ma2 = vwma(src2,len2)
plot(ma2,color=color.yellow)


//cond
longcondition = crossover(ma,ma2)
plotshape(longcondition,size = size.small)

//MTF
t = input("240",type = input.resolution)
ma_mtf = security(syminfo.tickerid,t,ma)
ma2_mtf = security(syminfo.tickerid,ma2)
plot(ma_mtf,title="VWMA MTF",color=color.red)
plot(ma2_mtf,color=color.aqua)

//cond MTF
longcondition_mtf = crossover(ma_mtf,ma2_mtf)
plotshape(longcondition_mtf,size = size.small,color = color.fuchsia)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。