Pine 脚本:添加两个股票交易量值
Pine script: Adding two stocks volume values
我正在尝试获取两只股票的总交易量并绘制它。其中一个在 2022 年开始交易,另一个在 2021 年开始交易。我注意到情节从 2022 年开始,跳过了 2021 年第一只股票的交易量。
indicator("tasi_p1", overlay=false,format=format.volume)
src = request.security("TADAWUL:4164",timeframe.period,volume, barmerge.gaps_off)
src := src +
request.security("TADAWUL:2082",timeframe.period,volume, barmerge.gaps_off)
palette = close[1] > close ? color.red : color.green
plot(src,style=plot.style_histogram,color = palette)
我的主要目标是绘制 group/sector 相关股票的交易量并将其用于我的策略。
另外,我注意到在 TradingView 中添加股票代码时出现相同的行为,例如“4164 + 2082”,它会跳过 2021 部分,甚至在蜡烛图中也是如此。
是否存在错误或我遗漏了什么?
嗯,因为 4164
将 return NaN
作为其开始交易前的交易量。然后你试图在你不应该做的计算中使用这个 NaN
值。
将您的 src
换成 nz()
,它将用零替换 NaN
。
//@version=5
indicator("tasi_p1", overlay=false,format=format.volume)
src = request.security("TADAWUL:4164",timeframe.period,volume, barmerge.gaps_off)
src := nz(src) +
request.security("TADAWUL:2082",timeframe.period,volume, barmerge.gaps_off)
palette = close[1] > close ? color.red : color.green
plot(src,style=plot.style_histogram,color = palette)
我正在尝试获取两只股票的总交易量并绘制它。其中一个在 2022 年开始交易,另一个在 2021 年开始交易。我注意到情节从 2022 年开始,跳过了 2021 年第一只股票的交易量。
indicator("tasi_p1", overlay=false,format=format.volume)
src = request.security("TADAWUL:4164",timeframe.period,volume, barmerge.gaps_off)
src := src +
request.security("TADAWUL:2082",timeframe.period,volume, barmerge.gaps_off)
palette = close[1] > close ? color.red : color.green
plot(src,style=plot.style_histogram,color = palette)
我的主要目标是绘制 group/sector 相关股票的交易量并将其用于我的策略。
另外,我注意到在 TradingView 中添加股票代码时出现相同的行为,例如“4164 + 2082”,它会跳过 2021 部分,甚至在蜡烛图中也是如此。
是否存在错误或我遗漏了什么?
嗯,因为 4164
将 return NaN
作为其开始交易前的交易量。然后你试图在你不应该做的计算中使用这个 NaN
值。
将您的 src
换成 nz()
,它将用零替换 NaN
。
//@version=5
indicator("tasi_p1", overlay=false,format=format.volume)
src = request.security("TADAWUL:4164",timeframe.period,volume, barmerge.gaps_off)
src := nz(src) +
request.security("TADAWUL:2082",timeframe.period,volume, barmerge.gaps_off)
palette = close[1] > close ? color.red : color.green
plot(src,style=plot.style_histogram,color = palette)