Ethan Lam
Ethan Lam

Reputation: 1

How can I ensure an indicators value with a higher timeframe) doesn't repaint on a lower timeframe?

I am retrieving daily close data for an indicator for use on a lower timeframe (1HR/15min) and would like this indicators value to only update every time the daily candle closes. I have attempted to resolve this by creating a function which uses "barstate.isrealtime" but it doesn't seem to work. I would love to hear if you have any solutions to this :)

f_secureSecurity(_symbol, _res, _src) => security(_symbol, _res, _src[barstate.isrealtime ? 1 : 0])

period = input(50)
getStatus(ticker) =>
    securityClose = f_secureSecurity(ticker, 'D', close)
    norm_price= normalize(securityClose,0,1)
    benchmark = f_secureSecurity("USD", 'D', close)
    relative_strength = (norm_price / benchmark)
    relative_strength_ratio = 100 + ((relative_strength - sma(relative_strength, period)) / stdev(relative_strength, period))
    momentum = mom(securityClose,10)
    momentum_rolling_mean = sma(momentum,period)
    momentum_rolling_std = stdev(momentum,period)
    relative_strength_momentum = 100 + ((momentum - momentum_rolling_mean)/momentum_rolling_std)
    smoothed_RS_Ratio = sma(relative_strength_ratio,10)
    smoothed_RS_Momentum_Ratio = sma(relative_strength_momentum,10)
    r_status = smoothed_RS_Ratio
    r_status

Upvotes: 0

Views: 315

Answers (1)

vitruvius
vitruvius

Reputation: 21342

You can directly use close[1] in your security() so it will always refer to previous daily close price.

f_secureSecurity(_symbol, _res, _src) => security(_symbol, _res, _src[1], lookahead = barmerge.lookahead_on)

Upvotes: 0

Related Questions