【发布时间】:2021-03-14 10:42:43
【问题描述】:
我正在使用 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!")
【问题讨论】:
-
请分享您已有的代码。
-
@BjornMistiaen 我已经编辑了我的问题,你可以在那里找到代码
-
请发布可编译的代码。这给出了错误
Script could not be translated from: |B|up := close[1] > -
@BjornMistiaen 抱歉,请您现在检查一下。
-
为了便于阅读,我对您的代码进行了格式化和重构。您能否编辑您的问题以准确解释您想要什么?特别是你所说的“以前”。上一个酒吧?上一次发生?以前与什么有关?什么时候需要重置“先前的”检测?等等...如果可能,请附上您的意思的屏幕截图。
标签: pine-script