英文:
Converting a study into a strategy on pinescript
问题
以下是您提供的代码的翻译部分:
//@version=5
strategy(title='Volume Flow Indicator [LazyBear]', shorttitle='VFI_LB', overlay = true)
length = input(130, title='VFI length')
coef = input(0.2)
vcoef = input(2.5, title='Max. vol. cutoff')
signalLength = input(5)
smoothVFI = input(false)
if ta.sma(x, y) >= smoothVFI
ta.sma(x, y)
else
X
typical = hlc3
inter = math.log(typical) - math.log(typical[1])
vinter = ta.stdev(inter, 30)
cutoff = coef * vinter * close
vave = ta.sma(volume, length)[1]
vmax = vave * vcoef
vc = if volume < vmax
volume
else
vmax
mf = typical - typical[1]
vcp = if mf > cutoff
vc
if mf < -cutoff
vc * -1
else
0
vfi = ta.sma(math.sum(vcp, length) / vave, 3)
vfima = ta.ema(vfi, signalLength)
d = vfi - vfima
plot(0, color=color.new(color.gray, 0), style=plot.style_cross)
showHisto = input(false)
plot(showHisto ? d : na, style=plot.style_histogram, color=color.new(color.gray, 50), linewidth=3)
plot(vfima, title='EMA of vfi', color=color.new(color.orange, 0))
plot(vfi, title='vfi', color=color.new(color.green, 0), linewidth=2)
请注意,这只是代码的翻译部分,不包括问题的解决方法。如果您需要修复代码中的错误,请查看您提到的错误信息并进行相应的更改。如果需要进一步的帮助,请提供具体的错误信息,以便我可以为您提供更多的指导。
英文:
Im trying to build a strategy with an indicator from lazy bear on pinescript. The code looks like this:
//@version=5
strategy(title='Volume Flow Indicator [LazyBear]', shorttitle='VFI_LB', overlay = true)
length = input(130, title='VFI length')
coef = input(0.2)
vcoef = input(2.5, title='Max. vol. cutoff')
signalLength = input(5)
smoothVFI = input(false)
if ta.sma(x, y) >= smoothVFI
ta.sma(x, y)
else
X
// sma_1 = ta.sma(x, y)
// smoothVFI ? sma_1 : x
typical = hlc3
inter = math.log(typical) - math.log(typical[1])
vinter = ta.stdev(inter, 30)
cutoff = coef * vinter * close
vave = ta.sma(volume, length)[1]
vmax = vave * vcoef
vc = if volume < vmax
volume
else
vmax //min( volume, vmax )
mf = typical - typical[1]
vcp = if mf > cutoff
vc
if mf < -cutoff
vc * -1
else
0
vfi = ta.sma(math.sum(vcp, length) / vave, 3)
vfima = ta.ema(vfi, signalLength)
d = vfi - vfima
plot(0, color=color.new(color.gray, 0), style=plot.style_cross)
showHisto = input(false)
plot(showHisto ? d : na, style=plot.style_histogram, color=color.new(color.gray, 50), linewidth=3)
plot(vfima, title='EMA of vfi', color=color.new(color.orange, 0))
plot(vfi, title='vfi', color=color.new(color.green, 0), linewidth=2)
These are my current mistakes and I do not know how to fix them.
Fehler in 11:11 Undeclared identifier 'x'
Fehler in 11:14 Undeclared identifier 'y'
Fehler in 14:5 Undeclared identifier 'X'
Fehler in 11:20 Cannot call 'operator >=' with argument 'expr1'='smoothVFI'. An argument of 'input bool' type was used but a 'simple float' is expected.
My idea is that I just want to do some backtesting on how it works to simply enter a long trade when the vfi crosses the zero above. Its not a standalone idea, I just want to implement that indicator into other strategies Im currently trading. Does anybody know how to fix these errors? Thanks for the help!
答案1
得分: 0
以下是已翻译的代码部分:
ma(x, y) => smoothVFI ? ta.sma(x, y) : x
//@version=5
indicator(title="Volume Flow Indicator [LazyBear]", shorttitle="VFI_LB")
length = input(130, title="VFI length")
coef = input(0.2)
vcoef = input(2.5, title="Max. vol. cutoff")
signalLength = input(5)
smoothVFI = input.bool(false)
ma(x, y) => smoothVFI ? ta.sma(x, y) : x
typical = hlc3
inter = math.log(typical) - math.log(typical[1])
vinter = ta.stdev(inter, 30)
cutoff = coef * vinter * close
vave = ta.sma(volume, length)[1]
vmax = vave * vcoef
vc = if (volume < vmax)
volume
else
vmax //min( volume, vmax )
mf = typical - typical[1]
vcp = if (mf > cutoff)
vc
else
if (mf < -cutoff)
-vc
else
0
vfi = ma(math.sum(vcp, length) / vave, 3)
vfima = ta.ema(vfi, signalLength)
d = vfi - vfima
plot(0, color=color.gray, style=plot.style_circles)
showHisto = input.bool(false)
plot(showHisto ? d : na, style=plot.style_histogram, color=color.new(color.gray, 50), linewidth=3)
plot(vfima, title="EMA of vfi", color=color.orange)
plot(vfi, title="vfi", color=color.green, linewidth=2)
希望这对您有所帮助。如果您有任何其他翻译需求,请随时告诉我。
英文:
Below line in the original code is actually a function and not a call to ta.sma()
(in v5
).
ma(x,y) => smoothVFI ? sma(x,y) : x
So, you should write this also as a function.
Below code is the correct way of upgrading this code to v5
:
//@version=5
indicator(title = "Volume Flow Indicator [LazyBear]", shorttitle="VFI_LB")
length = input(130, title="VFI length")
coef = input(0.2)
vcoef = input(2.5, title="Max. vol. cutoff")
signalLength=input(5)
smoothVFI=input.bool(false)
ma(x,y) => smoothVFI ? ta.sma(x,y) : x
typical=hlc3
inter = math.log( typical ) - math.log( typical[1] )
vinter = ta.stdev(inter, 30 )
cutoff = coef * vinter * close
vave = ta.sma( volume, length )[1]
vmax = vave * vcoef
vc = if (volume < vmax)
volume
else
vmax //min( volume, vmax )
mf = typical - typical[1]
vcp = if (mf > cutoff)
vc
else
if (mf < -cutoff)
-vc
else
0
vfi = ma(math.sum( vcp , length )/vave, 3)
vfima=ta.ema( vfi, signalLength )
d=vfi-vfima
plot(0, color=color.gray, style=plot.style_circles)
showHisto=input.bool(false)
plot(showHisto ? d : na, style=plot.style_histogram, color=color.new(color.gray, 50), linewidth=3)
plot( vfima , title="EMA of vfi", color=color.orange)
plot( vfi, title="vfi", color=color.green,linewidth=2)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论