如何为 line.new 定义蜡烛上/下和主体颜色

时间:2021-06-29 15:57:59

标签: pine-script

下午,

我似乎无法理解我哪里出错了。

我想要做的是根据价格在蜡烛内的位置确定新线的颜色:

如果价格在烛身内,颜色等于蓝色

如果价格较低,灯芯颜色等于绿色

如果价格是上部灯芯颜色等于红色

UW = max(open, close) > high
LW = low < min(open, close)
CandleBody = max(open, close) < min(open, close) and max(open, close) > min(open, close)

show_BTSL = input(true, title = "Show Candle Color", type = input.bool)
WickandCandleColor =  show_BTSL ?
     UW ? color.red : 
     LW ? color.green :
     CandleBody ? color.blue :
     color.blue :
     na
     

1 个答案:

答案 0 :(得分:0)

  1. 请记住,实时柱上的 close 是当前价格,因此在该柱上,您的代码不会按照您预期的方式运行。
  2. 您的条件需要改进。例如,max(open, close) > high 永远不会为真。这两者都不是:max(open, close) < min(open, close),因为两个值之间的最大值永远不会小于相同值之间的最小值。