Pine script Barssince将计算从绿色三角形到红色三角形的距离,而不是从绿色三角形到另一个绿色三角形的距离

Pine script Barssince将计算从绿色三角形到红色三角形的距离,而不是从绿色三角形到另一个绿色三角形的距离,pine-script,Pine Script,我有一个绿色三角形的长裤和红色三角形的短裤。Barssince是从一个绿色三角形到另一个绿色三角形,从一个红色到另一个红色。我想要的是barssince从一个绿色三角形变成一个红色三角形 fastSMA = sma(close, 15) slowSMA = sma(close, 45) enterLong = crossover(fastSMA, slowSMA) enterShort = crossunder(fastSMA, slowSMA) entryPrice = valuewhe

我有一个绿色三角形的长裤和红色三角形的短裤。Barssince是从一个绿色三角形到另一个绿色三角形,从一个红色到另一个红色。我想要的是barssince从一个绿色三角形变成一个红色三角形

fastSMA = sma(close, 15)
slowSMA = sma(close, 45)

enterLong  = crossover(fastSMA, slowSMA)
enterShort = crossunder(fastSMA, slowSMA)

entryPrice = valuewhen(enterLong or enterShort, close, 0)

plot(barsSinceLong, color = color.yellow)
plot(barsSinceShort, color = color.purple)

if barsSinceLong == 0 and barsSinceShort == 0
    c := c_NOT_IN_TRADE
if barsSinceLong > 0 and close < entryPrice
    c := c_LONG_ABOVE_ENTRYPRICE
else if barsSinceLong > 0 and close > entryPrice
    c := c_LONG_BELOW_ENTRYPRICE
else if barsSinceShort > 0 and close > entryPrice
    c := c_SHORT_BELOW_ENTRYPRICE
else if barsSinceShort > 0 and close < entryPrice
    c := c_SHORT_ABOVE_ENTRYPRICE
fastSMA=sma(关闭,15)
slowSMA=sma(闭合,45)
enterLong=交叉(快速SMA、慢速SMA)
enterShort=交叉(快速SMA、慢速SMA)
entryPrice=valuewhen(enterLong或enterShort,close,0)
绘图(长条形,颜色=颜色。黄色)
绘图(barsSinceShort,color=color.purple)
如果barsSinceLong==0且barsSinceShort==0
c:=c_不在交易中
如果barsSinceLong>0并关闭0且close>entryPrice
c:=c_LONG_低于入口价格
否则,如果barsSinceShort>0且close>entryPrice
c:=c\u短于\u入口价格
否则,如果barsSinceShort>0并关闭
您已经绘制了两个barssince(),因此您可以查看此函数的工作方式,您可以执行一个
交叉(barsSinceLong,BarsSincelShort)
,这样您将从长到短进行绘制。

基本上,我只想在入口和出口之间的这些蜡烛上应用barcolor。long应该是绿色,shorts应该是红色。可能类似于
valuewhen(enterLong,bar\u index,0)
,然后比较该范围,这样做更好吗?有多种方法,其中一种听起来像:
barcolor(barsSinceLong
,基本上它是一个if/else语句(如果long是最后一个信号,则将条涂成绿色,否则将条涂成红色)