Feystag

[Help requested] High resolution data 24 hour lag issue

BINANCE:BTCUSDT   Bitcoin / TetherUS
When I calculate MACD using daily resolution , my signals come at the expected date. However when I calculate them on a finer resolution (such as 4 hours), they arrive precisely 24 hours later than on the daily chart . I would have expected them to come sooner on the finer resolution charts.

The blue line is the high resolution 4hr data and green is the daily data. The blue line (4hr) lags behind the green line (daily) by 24 hours, I would have expected the blue to be ahead of the daily as the daily should only be correct once a day where as the 4hr show be correct 6 times per day.

Can anyone explain why this is and how I can possibly fix it?

This is how the script gets the data and calculates the macd:

// --------------------- Daily
dailyFastMA = ema ( src , fastLength)
dailySlowMA = ema ( src , slowLength)

dailyMacd = dailyFastMA - dailySlowMA
dailySignal = sma (dailyMacd, signalLength)
dailyHist = dailyMacd - dailySignal

dailyOutMacD = security(syminfo.tickerid, '1D', dailyMacd, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
dailyOutSignal = security(syminfo.tickerid, '1D', dailySignal, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
dailyOutHist = security(syminfo.tickerid, '1D', dailyHist, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)

// --------------------- 4 hourly
fourHourlyFastMA = ema ( src , fastLength * 6)
fourHourlySlowMA = ema ( src , slowLength * 6)

fourHourlyMacd = fourHourlyFastMA - fourHourlySlowMA
fourHourlySignal = sma (fourHourlyMacd, signalLength * 6)
fourHourlyHist = fourHourlyMacd - fourHourlySignal

fourHourlyOutMacD = security(syminfo.tickerid, '240', fourHourlyMacd, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
fourHourlyOutSignal = security(syminfo.tickerid, '240', fourHourlySignal, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
fourHourlyOutHist = security(syminfo.tickerid, '240', fourHourlyHist, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.