This 3 time frames Wave Trend indicator does not repaint after candle close. It only uses the value from the higher time frames if the higher time frame bar has closed.
But sometimes, the two higher time frames don't update (Edit: Keep the same value) even though the respective bars have closed. This happens only in the browser, though. Then, after a few closes it updates correctly again. This is happening without refreshing the browser, and if I have the same chart with the same script open in two browser tabs, it can happen in just one of them, but not the other one.
If the server side alert is used, it always delivers the correct values. I have tested this on the htf1WaveTrend value.
Does anyone have an idea why this is happening?
EDIT: The chart time frame is on 1 minute.
I have not noticed any similar problems with other indicators.
...
//@version=5
indicator("TEST 3 Time Frames Wave Trend v5", overlay = false)
// @author LazyBear (original)
//
// If you use this code in its original/modified form, do drop me a note.
//
//INPUTS
i_n1 = input( 10, 'Channel Length', inline='1', group='Wave Trend Settings')
i_n2 = input( 21, 'Average Length', inline='1', group='Wave Trend Settings')
i_ma = input( 8, 'Moving Average Length', inline='1', group='Wave Trend Settings')
i_obLevel1 = input( 60, 'Over Bought Level 1', inline='1', group='Wave Trend Settings')
i_obLevel2 = input( 53, 'Over Bought Level 2. Cross below for Short', inline='1', group='Wave Trend Settings')
i_osLevel1 = input( -60, 'Over Sold Level 1', inline='1', group='Wave Trend Settings')
i_osLevel2 = input( -53, 'Over Sold Level 2. Cross above for Long', inline='1', group='Wave Trend Settings')
i_ap = input( hlc3, 'source', inline='1', group='Wave Trend Settings')
i_htf1 = input.timeframe('2', 'HTF 1', group='Higher Time Frame Wave Trend')
i_htf2 = input.timeframe('4', 'HTF 2', group='Higher Time Frame Wave Trend')
var htf1WaveTrend = float(na)
var htf1WaveTrendSignal = float(na)
var htf2WaveTrend = float(na)
var htf2WaveTrendSignal = float(na)
var wtColor = color(na)
var htf1WaveTrendColor = color(na)
var htf2WaveTrendColor = color(na)
// FUNCTIONS
// Wave Trend
f_waveTrend(_tf, _ap, _n1, _n2, _ma) =>
_esa = request.security(syminfo.tickerid, _tf, ta.ema(_ap, _n1))
_d = request.security(syminfo.tickerid, _tf, ta.ema(math.abs(_ap - _esa), _n1))
_ci = (_ap - _esa) / (0.015 * _d)
_wt = request.security(syminfo.tickerid, _tf, ta.ema(_ci, _n2))
_wts = request.security(syminfo.tickerid, _tf, ta.sma(_wt, _ma))
[_wt, _wts]
// CALCULATIONS
[NewHtf1WaveTrend, NewHtf1WaveTrendSignal] = f_waveTrend(i_htf1, i_ap, i_n1, i_n2, i_ma)
htf1BarIsClosed = request.security(syminfo.tickerid, i_htf1, barstate.isconfirmed) // Only use if the HTF bar is closed. Prevents repainting
// if htfBarIsClosed
// htf1WaveTrend := NewHtf1WaveTrend
// htf1WaveTrendSignal := NewHtf1WaveTrendSignal
// Alternative to "if"
htf1WaveTrend := ta.valuewhen(htf1BarIsClosed, NewHtf1WaveTrend, 0)
htf1WaveTrendSignal := ta.valuewhen(htf1BarIsClosed, NewHtf1WaveTrendSignal, 0)
[NewHtf2WaveTrend, NewHtf2WaveTrendSignal] = f_waveTrend(i_htf2, i_ap, i_n1, i_n2, i_ma)
htf2BarIsClosed = request.security(syminfo.tickerid, i_htf2, barstate.isconfirmed) // Only use if the HTF bar is closed. Prevents repainting
// if htfBarIsClosed
// htf2WaveTrend := NewHtf2WaveTrend
// htf2WaveTrendSignal := NewHtf2WaveTrendSignal
// Alternative to "if"
htf2WaveTrend := ta.valuewhen(htf2BarIsClosed, NewHtf2WaveTrend, 0)
htf2WaveTrendSignal := ta.valuewhen(htf2BarIsClosed, NewHtf2WaveTrendSignal, 0)
if htf1BarIsClosed
alert('htf1 is: ' + str.tostring(htf1WaveTrend))
[wt, wts] = f_waveTrend(timeframe.period, i_ap, i_n1, i_n2, i_ma)
wtColor := wt[1] < wt[0] ? #00ff00 : wt[1] > wt[0] ? #eb4d4d : wtColor
htf1WaveTrendColor := htf1WaveTrend[1] < htf1WaveTrend[0] ? #018a01 : htf1WaveTrend[1] > htf1WaveTrend[0] ? #b51b1b : htf1WaveTrendColor
htf2WaveTrendColor := htf2WaveTrend[1] < htf2WaveTrend[0] ? #024d02 : htf2WaveTrend[1] > htf2WaveTrend[0] ? #800000 : htf2WaveTrendColor
plot(0, color=color.new(color.gray, 0))
plot(i_obLevel1, title='overbought', color=color.new(color.red, 0))
plot(i_osLevel1, title='oversold', color=color.new(color.green, 0))
plot(i_obLevel2, title='overbought min', color=color.new(color.red, 0), style=plot.style_cross)
plot(i_osLevel2, title='oversold max', color=color.new(color.green, 0), style=plot.style_cross)
plot(wt,title="WT",linewidth=3,color=wtColor)
plot(htf1WaveTrend,title="htfWT1",linewidth=3,color=htf1WaveTrendColor)
plot(htf2WaveTrend,title="htfWT2",linewidth=3,color=htf2WaveTrendColor)
...
EDIT: Here is the modified version suggested by @Daveatt Unfortunately this gives values that do not match the actual values Wave Trend would give on the higher time frames at all. Thanks anyway.
...
//@version=5
indicator("TEST 3 Time Frames Wave Trend v5", overlay = false, precision=4)
// @author LazyBear (original)
//
//INPUTS
i_n1 = input( 10, 'Channel Length', inline='1', group='Wave Trend Settings')
i_n2 = input( 21, 'Average Length', inline='1', group='Wave Trend Settings')
i_ma = input( 8, 'Moving Average Length', inline='1', group='Wave Trend Settings')
i_obLevel1 = input( 60, 'Over Bought Level 1', inline='1', group='Wave Trend Settings')
i_obLevel2 = input( 53, 'Over Bought Level 2. Cross below for Short', inline='1', group='Wave Trend Settings')
i_osLevel1 = input( -60, 'Over Sold Level 1', inline='1', group='Wave Trend Settings')
i_osLevel2 = input( -53, 'Over Sold Level 2. Cross above for Long', inline='1', group='Wave Trend Settings')
i_ap = input( hlc3, 'source', inline='1', group='Wave Trend Settings')
i_htf1 = input.timeframe('2', 'HTF 1', group='Higher Time Frame Wave Trend')
i_htf2 = input.timeframe('4', 'HTF 2', group='Higher Time Frame Wave Trend')
// var htf1WaveTrend = float(na)
// var htf1WaveTrendSignal = float(na)
// var htf2WaveTrend = float(na)
// var htf2WaveTrendSignal = float(na)
var wtColor = color(na)
var htf1WaveTrendColor = color(na)
var htf2WaveTrendColor = color(na)
// FUNCTIONS
// Security
f_security(_sym, _res, _src, _rep) =>
request.security(_sym, _res, _src[not _rep and barstate.isrealtime ? 1 : 0])[_rep or barstate.isrealtime ? 0 : 1]
// Wave Trend
f_waveTrend(_tf, _ap, _n1, _n2, _ma) =>
_esa = f_security(syminfo.tickerid, _tf, ta.ema(_ap, _n1), false)
_d = f_security(syminfo.tickerid, _tf, ta.ema(math.abs(_ap - _esa), _n1), false)
_ci = (_ap - _esa) / (0.015 * _d)
_wt = f_security(syminfo.tickerid, _tf, ta.ema(_ci, _n2), false)
_wts = f_security(syminfo.tickerid, _tf, ta.sma(_wt, _ma), false)
[_wt, _wts]
// CALCULATIONS
[htf1WaveTrend, htf1WaveTrendSignal] = f_waveTrend(i_htf1, i_ap, i_n1, i_n2, i_ma)
// htf1BarIsClosed = request.security(syminfo.tickerid, i_htf1, barstate.isconfirmed) // Only use if the HTF bar is closed. Prevents repainting
// // if htfBarIsClosed
// // htf1WaveTrend := NewHtf1WaveTrend
// // htf1WaveTrendSignal := NewHtf1WaveTrendSignal
// // Alternative to "if"
// htf1WaveTrend := ta.valuewhen(htf1BarIsClosed, NewHtf1WaveTrend, 0)
// htf1WaveTrendSignal := ta.valuewhen(htf1BarIsClosed, NewHtf1WaveTrendSignal, 0)
[htf2WaveTrend,hHtf2WaveTrendSignal] = f_waveTrend(i_htf2, i_ap, i_n1, i_n2, i_ma)
// htf2BarIsClosed = request.security(syminfo.tickerid, i_htf2, barstate.isconfirmed) // Only use if the HTF bar is closed. Prevents repainting
// // if htfBarIsClosed
// // htf2WaveTrend := NewHtf2WaveTrend
// // htf2WaveTrendSignal := NewHtf2WaveTrendSignal
// // Alternative to "if"
// htf2WaveTrend := ta.valuewhen(htf2BarIsClosed, NewHtf2WaveTrend, 0)
// htf2WaveTrendSignal := ta.valuewhen(htf2BarIsClosed, NewHtf2WaveTrendSignal, 0)
// if htf1BarIsClosed
// alert('htf1 is: ' + str.tostring(htf1WaveTrend))
[wt, wts] = f_waveTrend(timeframe.period, i_ap, i_n1, i_n2, i_ma)
wtColor := wt[1] < wt[0] ? #00ff00 : wt[1] > wt[0] ? #eb4d4d : wtColor
htf1WaveTrendColor := htf1WaveTrend[1] < htf1WaveTrend[0] ? #018a01 : htf1WaveTrend[1] > htf1WaveTrend[0] ? #b51b1b : htf1WaveTrendColor
htf2WaveTrendColor := htf2WaveTrend[1] < htf2WaveTrend[0] ? #024d02 : htf2WaveTrend[1] > htf2WaveTrend[0] ? #800000 : htf2WaveTrendColor
plot(0, color=color.new(color.gray, 0))
plot(i_obLevel1, title='overbought', color=color.new(color.red, 0))
plot(i_osLevel1, title='oversold', color=color.new(color.green, 0))
plot(i_obLevel2, title='overbought min', color=color.new(color.red, 0), style=plot.style_cross)
plot(i_osLevel2, title='oversold max', color=color.new(color.green, 0), style=plot.style_cross)
plot(wt,title="WT",linewidth=3,color=wtColor)
plot(htf1WaveTrend,title="htfWT1",linewidth=3,color=htf1WaveTrendColor)
plot(htf2WaveTrend,title="htfWT2",linewidth=3,color=htf2WaveTrendColor)
...