Pine script SMA绿色蜡烛
我想创建一个移动平均线的绿色蜡烛唯一的结束 不幸的是,我由另一个用户找到(并放在下面)的脚本返回错误的结果。 当前的结果是一条直线,它正确地连接绿色,如果连续的话,但是如果中间有一个或多个红色蜡烛,同一条线是水平的和断裂的,因为它保持了先前绿色闭合的最后一个值。 我怎样才能有一条线连接每个绿色闭合而不中断 在图像中显示脚本的结果Pine script SMA绿色蜡烛,pine-script,tradingview-api,Pine Script,Tradingview Api,我想创建一个移动平均线的绿色蜡烛唯一的结束 不幸的是,我由另一个用户找到(并放在下面)的脚本返回错误的结果。 当前的结果是一条直线,它正确地连接绿色,如果连续的话,但是如果中间有一个或多个红色蜡烛,同一条线是水平的和断裂的,因为它保持了先前绿色闭合的最后一个值。 我怎样才能有一条线连接每个绿色闭合而不中断 在图像中显示脚本的结果 smagreenbar=平均过去绿色烛光(1) plot(smagreenbar,color=color.green,linewidth=2)不确定这是否会对脚本产生
smagreenbar=平均过去绿色烛光(1)
plot(smagreenbar,color=color.green,linewidth=2)
不确定这是否会对脚本产生影响,但您拼写错误了avarege=sum/amount
averagePastgreenCandles(amount) =>
// number of counted candles
candles = 0
// current average
sum = 0.0
// check if the number of candles so far has exceeded the amount of bars on the chart
if bar_index > amount
// start counting with a limit of the current bars in chart
for i=0 to bar_index - 1
// confirm if the candle is green
if close[i] > open[i]
// add the average
sum := sum + close[i]
// add count of the candles we have counted
candles := candles + 1
// check if we have reached the amount of the candles that we want
if candles == amount
//close the loop
break
// return the average
avarege = sum/amount