从图表参数中删除空值

Remove empty values from chart parameters

有没有办法去除下图中的空值,使其不出现在图表中?

代码在此link: https://www.tradingview.com/v/UGSk1G42/

目前在 Pine Script 中尚无法做到这一点。

您可能对配置工作区的能力感到满意。但此设置将应用于所有指标。

这些值不是空值。

它们是交叉计算,所以当没有交叉时,它等于零 0。当交叉时,它等于 1。

如果将鼠标放在信号(绿色和红色三角形)上,您会看到零之一 0 变为 1。

你的图片中有六个零,下面是true=1或false=0的代码行。

如果您要删除下面的代码,您将删除“1 和 0”,但您也会丢失视觉三角形信号。

// monthly trend
plotshape(series=crossover(sma_month, sma_quarter), title="SMA Uptrend", style=shape.triangleup, location=location.belowbar, color=color.green, text="SMA Monthly", size=size.small)
plotshape(series=crossunder(sma_month, sma_quarter), title="SMA Downtrend", style=shape.triangledown, location=location.abovebar, color=color.red, text="SMA Monthly", size=size.small)

// quarterly trend
plotshape(series=crossover(sma_quarter, sma_halfYear), title="SMA Uptrend", style=shape.triangleup, location=location.belowbar, color=color.green, text="SMA Quarterly", size=size.small)
plotshape(series=crossunder(sma_quarter, sma_halfYear), title="SMA Downtrend", style=shape.triangledown, location=location.abovebar, color=color.red, text="SMA Quaterly", size=size.small)

// yearly trend
plotshape(series=crossover(sma_halfYear, sma_year), title="SMA Uptrend", style=shape.triangleup, location=location.belowbar, color=color.green, text="SMA Yearly", size=size.small)
plotshape(series=crossunder(sma_halfYear, sma_year), title="SMA Downtrend", style=shape.triangledown, location=location.abovebar, color=color.red, text="SMA Yearly", size=size.small)  

您可以使用警报条件,但这意味着您必须设置 6 个警报,并且根据 TradingView 会员资格,您可能无法做到。

这会去掉值,也会去掉显示视觉效果,并会在满足条件时向您发送弹出警报。

//@version=4
study(title="Monthly, Quaterly, Yearly SMA Trends", shorttitle="SMATrends", overlay=true, linktoseries=true)

// you can update the SMA values here (rounded values)
sma_month = sma(close, 20) // 20 trading days in a month
sma_quarter = sma(close, 60) // 60 trading days in a quarter
sma_halfYear = sma(close, 120) // 120 trading days in half a year
sma_year = sma(close, 250) // 250 trading days in a year

// you can comment to disable trendlines in the chart
plot(sma_month, title="20 SMA", color=#003C7B, linewidth=2, transp=50)
plot(sma_quarter, title="60 SMA", color=#FC8A10, linewidth=1, transp=50)
plot(sma_halfYear, title="120 SMA", color=#00DB00, linewidth=1, transp=50)
plot(sma_year, title="250 SMA", color=#FEDA15, linewidth=1, transp=50)



alertcondition(crossover(sma_month, sma_quarter), title="SMA Monthly Uptrend", message="SMA Monthly Uptrend")
alertcondition(crossunder(sma_month, sma_quarter), title="SMA Monthly Downtrend", message="SMA Monthly Downtrend")

alertcondition(crossover(sma_quarter, sma_halfYear), title="SMA Quaterly Uptrend", message="SMA Quaterly Uptrend")
alertcondition(crossunder(sma_quarter, sma_halfYear), title="SMA Quaterly Downtrend", message="SMA Quaterly Downtrend")

alertcondition(crossover(sma_halfYear, sma_year), title="SMA Yearly Uptrend", message="SMA Yearly Uptrend")
alertcondition(crossunder(sma_halfYear, sma_year), title="SMA Yearly Downtrend", message="SMA Yearly Downtrend")

这个问题稍微想了一下,我觉得下面符合你原来的要求。

//@version=4
study(title="Monthly, Quaterly, Yearly SMA Trends", shorttitle="SMATrends", overlay=true, linktoseries=true)

// you can update the SMA values here (rounded values)
sma_month = sma(close, 20) // 20 trading days in a month
sma_quarter = sma(close, 60) // 60 trading days in a quarter
sma_halfYear = sma(close, 120) // 120 trading days in half a year
sma_year = sma(close, 250) // 250 trading days in a year

// you can comment to disable trendlines in the chart
plot(sma_month, title="20 SMA", color=#003C7B, linewidth=2, transp=50)
plot(sma_quarter, title="60 SMA", color=#FC8A10, linewidth=1, transp=50)
plot(sma_halfYear, title="120 SMA", color=#00DB00, linewidth=1, transp=50)
plot(sma_year, title="250 SMA", color=#FEDA15, linewidth=1, transp=50)

// monthly trend

SMAMUp = crossover(sma_month, sma_quarter)
if SMAMUp
    label.new(bar_index, na, text="SMA Monthly Uptrend", yloc=yloc.belowbar, color=color.green, style=label.style_label_up) 

SMAMDown = crossunder(sma_month, sma_quarter)
if SMAMDown
    label.new(bar_index, na, text="SMA Monthly Downtrend", yloc=yloc.abovebar, color=color.red, style=label.style_label_down) 


SMAQUp = crossover(sma_quarter, sma_halfYear)
if SMAQUp
    label.new(bar_index, na, text="SMA Quarterly Uptrend", yloc=yloc.belowbar, color=color.green, style=label.style_label_up) 
SMAQDown = crossunder(sma_quarter, sma_halfYear)
if SMAQDown
    label.new(bar_index, na, text="SMA Quarterly Downtrend", yloc=yloc.abovebar, color=color.red, style=label.style_label_down) 

SMAYUp = crossover(sma_halfYear, sma_year)
if SMAYUp
    label.new(bar_index, na, text="SMA Yearly Uptrend", yloc=yloc.belowbar, color=color.green, style=label.style_label_up) 
SMAYDown = crossunder(sma_halfYear, sma_year)
if SMAYDown
    label.new(bar_index, na, text="SMA Yearly Downtrend", yloc=yloc.abovebar, color=color.red, style=label.style_label_down)