Govind Shukla
Govind Shukla

Reputation: 21

Pinescript error - itemType is not defined

while trying to save below code it throws error.

line 21: itemType is not defined

The error goes off if i remove rsievent from return value within the function. Seems like something woring with handling of string variable '[value, cond, rsievent]'

Full code as per below

    //@version=4
    study("Screen", shorttitle = 'Screen', overlay = false)
    
    // RSI Params
    rsi_length     = input(14, title = "RSI Length")
    rsi_overbought = input(70, title = "RSI Overbought Level")
    rsi_oversold   = input(30, title = "RSI Overbought Level")
    
    // Symbols 
    // There is a limit of 40 security calls so only 40 symbols at the same time is possible
    s01 = input('AAPL',  type=input.symbol)
    
    sFunc() => 
        rsievent = ''
        rsi     = rsi(close, rsi_length)
        cond    = rsi > rsi_overbought or rsi < rsi_oversold
        value   = rsi
        rsievent := crossover(rsi, 40) ? rsievent + 'RSICROSSOVER40'  + '\n' : rsievent
        [value, cond, rsievent]
    
    [v01, c01, b01] = security(s01, timeframe.period, sFunc())
    plot(v01, "v01", color=color.green)

Upvotes: 2

Views: 535

Answers (1)

bluebubble
bluebubble

Reputation: 11

Also encountered similar issue on version 5 with request.security. According to the pinescript reference manual this function will only return series(float/Int/Bool/Color) and handling of type string is not mentioned. So for my case to workaround my issue. I used the variable as int (the one that was giving me an error which at first I declared as string). Then I handled the string value that I want outside my function and after the request.security in my script. To illustrate please see sample script below hope this help.

sFunc() => 
    rsievent = 0
    rsi     = rsi(close, rsi_length)
    cond    = rsi > rsi_overbought or rsi < rsi_oversold
    value   = rsi
    rsievent := crossover(rsi, 40) ?  1 : 0
    [value, cond, rsievent]

[v01, c01, b01] = security(s01, timeframe.period, sFunc())

rsievent_str = b01 = 1 ? 'whatever string' + 'RSICROSSOVER40'  + '\n' : ''

Upvotes: 1

Related Questions