首页 > 解决方案 > Pine Script - 向上和向下趋势的多色线

问题描述

下面的代码显示上升趋势和下降趋势的单色线。上升趋势和下降趋势之间也有一条连接线。有人可以帮我获得 2 条颜色线并删除上升趋势和下降趋势之间的连接线。更多细节可以在截图中找到。图片

//@version=4
study(title="Trend Line", shorttitle="Trend Line", overlay=true, resolution="")
length = input(20,"Entry Length", minval=1)
len2=input(10, "Exit Length", minval=1)        

lower = lowest(length)
upper = highest(length)

up=highest(high,length)
down=lowest(low,length)
K1=barssince(high>=up[1])<=barssince(low<=down[1]) ? down : up
plot(K1, title="Trend Line", color=color.red, linewidth=2)

标签: pine-script

解决方案


我认为你需要这样的结果

//@version=4
study(title="Trend Line", shorttitle="Trend Line", overlay=true, resolution="")
length = input(20,"Entry Length", minval=1)
len2 = input(10, "Exit Length", minval=1)        

lower = lowest(length)
upper = highest(length)

up = highest(high,length)
down = lowest(low,length)

K1 = barssince(high >= up[1])<=barssince(low <= down[1]) ? down : up

linecolor = (open > K1) and (open[1] > K1[1]) ? color.red : (open < K1) and (open[1] <     K1[1]) ? color.green : na

plot(K1, title="Trend Line", style = plot.style_linebr, color=linecolor, linewidth=2)

推荐阅读