取先签松剧本

Take first sign pine script

我一直在尝试在版本 2 中进行构建登录。但是,这是在版本 4 中执行的。 有人可以在版本 2 中帮助我吗?非常感谢

// Determine currently LONG or SHORT
isLong = nz(isLong[1], false)
isShort = nz(isShort[1], false)

// Buy or Sell only if the buy signal is triggered and not already long or short
buySignal = not isLong and buy
sellSignal = not isShort and sell

if (buySignal)
    isLong := true
    isShort := false

if (sellSignal)
    isLong := false
    isShort := true
    
plotshape(series=buySignal, text='Buy', style=shape.labelup, location=location.belowbar, offset=0, color=#009688, textcolor=#ffffff, size=size.small)

plotshape(series=sellSignal, text='Sell', style=shape.labeldown, location=location.abovebar, offset=0, color=#F44336, textcolor=#ffffff, size=size.small)

将您的脚本升级到 v5 并删除 isShort,您不需要它。

//@version=5
indicator("My script", overlay=true)

_sma = ta.sma(close, 9)

buy = ta.crossover(close, _sma)
sell = ta.crossunder(close, _sma)

// Determine currently LONG or SHORT
var isLong = false

// Buy or Sell only if the buy signal is triggered and not already long or short
buySignal = not isLong and buy
sellSignal = isLong and sell

if (buySignal)
    isLong := true

if (sellSignal)
    isLong := false

plot(_sma)
plotshape(series=buySignal, text='Buy', style=shape.labelup, location=location.belowbar, offset=0, color=#009688, textcolor=#ffffff, size=size.small)
plotshape(series=sellSignal, text='Sell', style=shape.labeldown, location=location.abovebar, offset=0, color=#F44336, textcolor=#ffffff, size=size.small)