1

I am completely new to coding and I need some help. I put up a custom indicator for myself but I can't seem to find the color options under the "style " tab. Using the indicator separately you can see the color option though.

Also I want to remove the Plot option between "Downtrend Begins" and "Slow MA" mPlot = plot(ohlc4, title="plot", style=plot.style_line, linewidth=1) but I keep getting an error message.

See picture

Anyone can fix this and explain why?

Thank you

// @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')

3 Answers3

0

I had a similar issue. It seems that PineScript only allows to tweak options either in Style by default if values are hardcoded, or in Input if you specified some options as inputs. Note that even if you just partially use inputs for some parameters but not others (eg, for transparency but not colors), then PineScript simply decides to remove ALL options pertaining to this line of code from the Style tab and only shows the input you specified in Inputs (eg, transparency input you specified, but not the color, even if it is hardcoded, it won't be shown in Style).

In practice, try to remove all inputs you defined that pertain to colors and transparency settings, such as switchColor and transpSwitch, instead hardcode the values, then PineScript should display the option in Style instead of Input.

gaborous
  • 15,832
  • 10
  • 83
  • 102
0

I had a similar issue and solved it; it occurred when I had a conditional color assigned to the "plotColor" variable and changed the transparency on the plot function, like the code down below:

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

Then, instead of changing transparency on the plot function, I changed it on the conditional color variable itself. like this:

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

Now, i was able to see it on the style tab, i hope this helps!

EngTA
  • 1
  • 1
0

Here is the fix on your code

1st:- change code below (your code)

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)

to this code (Fixed code)

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)

2nd:- change code below (your code)

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

to this code (Fixed code)

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)
EngTA
  • 1
  • 1