将研究转化为Pine Script策略

huangapple go评论72阅读模式
英文:

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=&#39;Volume Flow Indicator [LazyBear]&#39;, shorttitle=&#39;VFI_LB&#39;, overlay = true)

length = input(130, title=&#39;VFI length&#39;)
coef = input(0.2)
vcoef = input(2.5, title=&#39;Max. vol. cutoff&#39;)
signalLength = input(5)
smoothVFI = input(false)

if ta.sma(x, y) &gt;= 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 &lt; vmax
    volume
else
    vmax  //min( volume, vmax )

mf = typical - typical[1]

vcp = if mf &gt; cutoff
    vc
if mf &lt; -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=&#39;EMA of vfi&#39;, color=color.new(color.orange, 0))
plot(vfi, title=&#39;vfi&#39;, 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) =&gt; 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 = &quot;Volume Flow Indicator [LazyBear]&quot;, shorttitle=&quot;VFI_LB&quot;)

length = input(130, title=&quot;VFI length&quot;)
coef = input(0.2)
vcoef = input(2.5, title=&quot;Max. vol. cutoff&quot;)
signalLength=input(5)
smoothVFI=input.bool(false)

ma(x,y) =&gt; 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 &lt; vmax)
    volume
else
    vmax //min( volume, vmax )

mf = typical - typical[1]

vcp = if (mf &gt; cutoff)
    vc
else
    if (mf &lt; -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=&quot;EMA of vfi&quot;, color=color.orange)
plot( vfi, title=&quot;vfi&quot;, color=color.green,linewidth=2)

huangapple
  • 本文由 发表于 2023年6月6日 00:36:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76408418.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定