0

im trying to work out how to specify a local variable from a specific timeframe so i can use it later to trigger and alert

If possible without using request security

The normal macd and signal variables are working fine

here is what i have tried but they are not working ( im new to pinescript and have no idea what to do )

//@version=5
indicator(title="", shorttitle="", overlay=false ,format=format.price, precision=4)


macd                = slowMA - fastMA
signal              = ta.ema(macd, signalMACDlen)
macd15              = slowMA - fastMA,  timeframe.period ('15')
signal15            = (timeframe.period ='15'), ta.ema(macd, signalMACDlen)
macd5(timeframe.period ='5')     = slowMA - fastMA

Thanks for any help

Juz
  • 17
  • 3

2 Answers2

0

To get an accurate value from another time frame request.security is needed. You can reduce the number of security calls by using your own function that returns multiple values for the same time frame.

my_function(parm1,parm2,parm3..parmn)=>
 {do stuff}
 [val1, val2, val3....valn]

[value1, value2, value3....valuen] = request.security(syminfo.tickerid, tf, my_function(parm1,parm2,parm3...parmn))```

// for example
f_get_all(src, fastlen, slowlen,siglen) =>
    [macdLine,signalLine,histLine]=  ta.macd(src, fastlen,slowlen,siglen)
    [rsii_]= ta.rsi(src, fastlen)

    [macdLine,signalLine,histLine,rsii_]



[macdLine15,signalline15,histLine15,rsii15]=request.security(syminfo.tickerid, "15", f_get_fifteen_all(close,14,21))
John Baron
  • 291
  • 2
  • 8
  • Would this way work, not sure what you mean with the do stuff section :) 'code' f_get_60_all(macd, signal, k, d, close) => [macd60, signal60, k60, d60, close60] [macd60, signal60, k60, d60, close60] = request.security(syminfo.tickerid, "60", f_get_60_all(macd, signal, k, d, close), barmerge.gaps_off, barmerge.lookahead_on) – Juz Nov 15 '22 at 09:57
  • i updated my answer with an example – John Baron Nov 15 '22 at 11:47
0

Would this work ?

f_get_fifteen_macd() => [MACD]
f_get_fifteen_signal() => [signal]
f_get_fifteen_k() => [k]
f_get_fifteen_d() => [d]

f_get_fifteen_all() =>
    [mac15] = f_get_fifteen_macd()
    [sig15] = f_get_fifteen_signal()
    [kli15] = f_get_fifteen_k()                                               
    [dli15] = f_get_fifteen_d()
request.security(syminfo.tickerid, "15", f_get_fifteen_all(), barmerge.gaps_off, barmerge.lookahead_on)

'''

Juz
  • 17
  • 3