You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

非重绘三时间框架Wave Trend指标浏览器端更新异常求助

问题描述
  • 三时间框架Wave Trend指标设定为K线收线后不重绘,仅在更高时间框架K线收线时调用对应数值
  • 当前图表使用1分钟时间框架,浏览器环境下部分标签页出现异常:高时间框架K线已收线,但指标的高时间框架数值未更新(停留在旧值),无需刷新浏览器即可观察到该问题,且其他指标未出现类似情况
  • 服务器端警报始终能获取正确的高时间框架数值
  • 修改后的代码存在错误:获取的高时间框架Wave Trend数值与实际值不符
原始Pine Script代码
//@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)
修改后的Pine Script代码
//@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)

内容的提问来源于stack exchange,提问作者camelCase

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 02:45:44