Pine Script 音量指示器不太工作

问题描述 投票:0回答:1

我想创建一个指标,当当前蜡烛的买入或卖出量高于前 (x) 根蜡烛时显示给我。
我很确定我拥有一切,有些正确,但我没有在我的图表上绘制任何东西。
在我想更改条形颜色之前,我尝试使用标签)。

最好,我想知道当前金条的购买量是否高于之前任何金条的购买量。
与销量相同。

老实说,我不知道该怎么做。如果有人可以看一下,我已经在下面粘贴了脚本。如果有人可以帮助我计算柱内交易量,那也很棒。我不确定这是否可能。谢谢大家!

//@version=5

indicator("Volume", overlay=true)

// Inputs
lookback = input(20, "Lookback Period", tooltip = "The number of previous candles to check for volume")
bullishcolor = input(color.green, "Bullish Color")
bearishcolor = input(color.red, "Bearish Color")

// Variables
highestvolume = ta.highest(volume, lookback)
bullishvolume = false
bearishvolume = false

// Calculations
if volume > highestvolume and (close>=open)
    bullishvolume := true
if volume > highestvolume and (close<open)
    bearishvolume := true

// Plot volume indication
barcolor(bullishvolume ? bearishcolor : bearishvolume ? bearishcolor : na)

我试过用 label.new() 绘图,但没有用。我也尝试过使用所有交易量而不是将它们分为看涨和看跌,但仍然没有运气

pine-script pine-script-v5 trading pinescript-v5
1个回答
0
投票

当您从最高柱测试时,它包括当前柱。
所以你永远不会满足这个条件:

volume > highestvolume 

因为最高音量总是至少等于音量。

你应该改变你的 if 条件:

// Calculations
if volume >= highestvolume and (close>=open)
    bullishvolume := true
if volume >= highestvolume and (close<open)
    bearishvolume := true

我测试了它,当满足条件时看到彩色条。

© www.soinside.com 2019 - 2024. All rights reserved.