Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Pine script Pinescript-十进制输入选项_Pine Script - Fatal编程技术网

Pine script Pinescript-十进制输入选项

Pine script Pinescript-十进制输入选项,pine-script,Pine Script,我想在设置中有一个选项,可以输入标签上当前价格的小数位数,但无法使用label.new使其正常工作 所以对于输入选项,它应该是 DecOption = input(title="Decimal Option", options=["No Decimal", "One Decimal", "Two Decimal"], defval="No Decimal") 使用“#.##”静态十进制

我想在设置中有一个选项,可以输入标签上当前价格的小数位数,但无法使用label.new使其正常工作

所以对于输入选项,它应该是

DecOption = input(title="Decimal Option", options=["No Decimal", "One Decimal", "Two Decimal"],
     defval="No Decimal")
使用“#.##”静态十进制输出不是问题。。。但是在设置中选择它作为输入对我来说比较困难,有什么建议吗

//@version=4
study("Current Price", overlay=true)

symbolName = input(title="Type Symbol Or Leave Blank", defval="BTC")
    
sizeOption = input(title="Label Size", type=input.string,options=["Auto", "Huge", "Large", "Normal", "Small", "Tiny"],defval="Large")
     
labelSize = (sizeOption == "Huge") ? size.huge :
     (sizeOption == "Large") ? size.large :
     (sizeOption == "Small") ? size.small :
     (sizeOption == "Tiny") ? size.tiny :
     (sizeOption == "Auto") ? size.auto :
         size.normal

l = label.new(bar_index, na, text= symbolName +tostring( close, " $ #"), 
  color=close >= open ? color.green : color.red, 
  textcolor=color.white,
  style=label.style_labeldown, yloc=yloc.abovebar, size=labelSize)

label.delete(l[1])

该函数的参考手册中解释了格式字符串。
格式字符串。可选参数,默认值为“#.########”。
要显示尾随零,请使用0而不是“#”符号。例如,“0.000”

4位小数的示例:

//@version=4
study("Current Price", overlay=true)

symbolName = input(title="Type Symbol Or Leave Blank", defval="BTC")
    
sizeOption = input(title="Label Size", type=input.string,options=["Auto", "Huge", "Large", "Normal", "Small", "Tiny"],defval="Large")
     
labelSize = (sizeOption == "Huge") ? size.huge :
     (sizeOption == "Large") ? size.large :
     (sizeOption == "Small") ? size.small :
     (sizeOption == "Tiny") ? size.tiny :
     (sizeOption == "Auto") ? size.auto :
         size.normal

l = label.new(bar_index, na, text= symbolName +tostring( close, " $ #.0000"), 
  color=close >= open ? color.green : color.red, 
  textcolor=color.white,
  style=label.style_labeldown, yloc=yloc.abovebar, size=labelSize)

label.delete(l[1])
编辑1:响应
此示例提供了将小数数作为整数输入的选项。
它还可以通过限制小数位数。
您还可以决定是否显示小数的尾随零。
当您将符号输入留空时,它将默认为图表符号名称

//@version=4
study("Current Price", "CP", overlay=true)

LS0 = "Auto", LS1 = "Huge", LS2 = "Large", LS3 = "Normal", LS4 = "Small", LS5 = "Tiny"

var string  i_symbolName    = input("BTC",  "Type Symbol Or Leave Blank",   type=input.string)
var int     i_decimals      = input(4,      "Decimal option",               type=input.integer, minval=0, maxval=10)
var bool    i_limit_mintick = input(false,  "Decimals limited by mintick",  type=input.bool)
var bool    i_trailing_zero = input(true,   "Show decimal trailing zero's", type=input.bool)
var string  i_sizeOption    = input(LS2,    "Label Size",                   type=input.string,  options=[LS0, LS1, LS2, LS3, LS4, LS5])

var string  labelText       = na
var color   labelColor      = na
var string  labelSize       =  (i_sizeOption == LS0) ? size.auto   :
                               (i_sizeOption == LS1) ? size.huge   :
                               (i_sizeOption == LS2) ? size.large  :
                               (i_sizeOption == LS3) ? size.normal :
                               (i_sizeOption == LS4) ? size.small  :
                               (i_sizeOption == LS5) ? size.tiny   :
                               size.normal

var label   l               = label.new(na, na, na, yloc=yloc.abovebar, style=label.style_label_down, textcolor=color.white, size=labelSize)
var string  strFormatBase   = " $ #"
var string  strFormat       = na
var string  symbolName      = i_symbolName == "" ? syminfo.ticker : i_symbolName

if barstate.islast
    strFormat := strFormatBase + (i_decimals ? "." : "")

    for i = 1 to i_limit_mintick ? str.length(tostring(syminfo.mintick))-2 : i_decimals
        strFormat := strFormat + (i_trailing_zero ? "0" : "#")
    
    labelText  := symbolName + tostring(close, strFormat)
    labelColor := close >= open ? color.green : color.red

    label.set_x(l, bar_index)
    label.set_text(l, labelText)
    label.set_color(l, labelColor)

谢谢比约恩,但这不是我要找的,我已经知道我可以用#等使小数保持静态。。。。。我要找的是有一个输入选项,可以输入不同的十进制数,因此,用户可以在设置中输入他们希望在标签上显示的不同符号/标记的小数位数,如下所示。。deoption=input(title=“Decimal Option”,options=[“No Decimal”,“One Decimal”,“Two Decimal”],deffal=“No Decimal”)更新了我的答案。请看“编辑1”部分。哇,太棒了,非常感谢。我只是相信,为了让它显示当前价格,我必须在1秒的图表上运行它,因为我们正在使用close。我不认为有任何其他方式来显示当前的价格数据,无论你在什么时间段,没有必要在1秒图表上运行它。它将在任何时间范围内工作。在任何实时图表上,
close
仅表示最新(当前)价格。每次realtime
close
prices更改时,都会执行并重新计算脚本。所以它总是会在标签上显示当前的实时价格。很抱歉现在才回复你,我错过了你的回复,我现在才回到这个想法上。好的,是的,你是对的,可以看到它将在任何TF上工作,但有趣的是,当价格上涨时,标签将打印priec中的变化,很好,平滑,并保持不变。但由于某种原因,无论何时价格下跌,价格都会停留在最后一个最高价格上,并且在价格下跌的很长一段时间内似乎都赶不上。有什么原因吗。。。它这样做毫无意义,但事实确实如此