【问题标题】:showing extra color boxes显示额外的颜色框
【发布时间】:2022-08-19 10:46:49
【问题描述】:

我是 tradingview pinescript 代码的新手。所以,有些问题我不知道如何解决。 我从脚本中删除了所有 input.*() 运算符,以删除“设置”中的“输入”选项卡(第 22 到 38 行)。 当我这样做时,会显示额外的 2 个颜色框 -> 颜色 1,颜色 2 Screenshot

如何删除这些颜色框,包括颜色 0 而没有像这样的输入选项卡 -> Edited above Screenshot

这是整个脚本

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © cryptoweeknd

//@version=5
indicator(\"ADR\", overlay=true)

//ADR side of script below

text_ADR1_high = \'ADR Upper\'
text_ADR2_high = \'ADR Upper\'

text_ADR1_low = \'ADR Lower\'
text_ADR2_low = \'ADR Lower\'

lime = #00FF00 //ADR2 Low
limes = #00FF00 //ADR1 Low
red = #FF4000 //ADR1 High
reds = #FF4000 //ADR2 High

//***Start of Inputs

labels_enabled = true

color_ADR1_high = red
color_ADR2_high = reds

color_ADR1_low = lime
color_ADR2_low = limes

adrUppercolorfill = red
adrlowercolorfill = lime
   
//***End of Inputs

//***Start of local functions definiton***

adr_1 = 10
adr_2 = 5

draw_line(_x1, _y1, _x2, _y2, _xloc, _extend, _color, _style, _width) =>
    dline = line.new(x1=_x1, y1=_y1, x2=_x2, y2=_y2, xloc=_xloc, extend=_extend, color=_color, style=_style, width=_width)
    line.delete(dline[1])
    
draw_label(_x, _y, _text, _xloc, _yloc, _color, _style, _textcolor, _size, _textalign, _tooltip) =>
    dlabel = label.new(x=_x, y=_y, text=_text, xloc=_xloc, yloc=_yloc, color=_color, style=_style, textcolor=_textcolor, size=_size, textalign=_textalign, tooltip=_tooltip)
    label.delete(dlabel[1])

//If security is futures - replace the ticker with continuous contract
tickerid_func() =>
    tickerid = syminfo.tickerid
    if syminfo.type == \'futures\'
        tickerid := syminfo.root + \'1!\'

//Function to calculate ADR levels
//Parameters:
//  * lengthInput - ADR period
//  * hi_low - true-->High, else-->Low 
adr_func(lengthInput,hi_low) =>
    float result = 0
    float adr = 0
    open_ = request.security(tickerid_func(), \"D\", open, barmerge.gaps_off, barmerge.lookahead_on)
    adr_High = request.security(tickerid_func(), \"D\", ta.sma(high[1], lengthInput), barmerge.gaps_off, barmerge.lookahead_on)
    adr_Low = request.security(tickerid_func(), \"D\", ta.sma(low[1], lengthInput), barmerge.gaps_off, barmerge.lookahead_on)
    adr := (adr_High - adr_Low)
    
    if hi_low//High
        result := adr/2 + open_
    else    //Low
        result := open_ - adr/2    

//Workaround to disable color management on the standard tab Style for plots
//Custom inputs for colors should be used instead
transp_func() =>
    transp_0 = 0

//***End of local functions definiton***

//***Start of getting data

start_time = request.security(tickerid_func(), \"D\", time_close[1],barmerge.gaps_off,barmerge.lookahead_on)
open__ = request.security(tickerid_func(), \"D\", open, barmerge.gaps_off, barmerge.lookahead_on)

start_time1 = request.security(tickerid_func(), \"W\", time_close[1],barmerge.gaps_off,barmerge.lookahead_on)

adr1_high = adr_func(adr_1,true)
adr1_low = adr_func(adr_1,false)
adr2_high = adr_func(adr_2,true)
adr2_low = adr_func(adr_2,false)

//***End of getting data

float _adr1_high = na
float _adr1_low = na
float _adr2_high = na
float _adr2_low = na
float _open = na

//*********************

//***Start of plotting*

//Decide if we can show the chart:
//Daily levels should be visible on intraday chart only

var show_chart = false

if timeframe.isintraday
    show_chart := true
    
//Plot all days
if show_chart
    _adr1_high := adr1_high
    _adr1_low  := adr1_low
    _adr2_high := adr2_high
    _adr2_low  := adr2_low
    _open      := open__

ADR1_high = plot(_adr1_high, title=text_ADR1_high, color=ta.change(_adr1_high) ? na : color_ADR1_high, linewidth=1)
ADR2_high = plot(_adr2_high, title=text_ADR2_high, color=ta.change(_adr2_high) ? na : color_ADR2_high, linewidth=1)
ADR1_low = plot(_adr1_low, title=text_ADR1_low, color=ta.change(_adr1_low) ? na : color_ADR1_low, linewidth=1)
ADR2_low = plot(_adr2_low, title=text_ADR2_low, color=ta.change(_adr2_low) ? na : color_ADR2_low, linewidth=1)
fill(plot1 = ADR1_high, plot2 = ADR2_high, color = ta.change(_adr1_high) ? na : color.new(adrUppercolorfill, 80))
fill(plot1 = ADR1_low, plot2 = ADR2_low, color = ta.change(_adr1_low) ? na : color.new(adrlowercolorfill, 80))

//***Start of Labels***

label_ADR1_high = \'\'
label_ADR2_high = \'\'

label_ADR1_low = \'\'
label_ADR2_low = \'\'

if labels_enabled == true
    label_ADR1_high := str.tostring(math.round_to_mintick(adr1_high))
    label_ADR2_high := str.tostring(math.round_to_mintick(adr2_high))
    
    label_ADR1_low  := str.tostring(math.round_to_mintick(adr1_low))
    label_ADR2_low  := str.tostring(math.round_to_mintick(adr2_low))
        
string_ADR1_high = \' (\' + label_ADR1_high + \')\'
string_ADR2_high = \' (\' + label_ADR2_high + \')\'

string_ADR1_low = \' (\' + label_ADR1_low + \')\'
string_ADR2_low = \' (\' + label_ADR2_low + \')\'

//Labels
if show_chart and labels_enabled == true
    draw_label(bar_index + 1, adr1_high, text_ADR1_high + string_ADR1_high, xloc.bar_index, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_ADR1_high,transp_func()), size.normal, text.align_left, \'\') 
    draw_label(bar_index + 1, adr2_high, text_ADR2_high + string_ADR2_high, xloc.bar_index, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_ADR2_high,transp_func()), size.normal, text.align_left, \'\')
  
    draw_label(bar_index + 1, adr1_low,  text_ADR1_low + string_ADR1_low, xloc.bar_index, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_ADR1_low,transp_func()), size.normal, text.align_left, \'\')   
    draw_label(bar_index + 1, adr2_low,  text_ADR2_low + string_ADR2_low, xloc.bar_index, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_ADR2_low,transp_func()), size.normal, text.align_left, \'\')  

///////////////////////////////////////////////////////////////////////////////////////////
  • editable=false 添加到您的plot() 函数是否可以解决您的问题?
  • 谢谢@vitruvius。当我添加 editable=false 时,我无法更改行 color。我们需要像this一样改变线条颜色
  • 抱歉,我以为你想去掉所有颜色选项,包括颜色 0、颜色 1 和颜色 2。你想要的是每个图只有一种颜色吗?
  • 我想删除没有 input tab 的颜色 1 和颜色 2 框,例如 this。我无法删除 ta.change() 函数,因为它会将行与之前的 days 合并。

标签: pine-script pinescript-v5


【解决方案1】:

什么是样式选项卡反正?它完全由tradingview控制.它包含可以在您的脚本中自动找到的所有样式选项。所以我认为你根本不应该关心它,但这只是我个人的意见。您想真正自定义和样式化您的脚本吗?然后使用输入,您可以根据需要进行分组。
回到你的问题,为什么会这样?
由于您用于着色的三元运算符,您的绘图中有 3 个颜色选项:color=ta.change(_adr1_high) ? na : color_ADR1_high
然后在样式选项卡中:color0 如果您的条件为假,color1 如果您的条件为真。我不确定color2 代表什么,但您可能会自己发现。
所以对我来说,最好的解决方案是使用输入而不是试图操纵自动颜色选项,因为该选项卡是一种与提供给您的选项有关的黑匣子,因此几乎无法控制它。

【讨论】:

    【解决方案2】:

    当我删除 Labels 脚本(第 125 到 152 行)时,它已修复 Screenshot

    无论如何添加label而不影响颜色框?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-26
      • 2014-10-19
      • 1970-01-01
      • 2012-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多