【问题标题】:how to debug arrays values in pinescript?如何调试 pinescript 中的数组值?
【发布时间】:2022-01-19 03:26:26
【问题描述】:

我有这个脚本:

strategy("My strategy")
var float   start_price     = na
var float   end_price       = na
var float[] start_prices    = array.new_float(0)
var float[] end_prices      = array.new_float(0)
var float   p               = na

f(x) => math.round(x / 500) * 500

lo = (high + close) / 2

var i = 0

if bar_index == 1 
    start_price := f(lo)
    end_price   := f(start_price * 1.015)
else
    if close <= start_price
        strategy.entry(str.format("Long {0}",i), strategy.long)
        array.push(end_prices, end_price)
        array.push(start_prices, end_price)
        i := i + 1
        start_price := start_price - 500
        end_price   := f(start_price * 1.015)

for j = 0 to (array.size(end_prices) == 0 ? na : array.size(end_prices) - 1)
    p := array.get(end_prices, j)
    if close >= p
        strategy.exit(str.format("Long {0}",j), limit=end_price)

我想控制台/调试/显示start_prices数组中的值 但是我一生都无法弄清楚如何做到这一点,没有console.log或类似的东西。我是一个有点称职的python程序员,但我总是使用print()... 无论如何,人们如何用这种语言进行调试?

【问题讨论】:

    标签: arrays debugging pine-script


    【解决方案1】:

    您可以使用tostring() 函数(v5 中的str.tostring())生成数组的字符串。然后您可以将其输出到标签或表格中。

    例如。

    start_prices_string = str.tostring(start_prices)
    debug = label.new(x = bar_index, y = close, style = label.style_label_left, text = start_prices_string)
    label.delete(debug[1])
    

    【讨论】:

      猜你喜欢
      • 2022-06-14
      • 1970-01-01
      • 2021-02-28
      • 1970-01-01
      • 2022-12-12
      • 2022-12-05
      • 2022-12-06
      • 2021-04-15
      • 2022-01-01
      相关资源
      最近更新 更多