Search code examples
pine-scriptpine-script-v5

Condition an OHLCV 'request.security' call


To condition a request.security call, you can use the ? operator, like this:

C = 1 > 0 ? request.security(syminfo.tickerid, "D", close) : 0

But is there any way to condition an OHLCV request.security call?

I'm encountering a Syntax error at input '[' error with this array format:

[O, H, L, C, V] = 1 > 0 ? request.security(syminfo.tickerid, "D", [open, high, low, close, volume]) : [0, 0, 0, 0, 0]


Solution

  • That is not possible.

    You cannot do something like below:

    [a, b, c, d] = [open, close, high, low]
    

    As a workaround, you can do:

    [O_htf, H_htf, L_htf, C_htf, V_htf] = request.security(syminfo.tickerid, "D", [open, high, low, close, volume])
    
    O = (1 > 0) ? O_htf : 0
    H = (1 > 0) ? H_htf : 0
    L = (1 > 0) ? L_htf : 0
    C = (1 > 0) ? C_htf : 0
    V = (1 > 0) ? V_htf : 0