有人知道如何在Tradingview的每日视图中将每周的高点和低点更改为先前在本周绘制的高点和低点吗?
下面是绘制当前每周最高价和最低价的脚本:
//@version=3
//modified Juros as by xKaVaLiS as modidified by zonedoutdad from the script by ChrisMoody
study(title="previous Weekly OHLC", shorttitle="previous Weekly OHLC", overlay=true, precision=8)
swt = input(true, title="Show This Weeks OHLC?")
showMonthly = input(false, title="Show Monthly Data (open/close)?")
highlightBG = input(false, title="Highlight Background Bias")
aboveBelowBarWeekIndicator = input(true, title="Turn on Above/Below Week Open Top Chart")
//Weekly
prevWeekClose = security(tickerid, 'W', close[1], lookahead=true)
weekHigh = security(tickerid, 'W', high, lookahead=true)
prevWeekHigh = security(tickerid, 'W', high[1], lookahead=true)
weekLow = security(tickerid, 'W', low, lookahead=true)
prevWeekLow = security(tickerid, 'W', low[1], lookahead=true)
//Weekly Plots
plot(swt and weekHigh ? weekHigh : na, title="Weekly High", style=circles, linewidth=1, color=green,transp=0)
plot(swt and weekLow ? weekLow : na, title="Weekly Low", style=circles, linewidth=1, color=red,transp=0)
答案 0 :(得分:1)
由于在此处使用lookahead=true
,该代码遭受了前瞻性偏差:
weekHigh = security(tickerid, 'W', high, lookahead=true)
weekLow = security(tickerid, 'W', low, lookahead=true)
此版本允许您显示前一周或当前一周的高/低,但没有前瞻性偏见。请注意,当前星期的值将在实时栏中重新绘制:
//@version=3
//modified Juros as by xKaVaLiS as modidified by zonedoutdad from the script by ChrisMoody
study(title="previous Weekly OHLC", shorttitle="previous Weekly OHLC", overlay=true, precision=8)
swt = input(true, title="Show This Week's HL?")
spw = input(true, title="Show Previous Week's HL?")
//Weekly
weekHigh = security(tickerid, 'W', high)
weekLow = security(tickerid, 'W', low)
prevWeekHigh = security(tickerid, 'W', high[1], lookahead=true)
prevWeekLow = security(tickerid, 'W', low[1], lookahead=true)
//Weekly Plots
plot(swt ? weekHigh : na, title="Weekly High", style=circles, linewidth=2, color=green,transp=0)
plot(swt ? weekLow : na, title="Weekly Low", style=circles, linewidth=2, color=maroon,transp=0)
plot(spw ? prevWeekHigh : na, title="Previous Weekly High", style=circles, linewidth=6, color=lime,transp=80)
plot(spw ? prevWeekLow : na, title="Previous Weekly Low", style=circles, linewidth=6, color=red,transp=80)
答案 1 :(得分:0)
tnx, 我使用了这段代码:并用您的代码将其覆盖在图表上,它给出的结果完全相同。
// @ version = 3 //由Juros修改为xKaVaLiS,由xKaVaLiS修改 来自ChrisMoody研究的脚本中的zonedoutdad(title =“上周 高和低”,shorttitle =“上一个星期H-L”,overlay = true,precision = 8)swt =输入(true,title =“显示本周OHLC?”)showMonthly =输入(false,title =“显示月度数据(打开/关闭)?”)HighlightBG = 输入(false,title =“突出显示背景偏差”) aboveBelowBarWeekIndicator = input(true,title =“打开上方/下方 周开放排行榜”)
//每周
prevWeekHigh =安全性(tickerid,'W',high [1],lookahead = true) prevWeekLow =安全性(tickerid,'W',low [1],lookahead = true)
///每周绘图图(swt和prevWeekHigh?prevWeekHigh:不, title =“上周高点”,style =阶梯线,线宽= 1, color = green,transp = 50)plot(swt and prevWeekLow?prevWeekLow:na, title =“上周低位”,style =阶梯线,线宽= 1, color = red,transp = 50)