简体   繁体   中英

Pine-script: How to summ float numbers

I struggle to make working code that summ my float numbers. Please help! I know how to make for integer. But for float numbers it just doesn't work! For example, when I add label.new to my graph for int numbers label shows summ, but for float it prints NaN

version = 4
study("test", "test", true, max_lines_count=500)
float visota = 1.2
var float counter = 0.0
var float delta = 0.0
var float vector = 0.0
delta = round((close - close[1]), 1)
if (barstate.isconfirmed)
    counter := counter + delta
label.new(bar_index, low - 4, tostring(counter))

Protect delta variable from n/a values on the very first bar using the nz() function and format the label's text to the ticker's mintick, as is shown below:

//@version = 4
study("test", overlay = true)
var float counter = 0.0
float delta = nz(round((close - close[1]), 1))

if (barstate.isconfirmed)
    counter += delta

label.new(bar_index, low - 4, tostring(counter, format.mintick))

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM