Plot 需要绘制所有相关蜡烛的支撑和阻力,但仅在交叉点绘制

Plot 需要绘制所有相关蜡烛的支撑和阻力,但仅在交叉点绘制,plot,pine-script,Plot,Pine Script,我想在所有蜡烛上画一个支撑点,当价格越过前一季度高点和前一个月高点,然后穿过前一周的低点时,收盘成为支撑点。 只要价格保持低于前一周的高位,每一次收盘都将成为支撑。只要价格不低于上季度低点或上个月低点,这种情况就会保持,然后支撑也会停止。它现在只在交叉点绘制 对于阻力来说,情况正好相反。 /@version=3 //陪审团 //------------------------------- //支持 //如果价格越过上季度最高点和上个月最高点,然后又越过上周最低点,那么收盘价将成为支撑。 //

我想在所有蜡烛上画一个支撑点,当价格越过前一季度高点和前一个月高点,然后穿过前一周的低点时,收盘成为支撑点。 只要价格保持低于前一周的高位,每一次收盘都将成为支撑。只要价格不低于上季度低点上个月低点,这种情况就会保持,然后支撑也会停止。它现在只在交叉点绘制

对于阻力来说,情况正好相反。

/@version=3
//陪审团
//-------------------------------
//支持
//如果价格越过上季度最高点和上个月最高点,然后又越过上周最低点,那么收盘价将成为支撑。
//只要价格保持在前一周的高点以下,每次收盘都会成为支撑。只要价格不交叉,这种情况就不会改变
//低于上季度低点或上个月低点,则支撑也停止。
//-------------------------------
//抵抗力
//如果价格在上季度低点和上个月低点下方交叉,然后在上周高点上方交叉,收盘价将成为阻力。
//只要价格保持在前一周低点之上,每次收盘都会成为支撑。只要价格不交叉,这种情况就不会改变
//高于前一季度高点或前一个月高点,则阻力也停止。
研究(title=“通用支撑与阻力”,shorttitle=“大学支撑与恢复”,叠加=真实,精度=8)
prevwkH=输入(true,title=“显示上周高点?”)
prevwkL=输入(true,title=“显示上周低点?”)
//前一周
prevWeekHigh=安全性(tickerid,'W',high[1],lookahead=true)
prevWeekLow=security(tickerid,'W',low[1],lookahead=true)
//上周的情节
绘图(prevwkH和prevWeekHigh?prevWeekHigh:na,title=“Prev Week High”,style=stepline,linewidth=1,color=green,transp=20)
绘图(prevwkL和prevWeekLow?prevWeekLow:na,title=“Prev Week Low”,style=stepline,linewidth=1,color=green,transp=20)
//警报
买入=收盘>周末高
卖出=收盘<前一周
Buyposmemo=false
买吗?真的:卖吗?false:Buyposmemo[1]
Buynow=买而不买(Buyposmemo[1])
bgcolor(Buynow?颜色(绿色,90):na)
Sellposmemo=false
Sellposmemo:=卖出?真的:买吗?错误:Sellposmemo[1]
Sellnow=卖出且不卖出(Sellposmemo[1])
bgcolor(Sellnow?颜色(红色,90):na)
alertcondition(购买,title=“立即购买”,message=“立即购买”)
alertcondition(出售,title=“立即出售”,message=“立即出售”)
//-------------------------------------------------------------
//通用趋势线
prevQuarterHigh=安全性(tickerid,'3M',high[1],lookahead=true)
prevQuarterLow=安全性(tickerid,'3M',low[1],lookahead=true)
上升趋势=错误
上升趋势:=(非上升趋势[1]和交叉(收盘,前四分之一高))或(上升趋势[1]和非交叉(收盘,前四分之一低))
//-------------------------------------------------------------
//阴谋支持与抵抗
绘图(向上和向下交叉(关闭,前一周低)?低-(高-低+1):na,样式=圆形,颜色=绿色,传输=0,线宽=4)
绘图(非上升趋势和交叉(闭合,前一周高)?高+(高-低+1):na,样式=圆圈,颜色=红色,传输=0,线宽=4)

每当我遇到问题时,我总是用
研究(overlay=false)
克隆我的代码,并绘制一些我怀疑导致问题的信号

因此,在您的情况下,您可以将代码复制并粘贴到新的指示符,并在末尾添加以下行。请删除所有其他
plot()
函数。否则,将出现缩放问题,结果将不那么明显

//plot support & resistance 
plot(series=upTrend ? 1:0, color=color.orange)
plot(series=crossunder(close, prevWeekLow) ? 1:0, color=color.green)
plot(series=crossover(close, prevWeekHigh) ? 1:0, color=color.red)
结果是:

如果仔细观察,这里的问题是
crossover()
crossunder()
函数仅在发生交叉/交叉时返回
BOOL
值。因此,plot函数中的条件仅在一个条上变为
TRUE

您需要做的是找出如何保持交叉/交叉的信号
TRUE
,直到遇到相反的信号

为此,我建议您开始使用
v4
。然后可以使用
var
关键字。使用
var
关键字创建的变量保留其值,直到您覆盖它们。因此,您可以执行以下操作:

var isSupport = false
var isResistance = false 

if (crossunder(close, prevWeekLow))
    isSupport := true
    isResistance := false

if (crossover(close, prevWeekHigh))
    isSupport := false
    isResistance := true
以下是使用
v4
的完整代码:

//@version=4
//By Juros
//-------------------------------
// support
// If the price crosses above the previous quarter high and previous month high, and then crosses down the previous week low, the close becomes a support. 
//As long as the price stays then below the previous week high, each close becomes a support. The    condition remains as long as the prices do not cross 
//below previous quarter low OR previous month low, then support also stops.

//-------------------------------
// resistance
// If the price crosses below the previous quarter low and previous month low, and then crosses up the previous week high, the close becomes a resistance.
// As long as the price stays then above the previous week low, each close becomes a support.  The condition remains as long as the price does not cross
// above previous quarter high OR previous month high, then resistance also stops.


study(title="Universal support and resistance", shorttitle="Univ sup & res", overlay=true, precision=8)
prevwkH = input(true, title="Show previous week high?")
prevwkL = input(true, title="show previous week low?")

//previous week
prevWeekHigh = security(syminfo.tickerid, 'W', high[1], lookahead=true)
prevWeekLow = security(syminfo.tickerid, 'W', low[1], lookahead=true)

//previous Week Plots
plot(prevwkH and prevWeekHigh ? prevWeekHigh : na, title="Prev Week High", style=plot.style_stepline,   linewidth=1, color=color.green,transp=20)
plot(prevwkL and prevWeekLow ? prevWeekLow : na, title="Prev Week Low", style=plot.style_stepline, linewidth=1, color=color.green,transp=20)

// alerts
Buy = close > prevWeekHigh
Sell = close < prevWeekLow

Buyposmemo = false
Buyposmemo := Buy ? true : Sell ? false : Buyposmemo[1]
Buynow = Buy and not (Buyposmemo[1])
bgcolor(Buynow ?  color(color.green) :na)

Sellposmemo = false
Sellposmemo := Sell ? true : Buy ? false : Sellposmemo[1]
Sellnow = Sell and not (Sellposmemo[1])
bgcolor(Sellnow ?  color(color.red) :na)

alertcondition(Buy, title = "Buy now", message="buy now")
alertcondition(Sell, title = "Sell now", message="Sell now")

//-------------------------------------------------------------

//universal trend line
prevQuarterHigh = security(syminfo.tickerid, '3M', high[1], lookahead=true)
prevQuarterLow = security(syminfo.tickerid, '3M', low[1], lookahead=true)

upTrend = false
upTrend := (not upTrend[1] and crossover(close, prevQuarterHigh)) or (upTrend[1] and not    crossunder(close, prevQuarterLow))

//-------------------------------------------------------------
var isSupport = false
var isResistance = false 

if (crossunder(close, prevWeekLow))
    isSupport := true
    isResistance := false

if (crossover(close, prevWeekHigh))
    isSupport := false
    isResistance := true

//plot support & resistance 
plot (upTrend and isSupport ? low-(high-low+1) : na, style=plot.style_circles, color=color.green, transp=0, linewidth=4 )
plot (not upTrend and isResistance ? high+(high-low+1) : na, style=plot.style_circles, color=color.red, transp=0, linewidth=4 )
/@version=4
//陪审团
//-------------------------------
//支持
//如果价格越过上季度最高点和上个月最高点,然后又越过上周最低点,那么收盘价将成为支撑。
//只要价格保持在前一周的高点以下,每次收盘都会成为支撑。只要价格不交叉,这种情况就不会改变
//低于上季度低点或上个月低点,则支撑也停止。
//-------------------------------
//抵抗力
//如果价格在上季度低点和上个月低点下方交叉,然后在上周高点上方交叉,收盘价将成为阻力。
//只要价格保持在前一周低点之上,每次收盘都会成为支撑。只要价格不交叉,这种情况就不会改变
//高于前一季度高点或前一个月高点,则阻力也停止。
研究(title=“通用支撑与阻力”,shorttitle=“大学支撑与恢复”,叠加=真实,精度=8)
prevwkH=输入(true,title=“显示上周高点?”)
prevwkL=输入(true,title=“显示上周低点?”)
//前一周
prevWeekHigh=security(syminfo.tickerid,'W',high[1],lookahead=true)
prevWeekLow=security(syminfo.tickerid,'W',low[1],lookahead=true)
//上周的情节
绘图(prevwkH和prevWeekHigh?prevWeekHigh:na,title=“Prev Week High”,style=plot.style\u stepline,线宽=1,颜色=color
//@version=4
//By Juros
//-------------------------------
// support
// If the price crosses above the previous quarter high and previous month high, and then crosses down the previous week low, the close becomes a support. 
//As long as the price stays then below the previous week high, each close becomes a support. The    condition remains as long as the prices do not cross 
//below previous quarter low OR previous month low, then support also stops.

//-------------------------------
// resistance
// If the price crosses below the previous quarter low and previous month low, and then crosses up the previous week high, the close becomes a resistance.
// As long as the price stays then above the previous week low, each close becomes a support.  The condition remains as long as the price does not cross
// above previous quarter high OR previous month high, then resistance also stops.


study(title="Universal support and resistance", shorttitle="Univ sup & res", overlay=true, precision=8)
prevwkH = input(true, title="Show previous week high?")
prevwkL = input(true, title="show previous week low?")

//previous week
prevWeekHigh = security(syminfo.tickerid, 'W', high[1], lookahead=true)
prevWeekLow = security(syminfo.tickerid, 'W', low[1], lookahead=true)

//previous Week Plots
plot(prevwkH and prevWeekHigh ? prevWeekHigh : na, title="Prev Week High", style=plot.style_stepline,   linewidth=1, color=color.green,transp=20)
plot(prevwkL and prevWeekLow ? prevWeekLow : na, title="Prev Week Low", style=plot.style_stepline, linewidth=1, color=color.green,transp=20)

// alerts
Buy = close > prevWeekHigh
Sell = close < prevWeekLow

Buyposmemo = false
Buyposmemo := Buy ? true : Sell ? false : Buyposmemo[1]
Buynow = Buy and not (Buyposmemo[1])
bgcolor(Buynow ?  color(color.green) :na)

Sellposmemo = false
Sellposmemo := Sell ? true : Buy ? false : Sellposmemo[1]
Sellnow = Sell and not (Sellposmemo[1])
bgcolor(Sellnow ?  color(color.red) :na)

alertcondition(Buy, title = "Buy now", message="buy now")
alertcondition(Sell, title = "Sell now", message="Sell now")

//-------------------------------------------------------------

//universal trend line
prevQuarterHigh = security(syminfo.tickerid, '3M', high[1], lookahead=true)
prevQuarterLow = security(syminfo.tickerid, '3M', low[1], lookahead=true)

upTrend = false
upTrend := (not upTrend[1] and crossover(close, prevQuarterHigh)) or (upTrend[1] and not    crossunder(close, prevQuarterLow))

//-------------------------------------------------------------
var isSupport = false
var isResistance = false 

if (crossunder(close, prevWeekLow))
    isSupport := true
    isResistance := false

if (crossover(close, prevWeekHigh))
    isSupport := false
    isResistance := true

//plot support & resistance 
plot (upTrend and isSupport ? low-(high-low+1) : na, style=plot.style_circles, color=color.green, transp=0, linewidth=4 )
plot (not upTrend and isResistance ? high+(high-low+1) : na, style=plot.style_circles, color=color.red, transp=0, linewidth=4 )