问题:
我尝试了无数种方法,但是却拥有零快乐。
//@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)
我在现实生活中的使用情况有点复杂。 实际上有一个第三/第四变量。 related_to_asset1和correlation_to_asset2(这是两个独立的相关系数)。
我要满足的条件是
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的上下文。
答案 0 :(得分:0)
这显示了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)