如何在 pine editor tradingview 中获取之前的文本或趋势线

How to get previous Text or trend line in pine editor tradingview

我正在使用 pine 编辑器在 TradingView 中进行编码,我正在使用 3 个超级趋势,现在是下降趋势,第一个超级趋势给出卖出 [红色] 信号并从向下的红线开始,然后第二个超级趋势给出卖出 [Orande in color] 信号并从向下的红线开始,与第三个超级趋势 [紫色] 类似的过程,在这里如果所有超级趋势都发出卖出信号,那么我需要显示一个大的父卖出信号,表明所有卖出条件已满足,现在如果其中一个信号变为绿色,表示买入信号,随后又变为红色,即卖出信号,则图表上应该再次显示母卖出信号。这暗示我需要从这里做空。 我附上了屏幕截图,你能帮我看看代码吗?

这里是代码供大家参考

//@version=4
study("ST", overlay = true, format=format.price, precision=2, resolution="")

Periods         = input(title="ATR Period", type=input.integer, defval=10)
src             = input(hl2, title="Source")
Multiplier      = input(title="ATR Multiplier", type=input.float, step=0.1, defval=1.0)
changeATR       = input(title="Change ATR Calculation Method ?", type=input.bool, defval=true)
showsignals     = input(title="Show Buy/Sell Signals ?", type=input.bool, defval=true)
highlighting    = input(title="Highlighter On/Off ?", type=input.bool, defval=false)

buyBool         = false
sellBool        = false

atr2            = sma(tr, Periods)
atr             = changeATR ? atr(Periods) : atr2
up              = src-(Multiplier*atr)
up1             = nz(up[1],up)

up              := close[1] > up1 ? max(up,up1) : up
dn              = src+(Multiplier*atr)
dn1             = nz(dn[1], dn)
dn              := close[1] < dn1 ? min(dn, dn1) : dn

trend           = 1
trend           := nz(trend[1], trend)
trend           := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend

upPlot          = plot(trend == 1 ? up : na, title="Up Trend", style=plot.style_linebr, linewidth=1, color=color.green)

buySignal       = trend == 1 and trend[1] == -1

plotshape(buySignal                 ? up : na, title="UpTrend Begins",             location=location.absolute, style=shape.circle,  size=size.tiny, color=color.green,                        transp=0)
plotshape(buySignal and showsignals ? up : na, title="Buy",            text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0)

dnPlot          = plot(trend == 1   ? na : dn, title="Down Trend", style=plot.style_linebr, linewidth=1, color=color.red)

sellSignal      = trend == -1 and trend[1] == 1

plotshape(sellSignal                 ? dn : na, title="DownTrend Begins",              location=location.absolute, style=shape.circle,    size=size.tiny, color=color.red,                        transp=0)
plotshape(sellSignal and showsignals ? dn : na, title="Sell",             text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0)

mPlot           = plot(ohlc4, title="", style=plot.style_circles, linewidth=0)

longFillColor   = highlighting ? (trend ==  1 ? color.green : color.white) : color.white
shortFillColor  = highlighting ? (trend == -1 ? color.red   : color.white) : color.white

fill(mPlot, upPlot, title="UpTrend Highligter",   color=longFillColor)
fill(mPlot, dnPlot, title="DownTrend Highligter", color=shortFillColor)

alertcondition(buySignal,  title="SuperTrend Buy",  message="SuperTrend Buy!")
alertcondition(sellSignal, title="SuperTrend Sell", message="SuperTrend Sell!")

changeCond      = trend != trend[1]

alertcondition(changeCond, title="SuperTrend Direction Change", message="SuperTrend has changed direction!")

Periods1        = input(   11, title="atr1 Period",                      type=input.integer)
src1            = input(  hl2, title="Source")
Multiplier1     = input(  2.0, title="atr1 Multiplier1",                 type=input.float, step=0.1)
changeatr11     = input( true, title="Change atr1 Calculation Method ?", type=input.bool)
showsignals1    = input( true, title="Show Buy/Sell Signals ?",          type=input.bool)
highlighting1   = input(false, title="Highlighter On/Off ?",             type=input.bool)

buyBool1        = false
sellBool1       = false

atr121          = sma(tr, Periods1)
atr1            = changeatr11 ? atr(Periods1) : atr121
up123           = src1-(Multiplier1*atr1)
up1231          = nz(up123[1],up123)
up123           := close[1] > up1231 ? max(up123,up1231) : up123
dn123           = src1+(Multiplier1*atr1)
dn1231          = nz(dn123[1], dn123)
dn123           := close[1] < dn1231 ? min(dn123, dn1231) : dn123
trend1          = 1
trend1          := nz(trend1[1], trend1)
trend1          := trend1 == -1 and close > dn1231 ? 1 : trend1 == 1 and close < up1231 ? -1 : trend1

up123Plot1      = plot(trend1 == 1 ? up123 : na, title="up123 trend1", style=plot.style_linebr, linewidth=1, color=color.green)

buySignal1      = trend1 == 1 and trend1[1] == -1

plotshape(buySignal1                  ? up123 : na, title="up123trend1 Begins",             location=location.absolute, style=shape.circle,  size=size.tiny, color=color.orange,                        transp=0)
plotshape(buySignal1 and showsignals1 ? up123 : na, title="Buy",                text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.orange, textcolor=color.white, transp=0)

dn123Plot       = plot(trend1 == 1 ? na : dn123, title="Down trend1", style=plot.style_linebr, linewidth=1, color=color.red)
sellSignal1     = trend1 == -1 and trend1[1] == 1

plotshape(sellSignal1                  ? dn123 : na, title="Downtrend1 Begins",              location=location.absolute, style=shape.circle,    size=size.tiny, color=color.orange,                        transp=0)
plotshape(sellSignal1 and showsignals1 ? dn123 : na, title="Sell",              text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.orange, textcolor=color.white, transp=0)

mPlot1          = plot(ohlc4, title="", style=plot.style_circles, linewidth=0)

longFillColor1  = highlighting1 ? (trend1 ==  1 ? color.green : color.white) : color.white
shortFillColor1 = highlighting1 ? (trend1 == -1 ? color.red   : color.white) : color.white

fill(mPlot1, up123Plot1, title="up123trend1 Highligter", color=longFillColor1)
fill(mPlot1, dn123Plot,  title="Downtrend1 Highligter",  color=shortFillColor1)

alertcondition(buySignal1,  title="Sup123ertrend1 Buy",  message="Sup123ertrend1 Buy!")
alertcondition(sellSignal1, title="Sup123ertrend1 Sell", message="Sup123ertrend1 Sell!")

changeCond1     = trend1 != trend1[1]

alertcondition(changeCond1, title="Sup123ertrend1 Direction Change", message="Sup123ertrend1 has changed direction!")
//@version=4
study("SuperTrend", "ST", true)

var float   m1          = input(1,  "ATR Multiplier", input.float,   step=0.1, group="Supertrend 1")
var int     p1          = input(10, "ATR Period",     input.integer,           group="Supertrend 1")
var float   m2          = input(1,  "ATR Multiplier", input.float,   step=0.1, group="Supertrend 2")
var int     p2          = input(15, "ATR Period",     input.integer,           group="Supertrend 2")
var float   m3          = input(1,  "ATR Multiplier", input.float,   step=0.1, group="Supertrend 3")
var int     p3          = input(20, "ATR Period",     input.integer,           group="Supertrend 3")

f_getColor_Resistance(_dir, _color) => _dir ==  1 and _dir == _dir[1] ? _color : na
f_getColor_Support(_dir, _color) =>    _dir == -1 and _dir == _dir[1] ? _color : na

[superTrend1, dir1] = supertrend(m1, p1)
[superTrend2, dir2] = supertrend(m2, p2)
[superTrend3, dir3] = supertrend(m3, p3)

sum_dir   = dir1 + dir2 + dir3
dir_long  = sum_dir==-3
dir_short = sum_dir==3

if (dir_long and dir_long != dir_long[1])
    label.new(bar_index, low, "Long",   style=label.style_label_up)

if (dir_short and dir_short != dir_short[1])
    label.new(bar_index, high, "Short", style=label.style_label_down)

colR1 = f_getColor_Resistance(dir1, color.red)
colS1 = f_getColor_Support(   dir1, color.green)

colR2 = f_getColor_Resistance(dir2, color.orange)
colS2 = f_getColor_Support(   dir2, color.yellow)

colR3 = f_getColor_Resistance(dir3, color.blue)
colS3 = f_getColor_Support(   dir3, color.maroon)

plot(superTrend1, "R1", colR1, linewidth=2)
plot(superTrend1, "S1", colS1, linewidth=2)

plot(superTrend2, "R1", colR2, linewidth=2)
plot(superTrend2, "S1", colS2, linewidth=2)

plot(superTrend3, "R1", colR3, linewidth=2)
plot(superTrend3, "S1", colS3, linewidth=2)