Pinescript:我可以根据仅从当前柱派生的值转 on/off 一个绘图系列吗
Pinescript: Can I turn on/off a plot series based on a value derived from just the current bar
问题:
- 我有两条移动平均线 ema1, ema2
- 如果 ema1 大于 ema2 我只想显示 ema1 和它的历史值并隐藏另一个。
- 如果 ema1 小于 ema2 我 只 想显示 ema2 及其历史值并隐藏另一个。
我尝试了无数种方法,但我的快乐为零。
//@version=4
study("Line test")
ema1 = ema(close,5)
ema2 = ema(close,10)
var plot_ema_1 = false
var plot_ema_2 = false
if ema1[1] > ema2[1]
plot_ema_1 := true
plot_ema_2 := false
else
plot_ema_1 := false
plot_ema_2 := true
plot(plot_ema_1 ? ema1 : na, color=color.blue, title="EMA-1", style=plot.style_line)
plot(plot_ema_2 ? ema2 : na, color=color.orange, title="EMA-2", style=plot.style_line)
Picture of problem
我意识到我在现实生活中的使用有点棘手。
实际上有一个 third/fourth 变量..
correlation_to_asset1 和 correlation_to_asset2(这是 2 个独立的相关系数)。
我要满足的条件是
if (correlation_to_asset1 > correlation_to_asset2)
display_ema1_and_all_its_historical_data
// ema2 needs to be completely turned off. A combined line doesn't
// work as it messes with the scaling.
else
display_ema2_and_all_its_historical_data
// ema1 needs to be completely turned off. A combined line doesn't
// work as it messes with the scaling.
如有任何见解,我们将不胜感激。我们可以使用 ema3/ema4 作为第 3/4 个变量...我只是想介绍一些提到 cc 的上下文。
这显示了 3 种不同的方法。我们更喜欢方法#1:
//@version=4
study("Line test", "", true)
ema1 = ema(close,5)
ema2 = ema(close,10)
// ————— v1: plot the maximum of the 2 emas.
plotEma1 = ema1[1] > ema2[1]
c = plotEma1 ? color.blue : color.orange
mx = max(ema1, ema2)
plot(mx, color=c, title="EMA", style=plot.style_line)
plotchar(plotEma1 != plotEma1[1] ? mx : na, "Dot", "•", location.absolute, c, size = size.tiny)
// var plot_ema_1 = false
// var plot_ema_2 = false
// if ema1[1] > ema2[1]
// plot_ema_1 := true
// plot_ema_2 := false
// else
// plot_ema_1 := false
// plot_ema_2 := true
// ————— v2: plot `na` color when the line isn't needed.
// plot(ema1, color=plot_ema_1 ? color.blue : na, title="EMA-1", style=plot.style_line)
// plot(ema2, color=plot_ema_2 ? color.orange : na, title="EMA-2", style=plot.style_line)
// ————— v3: plot using linebreak style.
// plot(plot_ema_1 ? ema1 : na, color=color.blue, title="EMA-1", style=plot.style_linebr)
// plot(plot_ema_2 ? ema2 : na, color=color.orange, title="EMA-2", style=plot.style_linebr)
问题:
- 我有两条移动平均线 ema1, ema2
- 如果 ema1 大于 ema2 我只想显示 ema1 和它的历史值并隐藏另一个。
- 如果 ema1 小于 ema2 我 只 想显示 ema2 及其历史值并隐藏另一个。
我尝试了无数种方法,但我的快乐为零。
//@version=4
study("Line test")
ema1 = ema(close,5)
ema2 = ema(close,10)
var plot_ema_1 = false
var plot_ema_2 = false
if ema1[1] > ema2[1]
plot_ema_1 := true
plot_ema_2 := false
else
plot_ema_1 := false
plot_ema_2 := true
plot(plot_ema_1 ? ema1 : na, color=color.blue, title="EMA-1", style=plot.style_line)
plot(plot_ema_2 ? ema2 : na, color=color.orange, title="EMA-2", style=plot.style_line)
Picture of problem
我意识到我在现实生活中的使用有点棘手。 实际上有一个 third/fourth 变量.. correlation_to_asset1 和 correlation_to_asset2(这是 2 个独立的相关系数)。
我要满足的条件是
if (correlation_to_asset1 > correlation_to_asset2)
display_ema1_and_all_its_historical_data
// ema2 needs to be completely turned off. A combined line doesn't
// work as it messes with the scaling.
else
display_ema2_and_all_its_historical_data
// ema1 needs to be completely turned off. A combined line doesn't
// work as it messes with the scaling.
如有任何见解,我们将不胜感激。我们可以使用 ema3/ema4 作为第 3/4 个变量...我只是想介绍一些提到 cc 的上下文。
这显示了 3 种不同的方法。我们更喜欢方法#1:
//@version=4
study("Line test", "", true)
ema1 = ema(close,5)
ema2 = ema(close,10)
// ————— v1: plot the maximum of the 2 emas.
plotEma1 = ema1[1] > ema2[1]
c = plotEma1 ? color.blue : color.orange
mx = max(ema1, ema2)
plot(mx, color=c, title="EMA", style=plot.style_line)
plotchar(plotEma1 != plotEma1[1] ? mx : na, "Dot", "•", location.absolute, c, size = size.tiny)
// var plot_ema_1 = false
// var plot_ema_2 = false
// if ema1[1] > ema2[1]
// plot_ema_1 := true
// plot_ema_2 := false
// else
// plot_ema_1 := false
// plot_ema_2 := true
// ————— v2: plot `na` color when the line isn't needed.
// plot(ema1, color=plot_ema_1 ? color.blue : na, title="EMA-1", style=plot.style_line)
// plot(ema2, color=plot_ema_2 ? color.orange : na, title="EMA-2", style=plot.style_line)
// ————— v3: plot using linebreak style.
// plot(plot_ema_1 ? ema1 : na, color=color.blue, title="EMA-1", style=plot.style_linebr)
// plot(plot_ema_2 ? ema2 : na, color=color.orange, title="EMA-2", style=plot.style_linebr)