How can I truncate numbers in Pine Script?

EdmasterEd

I have this table which shows me the values of RSI, ADX, DMI+ and DMI-. However, after the comma I have 10 number, but I want only 2 after it. How can I make this happen?

//===== RSI =====//
var string GP2 = "RSI Settings"
lenRSI = input.int(14, inline = "11", minval=1, title="RSI Length", group = GP2)
src = input(close, "RSI Source", inline = "11", group = GP2)
upRSI = ta.rma(math.max(ta.change(src), 0), lenRSI)
downRSI = ta.rma(-math.min(ta.change(src), 0), lenRSI)
rsi = downRSI == 0 ? 100 : upRSI == 0 ? 0 : 100 - (100 / (1 + upRSI / downRSI))

//===== DMI+/- =====//
var string GP3 = "ADX and DMI +/- Settings"
lensig = input.int(14, inline = "11", title="ADX Smoothing", minval=1, maxval=50, group = GP3)
voltrig = input.int(20, inline = "11", minval=1, title="ADX Volatility Trigger", group = GP3)
lenDMI = input.int(14, inline = "11", minval=1, title="DMI +/- Length", group = GP3)
upDMI = ta.change(high)
downDMI = -ta.change(low)
plusDMI = na(upDMI) ? na : (upDMI > downDMI and upDMI > 0 ? upDMI : 0)
minusDMI = na(downDMI) ? na : (downDMI > upDMI and downDMI > 0 ? downDMI : 0)
trur = ta.rma(ta.tr, lenDMI)
plus = fixnan(100 * ta.rma(plusDMI, lenDMI) / trur)
minus = fixnan(100 * ta.rma(minusDMI, lenDMI) / trur)
sum = plus + minus
adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), lensig)

//===== Table =====//
    var string GP4 = "Table Position"
string  tableYposInput = input.string("top", "Panel position", inline = "11", options = ["top", "middle", "bottom"], group = GP4)
string  tableXposInput = input.string("right", "", inline = "11", options = ["left", "center", "right"], group = GP4)

var testTable = table.new(position = position.top_right, columns = 4, rows = 3, bgcolor = color.rgb(250, 250, 250, 100), frame_color = color.rgb(250, 250, 250, 90), frame_width = 2, border_color = color.rgb(250, 250, 250, 90), border_width = 2)
if barstate.islast
    table.cell(table_id = testTable, column = 0, row = 0, text = "RSI", text_color = color.rgb(255, 186, 8))
    table.cell(table_id = testTable, column = 1, row = 0, text = "ADX", text_color = color.rgb(255, 186, 8))
    table.cell(table_id = testTable, column = 2, row = 0, text = "DMI+", text_color = color.rgb(255, 186, 8))
    table.cell(table_id = testTable, column = 3, row = 0, text = "DMI-", text_color = color.rgb(255, 186, 8))
    table.cell(table_id = testTable, column = 0, row = 1, text = "" + str.tostring(rsi), text_color = color.rgb(255, 186, 8))
    table.cell(table_id = testTable, column = 1, row = 1, text = "" + str.tostring(adx), text_color = color.rgb(255, 186, 8))
    table.cell(table_id = testTable, column = 2, row = 1, text = "" + str.tostring(plus), text_color = color.rgb(255, 186, 8))
    table.cell(table_id = testTable, column = 3, row = 1, text = "" + str.tostring(minus), text_color = color.rgb(255, 186, 8))
bbnm

You can use the format argument of the str.tostring(value, format) function.

str.tostring(rsi, ".##")

Este artículo se recopila de Internet, indique la fuente cuando se vuelva a imprimir.

En caso de infracción, por favor [email protected] Eliminar

Editado en
0

Déjame decir algunas palabras

0Comentarios
Iniciar sesiónRevisión de participación posterior

Artículos relacionados

Bash & Printf: How can I both right pad and truncate?

Pine Script: как нарисовать все линии на графике вручную

Как заполнять графики на данных разного разрешения в Pine Script?

How can I print numbers between two numbers that I enter?

Pine-Script - can't use IF on PLOTSHAPE, solutions?

How can I suppress (not print) line numbers?

How can I parse this numbers to timestamp?

How can I truncate a log file to a max number of lines from the bottom up?

How can I truncate a log file to a max number of lines from the bottom up?

How can I get all td elements with text-overflow: ellipsis where the text is truncate?

How to draw highest price of the previous month in the lower timeframes in Pine script?

Pine-script how to send alert on color change on RSI graph

How to find the value of a single candle x bar before in Pine Script

Comparison plot in Pine script

How can I click OK with Apple Script?

How can I create a testing script with GDB

How can I run a script after importing it?

How can I pass arguments into ps script

How can I get random numbers between -1024 and 1024 in vhdl

How can I update a field of a table with random numbers of specific range

How can I add line numbers to a textarea using an ordered list?

How can I "break up" numbers into smaller pieces in javascript?

How can I let my code return the average of the numbers?

How can I get just numbers in a field parsed to another field?

Java How can I calculate the average of numbers in an array?

How can I create a List of random int numbers without repeating?

How can I add different numbers in my text field?

How can I turn a string that contains numbers and operators into a result?

how can I use Split Method to parse this set of numbers?