Giovanni Dominoni
Giovanni Dominoni

Reputation: 81

Could not find function or function reference (using request.security)

the function bigTEMA is right there, but pinescript cannot find it. Maybe I'm using request.security wrong?

Basically I am just trying to trigger a buy when tema and sma are up on an hourly basis, but only when, inside that 60 minutes, close crosses below a specific average. Here is the code, probably it will be more clear.

  //@version=5
    
    
    strategy("XXX", overlay=true, default_qty_type=strategy.cash, default_qty_value=100, calc_on_every_tick=true)
    
    
    
  //INDICATORS
    
    temaLength = input.int(9, minval=1)
    ema1 = ta.ema(close, temaLength)
    ema2 = ta.ema(ema1, temaLength)
    ema3 = ta.ema(ema2, temaLength)
    tema = 3 * (ema1 - ema2) + ema3
    
    fastMA = ta.sma(close, 10)
    
    bigTEMA = request.security(syminfo.tickerid, "60", tema, lookahead=barmerge.lookahead_off)
    plot(bigTEMA, "TEMA", color=color.orange)
    
    bigMA = request.security(syminfo.tickerid, "60", fastMA, lookahead=barmerge.lookahead_off)
    plot(bigMA, "fastMA", color=color.orange)
    
    bigCLOSE = request.security(syminfo.tickerid, "60", close, lookahead=barmerge.lookahead_off)
    plot(bigCLOSE, "bigCLOSE", color=color.red)
    bigOPEN = request.security(syminfo.tickerid, "60", open, lookahead=barmerge.lookahead_off)
    plot(bigOPEN, "bigOPEN", color=color.green)   
    
    MAOPEN = ta.sma(open, 20)
    plot(MAOPEN, "BIGOPEN", color=color.green)
    
    MACLOSE = ta.sma(close, 20)
    plot(MACLOSE, "BIGCLOSE", color=color.red)
    
// STRATEGY CONDITIONS
    
    longCond = bigTEMA > bigTEMA(12) and bigMA > bigMA(12)
    long1 = bigCLOSE > bigOPEN and ta.crossunder(close, MAOPEN)
    long2 = bigCLOSE <= bigOPEN and ta.crossunder(close, MACLOSE)

    
    
    i_startTime = input.time(defval = timestamp("25 Jan 2022 00:00 +0000"), title = "Start Time")
    inDateRange = time >= i_startTime


// STRATEGY ENTRY
    
    if ((long1 or long2) and longCond and inDateRange)
        strategy.entry("long", strategy.long)

Upvotes: 0

Views: 6046

Answers (1)

vitruvius
vitruvius

Reputation: 21209

You don't have a function named bigTEMA. You have a variable named bigTEMA. That is a big difference and what causing your issue. Same issue for the bigMA.

Following two lines define two variables.

bigTEMA = request.security(syminfo.tickerid, "60", tema, lookahead=barmerge.lookahead_off)    
bigMA = request.security(syminfo.tickerid, "60", fastMA, lookahead=barmerge.lookahead_off)

And here you are trying to use those variables as a function and pass 12 to them which is not correct hence the error.

longCond = bigTEMA > bigTEMA(12) and bigMA > bigMA(12)

Upvotes: 3

Related Questions