I get the error "internal server pine compilation error" but i don't know where to look for an error in my code

Viewed 29

This indicator I was developing was working fine til last modifications, now it tells me "Internal server pine compilation error" but i don't know what's wrong. I just converted a lot of inputs i was using for debug into actual variables cause i don't need to have them configurable. I don't know what to add because when saving it says:

Processing script... Script 'Aleznox Entrypoints' has been saved

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

//@version=5

indicator(title          = "Aleznox Entrypoints [FishoJr] + EMA + VPVR", 
     shorttitle      = "Aleznox Entrypoints", 
     overlay         = true)
     
vp_lookback = 200
vp_max_bars = 500
vp_bar_mult = 50
vp_bar_offset = 30
vp_bar_width = 2
vp_delta_type = 'Both'
vp_poc_show = true
vp_bar_color = color.new(color.blue, 60)
vp_poc_color = color.new(color.white, 10)
lengthKC = 20
adxlen = 14
dilen = 14
transparency = 85

//upperTimeframe = input.timeframe("1D", "Upper timeframe trend", options = ["1", "3", "15", "60", "240", "1D", "1W", "1M"])
//isAutomated = input.bool(true, title="Automated Set UpperTimeFrame")

// VP VARIABLES
float vp_Vmax = 0.0
int vp_VmaxId = 0
int vp_N_BARS = vp_max_bars

var int vp_first = time

vp_a_P = array.new_float(vp_N_BARS + 1, 0.0)
vp_a_V = array.new_float(vp_N_BARS, 0.0)
vp_a_D = array.new_float(vp_N_BARS, 0.0)
vp_a_W = array.new_int(vp_N_BARS, 0)

// VP CALCULATIONS
float vp_HH = ta.highest(high, vp_lookback)
float vp_LL = ta.lowest(low, vp_lookback)

if barstate.islast
    float vp_HL = (vp_HH - vp_LL) / vp_N_BARS
    for j = 1 to vp_N_BARS + 1 by 1
        array.set(vp_a_P, j - 1, vp_LL + vp_HL * j)
    for i = 0 to vp_lookback - 1 by 1
        int Dc = 0
        array.fill(vp_a_D, 0.0)
        for j = 0 to vp_N_BARS - 1 by 1
            float Pj = array.get(vp_a_P, j)
            if low[i] < Pj and high[i] > Pj and (vp_delta_type == 'Bullish' ? close[i] >= open[i] : vp_delta_type == 'Bearish' ? close[i] <= open[i] : true)
                float Dj = array.get(vp_a_D, j)
                float dDj = Dj + nz(volume[i])
                array.set(vp_a_D, j, dDj)
                Dc += 1
                Dc
        for j = 0 to vp_N_BARS - 1 by 1
            float Vj = array.get(vp_a_V, j)
            float Dj = array.get(vp_a_D, j)
            float dVj = Vj + (Dc > 0 ? Dj / Dc : 0.0)
            array.set(vp_a_V, j, dVj)
    vp_Vmax := array.max(vp_a_V)
    vp_VmaxId := array.indexof(vp_a_V, vp_Vmax)
    for j = 0 to vp_N_BARS - 1 by 1
        float Vj = array.get(vp_a_V, j)
        int Aj = math.round(vp_bar_mult * Vj / vp_Vmax)
        array.set(vp_a_W, j, Aj)

// Timeframe corrections                    
currentTimeframeMultiplier = switch timeframe.period
    "1" => 1
    "3" => 3
    "5" => 5
    "15" => 15
    "30" =>30
    "60" => 60
    "240" => 240
    "D" => 1440
    "W" => 10080
    =>
        runtime.error("Timeframe not supported :" + timeframe.period)
        0
        
upperTimeframeMultiplier = switch currentTimeframeMultiplier
    1 => 3
    3 => 15
    5 => 15
    15 => 60
    30 =>240
    60 => 240
    240 => 1440
    1440 => 10080
    10080 => 40320
    =>
        runtime.error("Timeframe not supported")
        0
        
upperTimeframe = switch upperTimeframeMultiplier
    3 => "3"
    5 => "5"
    15 => "15"
    60 => "60"
    240 => "240"
    1440 => "1D"
    10080 => "1W"
    40320 => "1M"
    => 
        "1M"

timeframeMultiplier = upperTimeframeMultiplier / currentTimeframeMultiplier


//Functions 
//adx       
dirmov(len) =>
    up = ta.change(high)
    down = -ta.change(low)
    truerange = ta.rma(ta.tr, len)
    plus = fixnan(100 * ta.rma(up > down and up > 0 ? up : 0, len) / truerange)
    minus = fixnan(100 * ta.rma(down > up and down > 0 ? down : 0, len) / truerange)
    [plus, minus]

adx(dilen, adxlen) => 
    [plus, minus] = dirmov(dilen)
    sum = plus + minus
    adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
    adx

//Entrypoints using adx, sqz, uppertimeframe    
entryPoints(val, sig, step, trendBool) =>
    if (val > 0 and val < nz(val[step]) and nz(val[step]) > nz(val[step+1]) and sig < sig[step] and trendBool == false)
        l = label.new(bar_index, na)
        label.set_text(l, "short")
        label.set_color(l, color.red)
        label.set_yloc(l, yloc.abovebar)
        label.set_style(l, label.style_label_down)
    if (val < 0 and val > nz(val[step]) and nz(val[step]) < nz(val[step+1]) and sig < sig[step] and trendBool == true)
        l = label.new(bar_index, na)
        label.set_text(l, "long")
        label.set_color(l, color.green)
        label.set_yloc(l, yloc.belowbar)
        label.set_style(l, label.style_label_up)


//Uppertimeframe trend gauging using sqz
fillTrends(sqz, timeframeMultiplier) =>
    trend = sqz < nz(sqz[timeframeMultiplier]) ? false : true
    trend

//sqz
sqz() =>
    ta.linreg(close - math.avg(math.avg(ta.highest(high, lengthKC), ta.lowest(low, lengthKC)),ta.sma(close,lengthKC)), lengthKC,0)


//fetching series needed
sqz = sqz()
adx = adx(dilen, adxlen)

upperAdx = request.security(symbol=syminfo.tickerid, timeframe=upperTimeframe, expression=adx(dilen, adxlen))
upperSqz = request.security(symbol=syminfo.tickerid, timeframe=upperTimeframe, expression=sqz())

//Trends
trendBool = fillTrends(upperSqz, timeframeMultiplier)
bgcolor(trendBool ? color.new(color.green, transparency) : color.new(color.red, transparency))

//Entrypoints
entryPoints(sqz, adx, 1, trendBool)

//Adding 2 EMAs
//ADD EMA >>
iEma = input(10, title="EMA1")
iEma1 = input(55, title="EMA2")
iEmaColor = input.color(color.blue, title="EMA1 Color")
iEmaColor1 = input.color(color.orange, title="EMA2 Color")

src = close
ema10 = ta.ema(src,iEma)
ema55 = ta.ema(src,iEma1)

plot(ema10, color = iEmaColor, style=plot.style_line, linewidth=2, title="EMA_1")
plot(ema55, color = iEmaColor1, style=plot.style_line, linewidth=2, title="EMA_2")
1 Answers

Internal server pine compilation error is a catch-all error for when the compiler does not compile your script properly but the reason is not handled. This is most likely a bug with the Pine compiler itself. I reported it to the Pine team, they'll take a look.

The issue appears to be related to the fact that runtime.error() is used with request.security(), so extracting runtime.error() from your switch statements makes everything work:

// Timeframe corrections                    
currentTimeframeMultiplier = switch timeframe.period
    "1" => 1
    "3" => 3
    "5" => 5
    "15" => 15
    "30" =>30
    "60" => 60
    "240" => 240
    "D" => 1440
    "W" => 10080
    => 0

if currentTimeframeMultiplier == 0
    runtime.error("Timeframe not supported :" + timeframe.period)

upperTimeframeMultiplier = switch currentTimeframeMultiplier
    1 => 3
    3 => 15
    5 => 15
    15 => 60
    30 =>240
    60 => 240
    240 => 1440
    1440 => 10080
    10080 => 40320
    => 0

if upperTimeframeMultiplier == 0
    runtime.error("Timeframe not supported")
Related