how to debug arrays values in pinescript?

Viewed 598

I have this script:

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)

I want to console/debug/display the values in start_prices array But I can't figure out for the life of me how to do that, there's no console.log or anything like that. I'm a somewhat competent python programmer, but I always use the print()... Anyway, how do people debug in this language?

1 Answers

You can use the tostring() function (str.tostring() in v5) to generate a string of your array. You can then output it into a label or table.

eg.

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])
Related