JayRogers

Previous Period Levels

Description:
  • It's just levels of previous periods, with the inclusion of 4 hour and and month. Nothing special.
Setup:
  • Should be mostly self explanatory... but selecting either the 4 hour or month check boxes will override the dropdown selection.
  • Checking both the 4 hour and month boxes together will cause it to default to whatever has been selected in the dropdown.
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

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.

Want to use this script on a chart?
//@version=2

study(title="Previous Period Levels", shorttitle="Previous Levels", overlay=true)

// Revision:        1
// Author:          @JayRogers
//
// Description:
//  - It's just levels of previous periods, with the inclusion of 4 hour and and month. Nothing special.
// Setup:
//  - Should be mostly self explanatory... but selecting either the 4 hour or month check boxes will override the dropdown selection.
//  - Checking both the 4 hour and month boxes together will cause it to default to whatever has been selected in the dropdown.

openLevel   = input(defval = true, title = "Show Open Level")
highLevel   = input(defval = true, title = "Show High Level")
lowLevel    = input(defval = true, title = "Show Low Level")
closeLevel  = input(defval = true, title = "Show Close Level")

hl2Level    = input(defval = false, title = "Show hl2 Level")
hlc3Level   = input(defval = false, title = "Show hlc3 Level")
ohlc4Level  = input(defval = false, title = "Show ohlc4 Level")

timeFrame   = input(defval = "D", title = "Select Time Frame ( or choose single option below ) ", type = resolution)
use4hour    = input(defval = false, title = "Use 4 hour?")
useMonth    = input(defval = false, title = "Use Month?")

// === BASE FUNCTIONS ===
// security wrapper for repeat calls
reso(exp, res) => security(tickerid, res, exp)
// === /BASE FUNCTIONS ===

tf() => use4hour and not useMonth ? "240" : useMonth and not use4hour ? "M" : timeFrame

openPrev    = change(time(tf())) ? na : reso(open[1], tf())
highPrev    = change(time(tf())) ? na : reso(high[1], tf())
lowPrev     = change(time(tf())) ? na : reso(low[1], tf())
closePrev   = change(time(tf())) ? na : reso(close[1], tf())

hl2Prev     = change(time(tf())) ? na : reso(hl2[1], tf())
hlc3Prev    = change(time(tf())) ? na : reso(hlc3[1], tf())
ohlc4Prev   = change(time(tf())) ? na : reso(ohlc4[1], tf())

plot(openLevel ? openPrev : na, title = "Open", color = silver, linewidth = 2, style = linebr, transp = 50)
plot(highLevel ? highPrev : na, title = "High", color = silver, linewidth = 2, style = linebr, transp = 50)
plot(lowLevel ? lowPrev : na, title = "Low", color = silver, linewidth = 2, style = linebr, transp = 50)
plot(closeLevel ? closePrev : na, title = "Close", color = silver, linewidth = 2, style = linebr, transp = 50)

plot(hl2Level ? hl2Prev : na, title = "hl2", color = silver, linewidth = 2, style = linebr, transp = 50)
plot(hlc3Level ? hlc3Prev : na, title = "hlc3", color = silver, linewidth = 2, style = linebr, transp = 50)
plot(ohlc4Level ? ohlc4Prev : na, title = "ohlc4", color = silver, linewidth = 2, style = linebr, transp = 50)