“样式”选项卡上没有颜色选项

问题描述 投票:0回答:3

我对编码完全陌生,我需要一些帮助。 我为自己设置了一个自定义指示器,但我似乎无法在“样式”选项卡下找到颜色选项。单独使用指示器,您可以看到颜色选项。

我还想删除“下降趋势开始”和“慢速移动平均线”之间的绘图选项 mPlot = 图(ohlc4, title="plot", style=plot.style_line, 线宽=1) 但我不断收到错误消息。

See picture

任何人都可以解决这个问题并解释原因吗?

// @version=5
indicator("Ultimate Strategy", overlay=true)

//HULL 
src = input(close, title='Source', group="HULL SUITE")
modeSwitch = input.string('Hma', title='Hull Variation', options=['Hma', 'Thma', 'Ehma'], group="HULL SUITE")
length =  input(55, title='Length(180-200 for floating S/R , 55 for swing entry)', group="HULL SUITE")
lengthMult = input(1, title='Length multiplier (Used to view higher timeframes with straight band)', group="HULL SUITE")

useHtf = input(false, title='Show Hull MA from X timeframe? (good for scalping)', group="HULL SUITE")
htf = input.timeframe('240', title='Higher timeframe', group="HULL SUITE")

switchColor = input(true, 'Color Hull according to trend?', group="HULL SUITE")
candleCol = input(false, title='Color candles based on Hull\'s Trend?', group="HULL SUITE")
visualSwitch = input(true, title='Show as a Band?', group="HULL SUITE")
thicknesSwitch = input(1, title='Line Thickness', group="HULL SUITE")
transpSwitch = input.int(40, title='Band Transparency', step=5, group="HULL SUITE")

HMA(_src, _length) =>
    ta.wma(2 * ta.wma(_src, _length / 2) - ta.wma(_src, _length), math.round(math.sqrt(_length)))
EHMA(_src, _length) =>
    ta.ema(2 * ta.ema(_src, _length / 2) - ta.ema(_src, _length), math.round(math.sqrt(_length)))
THMA(_src, _length) =>
    ta.wma(ta.wma(_src, _length / 3) * 3 - ta.wma(_src, _length / 2) - ta.wma(_src, _length), _length)

Mode(modeSwitch, src, len) =>
    modeSwitch == 'Hma' ? HMA(src, len) : modeSwitch == 'Ehma' ? EHMA(src, len) : modeSwitch == 'Thma' ? THMA(src, len / 2) : na

_hull = Mode(modeSwitch, src, int(length * lengthMult))
HULL = useHtf ? request.security(syminfo.ticker, htf, _hull) : _hull
MHULL = HULL[0]
SHULL = HULL[2]

hullColor = switchColor ? HULL > HULL[2] ? #ffee58 : #5d606b : #5d606b

Fi1 = plot(MHULL, title='MHULL', color=color.new(hullColor, 50), linewidth=thicknesSwitch)
Fi2 = plot(visualSwitch ? SHULL : na, title='SHULL', color=color.new(hullColor, 50), linewidth=thicknesSwitch)
alertcondition(ta.crossover(MHULL, SHULL), title='Hull - trending up.', message='Hull - trending up.')
alertcondition(ta.crossover(SHULL, MHULL), title='Hull - trending down.', message='Hull - trending down.')

fill(Fi1, Fi2, title='Band Filler', color=color.new(hullColor, 50))

//SUPERTREND
import Electrified/SupportResitanceAndTrend/4 as SRT

ATR = "SUPERTREND"
WMA = "WMA", EMA = "EMA", SMA = "SMA", VWMA = "VWMA", VAWMA = "VAWMA"

mode = input.string(VWMA, "Mode", options=[SMA,EMA,WMA,VWMA,VAWMA], group=ATR, tooltip="Selects which averaging function will be used to determine the ATR value.")
atrPeriod = input.int(120, "Period", group=ATR, tooltip="The number of bars to use in calculating the ATR value.")
atrM = input.float(3.0, title="Multiplier", step=0.5, group=ATR, tooltip="The multiplier used when defining the super trend limits.")
maxDeviation = input.float(0, title="Max Deviation", minval=0, step=0.5, group=ATR, tooltip="The maximum deviation of the true range before being considered and outlier.\nA value of zero (default) results in no filtering.")

closeBars = input.int(3, "Closed Bars", minval = 0, group=ATR, tooltip="The number of closed bars that have to exceed the super-trend value before the trend reversal is confirmed.")

showsignals = input(false, title="Show Buy/Sell Signals ?", group=ATR)
highlighting = input(false, "Highlighter On/Off ?", group=ATR)

[trend, up, dn, unconfirmed, warn, reversal] = SRT.superTrend(atrM, atrPeriod, mode, closeBars, maxDeviation)

upPlot = plot(trend==1 ? up : na, title="Up Trend", style=plot.style_linebr, linewidth=1, color=unconfirmed==0?#ffee58:color.red)
buySignal = trend == 1 and trend[1] == -1
plotshape(buySignal ? up : na, title="UpTrend Begins", location=location.absolute, style=shape.triangleup, size=size.tiny, color=#ffee58)
dnPlot = plot(trend==1 ? na : dn, title="Down Trend", style=plot.style_linebr, linewidth=1, color=unconfirmed==0?#5d606b:color.red)
sellSignal = trend == -1 and trend[1] == 1
plotshape(sellSignal ? dn : na, title="DownTrend Begins", location=location.absolute, style=shape.triangledown, size=size.tiny, color=#5d606b)
mPlot = plot(ohlc4, title="plot", style=plot.style_line, linewidth=1)
longFillColor = color.new(highlighting ? (trend == 1 ? color.green : color.white) : color.white, 999)
shortFillColor = color.new(highlighting ? (trend == -1 ? color.red : color.white) : color.white, 999)
fill(mPlot, upPlot, title="UpTrend Highligter", color=longFillColor)
fill(mPlot, dnPlot, title="DownTrend Highligter", color=shortFillColor)

alertcondition(buySignal,
  "SuperTrend - Up ▲ (+)", message="SuperTrend - Up ▲ (+)")
alertcondition(sellSignal,
  "SuperTrend - Down ▼ (-)", message="SuperTrend - Down ▼ (-)")
  
//EMA CLOUD  
EMACLOUD = "EMA CLOUD"

slow = input(25, title="Slow EMA", group=EMACLOUD)
fast = input(12, title="Fast EMA", group=EMACLOUD)

emaSlow = ta.ema(close, slow)
emaFast = ta.ema(close, fast)

col = emaFast > emaSlow ? #ffee58: emaFast < emaSlow ? #5d606b: color.yellow

p1 = plot(emaSlow, title="Slow MA", style=plot.style_linebr, linewidth=1, color=col)
p2 = plot(emaFast, title="Fast MA", style=plot.style_linebr, linewidth=1, color=col)

alertcondition(ta.crossover(emaSlow, emaFast), title="EMA - Sell", message="EMA - Sell")
alertcondition(ta.crossover(emaFast, emaSlow), title="EMA - Buy", message="EMA - Buy")

//Support And Resistance
SAR= "Support And Resistance"
prd = input.float(defval = 10, title="Pivot Period", minval = 4, maxval = 30, group = SAR)
ppsrc = input.string(defval = 'High/Low', title="Source", options = ['High/Low', 'Close/Open'], group = SAR)
maxnumpp = input.float(defval = 20, title =" Maximum Number of Pivot", minval = 5, maxval = 100, group = SAR)
ChannelW = input.float(defval = 10, title = "Maximum Channel Width %", minval = 1, group = SAR)
maxnumsr = input.float(defval = 5, title =" Maximum Number of S/R", minval = 1, maxval = 10, group = SAR)
min_strength = input.float(defval = 2, title =" Minimum Strength", minval = 1, maxval = 10, group = SAR)
labelloc = input(defval = 20, title = "Label Location", group = SAR, tooltip = "Positive numbers reference future bars, negative numbers reference histical bars")
linestyle = input.string(defval = 'Dotted', title = "Line Style", options = ['Solid', 'Dotted', 'Dashed'], group = SAR)
linewidth = input.float(defval = 2, title = "Line Width", minval = 1, maxval = 4, group = SAR)
resistancecolor = input(defval = color.silver, title = "Resistance Color", group = SAR)
supportcolor = input(defval = color.silver, title = "Support Color", group = SAR)
showpp = input(false, title = "Show Point Points", group = SAR)

float src1 =  ppsrc == 'High/Low' ? high : math.max(close, open)
float src2 =  ppsrc == 'High/Low' ? low: math.min(close, open)
float ph = ta.pivothigh(src1, prd, prd)
float pl = ta.pivotlow(src2, prd, prd)

Lstyle = linestyle == 'Dashed' ? line.style_dashed :
         linestyle == 'Solid' ? line.style_solid :
         line.style_dotted
                 
prdhighest =  ta.highest(300)
prdlowest = ta.lowest(300)
cwidth = (prdhighest - prdlowest) * ChannelW / 100

var pivotvals= array.new_float(0)

if ph or pl
    array.unshift(pivotvals, ph ? ph : pl)
    if array.size(pivotvals) > maxnumpp // limit the array size
        array.pop(pivotvals)

get_sr_vals(ind)=>
    float lo = array.get(pivotvals, ind)
    float hi = lo
    int numpp = 0
    for y = 0 to array.size(pivotvals) - 1
        float cpp = array.get(pivotvals, y)
        float wdth = cpp <= lo ? hi - cpp : cpp - lo
        if wdth <= cwidth // fits the max channel width?
            lo := cpp <= lo ? cpp : lo
            hi := cpp > lo ? cpp : hi
            numpp += 1
    [hi, lo, numpp]  

var sr_up_level = array.new_float(0)
var sr_dn_level = array.new_float(0)
sr_strength = array.new_float(0)

find_loc(strength)=>
    ret = array.size(sr_strength)
    for i = (ret > 0 ? array.size(sr_strength) - 1 : na) to 0
        if strength <= array.get(sr_strength, i)
            break
        ret := i
    ret

check_sr(hi, lo, strength)=>
    ret = true
    for i = 0 to (array.size(sr_up_level) > 0 ? array.size(sr_up_level) - 1 : na)
        //included?
        if array.get(sr_up_level, i) >= lo and array.get(sr_up_level, i) <= hi  or 
           array.get(sr_dn_level, i) >= lo and array.get(sr_dn_level, i) <= hi
            if strength >= array.get(sr_strength, i)
                array.remove(sr_strength, i)
                array.remove(sr_up_level, i)
                array.remove(sr_dn_level, i)
                ret
            else
                ret := false
            break
    ret

var sr_lines = array.new_line(11, na)

if ph or pl
    //because of new calculation, remove old S/R levels
    array.clear(sr_up_level)
    array.clear(sr_dn_level)
    array.clear(sr_strength)
    //find S/R zones
    for x = 0 to array.size(pivotvals) - 1
        [hi, lo, strength] = get_sr_vals(x)
        if check_sr(hi, lo, strength)
            loc = find_loc(strength)
            // if strength is in first maxnumsr sr then insert it to the arrays 
            if loc < maxnumsr and strength >= min_strength
                array.insert(sr_strength, loc, strength)
                array.insert(sr_up_level, loc, hi)
                array.insert(sr_dn_level, loc, lo)
                // keep size of the arrays = 5
                if array.size(sr_strength) > maxnumsr
                    array.pop(sr_strength)
                    array.pop(sr_up_level)
                    array.pop(sr_dn_level)
    
    for x = 1 to 10
        line.delete(array.get(sr_lines, x))

       
    for x = 0 to (array.size(sr_up_level) > 0 ? array.size(sr_up_level) - 1 : na)
        float mid = math.round_to_mintick((array.get(sr_up_level, x) + array.get(sr_dn_level, x)) / 2)
        rate = 100 * (mid - close) / close

                     
        array.set(sr_lines, x + 1, 
                  line.new(x1 = bar_index, y1 = mid, x2 = bar_index - 1, y2 = mid, 
                  extend = extend.both,
                  color = mid >= close ? resistancecolor : supportcolor, 
                  style = Lstyle, 
                  width = na))

f_crossed_over()=>
    ret = false
    for x = 0 to (array.size(sr_up_level) > 0 ? array.size(sr_up_level) - 1 : na)
        float mid = math.round_to_mintick((array.get(sr_up_level, x) + array.get(sr_dn_level, x)) / 2)
        if close[1] <= mid and close > mid
            ret := true
    ret

f_crossed_under()=>
    ret = false
    for x = 0 to (array.size(sr_up_level) > 0 ? array.size(sr_up_level) - 1 : na)
        float mid = math.round_to_mintick((array.get(sr_up_level, x) + array.get(sr_dn_level, x)) / 2)
        if close[1] >= mid and close < mid
            ret := true
    ret

alertcondition(f_crossed_over(), title='Resistance Broken', message='Resistance Broken')
alertcondition(f_crossed_under(), title='Support Broken', message='Support Broken')
pine-script pine-script-v5 tradingview-api
3个回答
0
投票

我也有类似的问题。看来 PineScript 只允许在默认情况下在“样式”中调整选项(如果值是硬编码的),或者在“输入”中(如果指定某些选项作为输入)。请注意,即使您仅部分使用某些参数的输入而不使用其他参数(例如,用于透明度而不是颜色),PineScript 也会简单地决定从“样式”选项卡中删除与该行代码相关的所有选项,并仅显示您指定的输入在输入中(例如,您指定的透明度输入,但不是颜色,即使是硬编码,也不会在样式中显示)。

在实践中,尝试删除您定义的与颜色和透明度设置相关的所有输入,例如 switchColor 和 transpSwitch,而是对值进行硬编码,然后 PineScript 应该在 Style 而不是 Input 中显示该选项。


0
投票

我有类似的问题并解决了;当我将条件颜色分配给“plotColor”变量并更改绘图函数的透明度时,就会发生这种情况,如下面的代码所示:

plotColor = close > open ? #00ff0a: #ff0000
plot(close, color = color.new(plotColor, 20))

然后,我没有更改绘图函数的透明度,而是更改了条件颜色变量本身。像这样:

plotColor = close > open ? color.new(#00ff0a, 20) : color.new(#ff0000, 20)
plot(close, color = plotColor )

现在,我可以在样式选项卡上看到它,我希望这有帮助!


0
投票

这是对您的代码的修复

第一:- 更改下面的代码(您的代码)

hullColor = switchColor ? HULL > HULL[2] ? #ffee58 : #5d606b : #5d606b
Fi1 = plot(MHULL, title='MHULL', color=color.new(hullColor, 50), 
  linewidth=thicknesSwitch)
Fi2 = plot(visualSwitch ? SHULL : na, title='SHULL', color=color.new(hullColor, 
  50), linewidth=thicknesSwitch)

此代码(固定代码)

hullColor = switchColor ? HULL > HULL[2] ? color.new(#ffee58, 50) : 
  color.new(#5d606b, 50) : color.new(#5d606b, 50)
Fi1 = plot(MHULL, title='MHULL', color=hullColor, linewidth=thicknesSwitch)
Fi2 = plot(visualSwitch ? SHULL : na, title='SHULL', color=hullColor, 
  linewidth=thicknesSwitch)

第二:- 更改下面的代码(您的代码)

longFillColor = color.new(highlighting ? (trend == 1 ? #4caf50 : #ffffff) : 
  #ffffff, 999)
shortFillColor = color.new(highlighting ? (trend == -1 ? #ff5252 : #ffffff) : 
  #ffffff, 999)

此代码(固定代码)

longFillColor = highlighting ? (trend == 1 ? color.new(#4caf50, 99) : 
  color.new(#ffffff, 99)) : color.new(#ffffff, 99)
shortFillColor = highlighting ? (trend == -1 ? color.new(#ff5252, 99) : 
  color.new(#ffffff, 99)) : color.new(#ffffff, 99)
© www.soinside.com 2019 - 2024. All rights reserved.