【问题标题】:Struggling to convert Pine Script from v1 to v5努力将 Pine Script 从 v1 转换为 v5
【发布时间】:2023-02-05 19:52:26
【问题描述】:

请看下面我在 Trading View 上找到的一个指标。我想将其转换为 v5,但 tradingview pinescript 中没有出现任何选项。有人可以帮我解决这个问题吗?

非常感谢

study("Supertrend V1.0 - Buy or Sell Signal", overlay = true)

Factor=input(3, minval=1,maxval = 100)
Pd=input(7, minval=1,maxval = 100)


Up=hl2-(Factor*atr(Pd))
Dn=hl2+(Factor*atr(Pd))


TrendUp=close[1]>TrendUp[1]? max(Up,TrendUp[1]) : Up
TrendDown=close[1]<TrendDown[1]? min(Dn,TrendDown[1]) : Dn

Trend = close > TrendDown[1] ? 1: close< TrendUp[1]? -1: nz(Trend[1],1)
Tsl = Trend==1? TrendUp: TrendDown

linecolor = Trend == 1 ? green : red

plot(Tsl, color = linecolor , style = line , linewidth = 2,title = "SuperTrend")

plotshape(cross(close,Tsl) and close>Tsl , "Up Arrow", shape.triangleup,location.belowbar,green,0,0)
plotshape(cross(Tsl,close) and close<Tsl , "Down Arrow", shape.triangledown , location.abovebar, red,0,0)
//plot(Trend==1 and Trend[1]==-1,color = linecolor, style = circles, linewidth = 3,title="Trend")

plotarrow(Trend == 1 and Trend[1] == -1 ? Trend : na, title="Up Entry Arrow", colorup=lime, maxheight=60, minheight=50, transp=0)
plotarrow(Trend == -1 and Trend[1] == 1 ? Trend : na, title="Down Entry Arrow", colordown=red, maxheight=60, minheight=50, transp=0)

【问题讨论】:

    标签: pine-script pine-script-v5 pine-script-v4


    【解决方案1】:

    自动转换工具从v3 开始工作。因此,您需要自己将其更新为v3,然后让该工具完成其工作。

    唯一需要注意的是self referenced variables are removed

    //@version=5
    indicator('Supertrend V1.0 - Buy or Sell Signal', overlay=true)
    
    Factor = input.int(3, minval=1, maxval=100)
    Pd = input.int(7, minval=1, maxval=100)
    
    Up = hl2 - Factor * ta.atr(Pd)
    Dn = hl2 + Factor * ta.atr(Pd)
    
    TrendUp = 0.0
    TrendUp := close[1] > TrendUp[1] ? math.max(Up, TrendUp[1]) : Up
    TrendDown = 0.0
    TrendDown := close[1] < TrendDown[1] ? math.min(Dn, TrendDown[1]) : Dn
    
    Trend = 0.0
    Trend := close > TrendDown[1] ? 1 : close < TrendUp[1] ? -1 : nz(Trend[1], 1)
    Tsl = Trend == 1 ? TrendUp : TrendDown
    
    linecolor = Trend == 1 ? color.green : color.red
    
    plot(Tsl, color=linecolor, style=plot.style_line, linewidth=2, title='SuperTrend')
    
    plotshape(ta.cross(close, Tsl) and close > Tsl, 'Up Arrow', shape.triangleup, location.belowbar, color.new(color.green, 0), 0)
    plotshape(ta.cross(Tsl, close) and close < Tsl, 'Down Arrow', shape.triangledown, location.abovebar, color.new(color.red, 0), 0)
    //plot(Trend==1 and Trend[1]==-1,color = linecolor, style = circles, linewidth = 3,title="Trend")
    
    plotarrow(Trend == 1 and Trend[1] == -1 ? Trend : na, title='Up Entry Arrow', colorup=color.new(color.lime, 0), maxheight=60, minheight=50)
    plotarrow(Trend == -1 and Trend[1] == 1 ? Trend : na, title='Down Entry Arrow', colordown=color.new(color.red, 0), maxheight=60, minheight=50)
    

    【讨论】:

      【解决方案2】:

      你能帮我处理那个代码吗?我如何转换为版本 3 @vitruvius

      study(shorttitle = "MACD 4C", title = "4 colour MACD")
      fastMA = input(title="Fast moving average", type = integer, defval = 12, minval = 7)
      slowMA = input(title="Slow moving average", type = integer, defval = 26, minval = 7)
      lastColor = yellow
      [currMacd,_,_] = macd(close[0], fastMA, slowMA, 9)
      [prevMacd,_,_] = macd(close[1], fastMA, slowMA, 9)
      plotColor = currMacd > 0 
          ? currMacd > prevMacd ? lime : green 
          : currMacd < prevMacd ? maroon : red
      plot(currMacd, style = histogram, color = plotColor, linewidth = 3)
      plot(0, title = "Zero line", linewidth = 1, color = gray)
      

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-01-13
      • 2021-06-16
      • 2014-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多