Reputation: 39
Does anyone know how to change the weekly high and low to previous high and low plotted then on the current week in daily view on Tradingview?
The script to plot the current weekly high & low is below:
//@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)
Upvotes: 0
Views: 1988
Reputation: 39
tnx, I used this code:and overlaid it on the chart with your code, and it gives exactly the same result.
//@version=3 //modified by Juros as by xKaVaLiS as modidified by zonedoutdad from the script by ChrisMoody study(title="previous Week high & low", shorttitle="Prev Wk H-L", 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
prevWeekHigh = security(tickerid, 'W', high[1], lookahead=true) prevWeekLow = security(tickerid, 'W', low[1], lookahead=true)
//Weekly Plots plot(swt and prevWeekHigh ? prevWeekHigh : na, title="Prev Week High", style=stepline, linewidth=1, color=green,transp=50) plot(swt and prevWeekLow ? prevWeekLow : na, title="Prev Week Low", style=stepline, linewidth=1, color=red,transp=50)
Upvotes: 0
Reputation: 8779
That code suffered from lookahead bias because of the use of lookahead=true
here:
weekHigh = security(tickerid, 'W', high, lookahead=true)
weekLow = security(tickerid, 'W', low, lookahead=true)
This version allows you to show the previous or the current week's hi/lo, but without the lookahead bias. Note that the current week's value will repaint in the realtime bar:
//@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)
Upvotes: 1