ProRealCode - Trading & Coding with ProRealTime™
Hallo,
the second script contains previous OHLC values – see attachment. In Tradingview I can select the timeframe for the previous OHLC from 15 Minutes to 1 Month. For example – if i use the Daily chart I can choose to visualize the previous weekly and monthly OHLC. I can also select if I want to see all OHLC, only High/Low or only Open/Close. In the attached picture Week (blue line) and Month (black dotted) previous OHLC are selected and this only for High/Low.
Questions:
Can anyone provide an exact conversion of the code below?
Most important are 1 Hour to 1 Month previous OHLC. A possibility to easy select between the previous OHLC timeframes would be great. If a selection is not possible, also seperated scripts for each timeframe would be good.
I also want to use this as screener – e.g. scan for stocks which are 1 % (variable) in the range of their previous OHLC (Month Low). Is this possible in ProRealtime and can anyone provide this as a screener script?
Tradingview code:
//@version=3
study(title=”SVVT PreOHLC Intraday/Month V1.8″, shorttitle=”SVVT PreOHLC Intraday/Month V1.8″, overlay=true)
select_inp = input(defval=”All OHLC”, title=’OHLC Selection’, options=[“All OHLC”,”Only High/Low”,”Only Open/Close”])
pm = input(false, title=”Show Pre-Month OHLC?”)
pw = input(false, title=”Show Pre-Week OHLC?”)
pd = input(false, title=”Show Pre-Day OHLC?”)
p4h = input(false, title=”Show Pre-4-Hour OHLC?”)
p2h = input(false, title=”Show Pre-2-Hour OHLC?”)
p1h = input(true, title=”Show Pre-1-Hour OHLC?”)
p30m = input(false, title=”Show Pre-30-Min OHLC?”)
p15m = input(false, title=”Show Pre-15-Min OHLC?”)
//Monthly
mo = security(tickerid, ‘M’, open[1], lookahead=barmerge.lookahead_on)
mc = security(tickerid, ‘M’, close[1], lookahead=barmerge.lookahead_on)
mh = security(tickerid, ‘M’, high[1], lookahead=barmerge.lookahead_on)
ml = security(tickerid, ‘M’, low[1], lookahead=barmerge.lookahead_on)
//Weekly
wo = security(tickerid, ‘W’, open[1], lookahead=barmerge.lookahead_on)
wc = security(tickerid, ‘W’, close[1], lookahead=barmerge.lookahead_on)
wh = security(tickerid, ‘W’, high[1], lookahead=barmerge.lookahead_on)
wl = security(tickerid, ‘W’, low[1], lookahead=barmerge.lookahead_on)
//Daily
do = security(tickerid, ‘D’, open[1], lookahead=barmerge.lookahead_on)
dc = security(tickerid, ‘D’, close[1], lookahead=barmerge.lookahead_on)
dh = security(tickerid, ‘D’, high[1], lookahead=barmerge.lookahead_on)
dl = security(tickerid, ‘D’, low[1], lookahead=barmerge.lookahead_on)
//4 Hour
fho = security(tickerid, ‘240’, open[1], lookahead=barmerge.lookahead_on)
fhc = security(tickerid, ‘240’, close[1], lookahead=barmerge.lookahead_on)
fhh = security(tickerid, ‘240’, high[1], lookahead=barmerge.lookahead_on)
fhl = security(tickerid, ‘240’, low[1], lookahead=barmerge.lookahead_on)
//2 Hour
tho = security(tickerid, ‘120’, open[1], lookahead=barmerge.lookahead_on)
thc = security(tickerid, ‘120’, close[1], lookahead=barmerge.lookahead_on)
thh = security(tickerid, ‘120’, high[1], lookahead=barmerge.lookahead_on)
thl = security(tickerid, ‘120’, low[1], lookahead=barmerge.lookahead_on)
//1 Hour
oho = security(tickerid, ’60’, open[1], lookahead=barmerge.lookahead_on)
ohc = security(tickerid, ’60’, close[1], lookahead=barmerge.lookahead_on)
ohh = security(tickerid, ’60’, high[1], lookahead=barmerge.lookahead_on)
ohl = security(tickerid, ’60’, low[1], lookahead=barmerge.lookahead_on)
//30 Min
tomo = security(tickerid, ’30’, open[1], lookahead=barmerge.lookahead_on)
tomc = security(tickerid, ’30’, close[1], lookahead=barmerge.lookahead_on)
tomh = security(tickerid, ’30’, high[1], lookahead=barmerge.lookahead_on)
toml = security(tickerid, ’30’, low[1], lookahead=barmerge.lookahead_on)
//15 Min
ofmo = security(tickerid, ’15’, open[1], lookahead=barmerge.lookahead_on)
ofmc = security(tickerid, ’15’, close[1], lookahead=barmerge.lookahead_on)
ofmh = security(tickerid, ’15’, high[1], lookahead=barmerge.lookahead_on)
ofml = security(tickerid, ’15’, low[1], lookahead=barmerge.lookahead_on)
//Plots
select = select_inp == “All OHLC” ? 0 : select_inp == “Only High/Low” ? 1 : 2
//Monthly
plot(pm and mo and (select == 0 or select == 2) ? mo : na, title=”Pre-Month Open”, style=linebr, linewidth=1, color=#DF01D7, transp=0)
plot(pm and mc and (select == 0 or select == 2) ? mc : na, title=”Pre-Month Close”, style=linebr, linewidth=1, color=blue, transp=0)
plot(pm and mh and (select == 0 or select == 1) ? mh : na, title=”Pre-Month High”, style=linebr, linewidth=1, color=black, transp=0)
plot(pm and ml and (select == 0 or select == 1) ? ml : na, title=”Pre-Month Low”, style=linebr, linewidth=1, color=black, transp=0)
//Weekly
plot(pw and wo and (select == 0 or select == 2) ? wo : na, title=”Pre-Week Open”, style=linebr, linewidth=1, color=#DF01D7, transp=0)
plot(pw and wc and (select == 0 or select == 2) ? wc : na, title=”Pre-Week Close”, style=linebr, linewidth=1, color=blue, transp=0)
plot(pw and wh and (select == 0 or select == 1) ? wh : na, title=”Pre-Week High”, style=linebr, linewidth=1, color=black, transp=0)
plot(pw and wl and (select == 0 or select == 1) ? wl : na, title=”Pre-Week Low”, style=linebr, linewidth=1, color=black, transp=0)
//Daily
plot(pd and do and (select == 0 or select == 2) ? do : na, title=”Pre-Day Open”, style=linebr, linewidth=1, color=#DF01D7, transp=0)
plot(pd and dc and (select == 0 or select == 2) ? dc : na, title=”Pre-Day Close”, style=linebr, linewidth=1, color=blue, transp=0)
plot(pd and dh and (select == 0 or select == 1) ? dh : na, title=”Pre-Day High”, style=linebr, linewidth=1, color=black, transp=0)
plot(pd and dl and (select == 0 or select == 1) ? dl : na, title=”Pre-Day Low”, style=linebr, linewidth=1, color=black, transp=0)
//4 Hour
plot(p4h and fho and (select == 0 or select == 2) ? fho : na, title=”Pre-4-Hour Open”, style=linebr, linewidth=1, color=#DF01D7, transp=0)
plot(p4h and fhc and (select == 0 or select == 2) ? fhc : na, title=”Pre-4-Hour Close”, style=linebr, linewidth=1, color=blue, transp=0)
plot(p4h and fhh and (select == 0 or select == 1) ? fhh : na, title=”Pre-4-Hour High”, style=linebr, linewidth=1, color=black, transp=0)
plot(p4h and fhl and (select == 0 or select == 1) ? fhl : na, title=”Pre-4-Hour Low”, style=linebr, linewidth=1, color=black, transp=0)
//2 Hour
plot(p2h and tho and (select == 0 or select == 2) ? tho : na, title=”Pre-2-Hour Open”, style=linebr, linewidth=1, color=#DF01D7, transp=0)
plot(p2h and thc and (select == 0 or select == 2) ? thc : na, title=”Pre-2-Hour Close”, style=linebr, linewidth=1, color=blue, transp=0)
plot(p2h and thh and (select == 0 or select == 1) ? thh : na, title=”Pre-2-Hour High”, style=linebr, linewidth=1, color=black, transp=0)
plot(p2h and thl and (select == 0 or select == 1) ? thl : na, title=”Pre-2-Hour Low”, style=linebr, linewidth=1, color=black, transp=0)
//1 Hour
plot(p1h and oho and (select == 0 or select == 2) ? oho : na, title=”Pre-1-Hour Open”, style=linebr, linewidth=1, color=#DF01D7, transp=0)
plot(p1h and ohc and (select == 0 or select == 2) ? ohc : na, title=”Pre-1-Hour Close”, style=linebr, linewidth=1, color=blue, transp=0)
plot(p1h and ohh and (select == 0 or select == 1) ? ohh : na, title=”Pre-1-Hour High”, style=linebr, linewidth=1, color=black, transp=0)
plot(p1h and ohl and (select == 0 or select == 1) ? ohl : na, title=”Pre-1-Hour Low”, style=linebr, linewidth=1, color=black, transp=0)
//30 Min
plot(p30m and tomo and (select == 0 or select == 2) ? tomo : na, title=”Pre-30-Min Open”, style=linebr, linewidth=1, color=#DF01D7, transp=0)
plot(p30m and tomc and (select == 0 or select == 2) ? tomc : na, title=”Pre-30-Min Close”, style=linebr, linewidth=1, color=blue, transp=0)
plot(p30m and tomh and (select == 0 or select == 1) ? tomh : na, title=”Pre-30-Min High”, style=linebr, linewidth=1, color=black, transp=0)
plot(p30m and toml and (select == 0 or select == 1) ? toml : na, title=”Pre-30-Min Low”, style=linebr, linewidth=1, color=black, transp=0)
//15 Min
plot(p15m and ofmo and (select == 0 or select == 2) ? ofmo : na, title=”Pre-15-Min Open”, style=linebr, linewidth=1, color=#DF01D7, transp=0)
plot(p15m and ofmo and (select == 0 or select == 2) ? ofmc : na, title=”Pre-15-Min Close”, style=linebr, linewidth=1, color=blue, transp=0)
plot(p15m and ofmo and (select == 0 or select == 1) ? ofmh : na, title=”Pre-15-Min High”, style=linebr, linewidth=1, color=black, transp=0)
plot(p15m and ofmo and (select == 0 or select == 1) ? ofml : na, title=”Pre-15-Min Low”, style=linebr, linewidth=1, color=black, transp=0)
Thanks and best regards!
Anyone?
Try this:
[attachment file=”OHLC Y Q M W D H4 H1.itf”]
Lookback value is 1 = last year, last month last week etc. 2 = two years ago, two months ago, two weeks ago etc.
With this feature you can apply the indicator more than once to a chart and have the last three months OHLC values shown for example.
[attachment file=95717]
//Settings
LookBack = 1
Y = 0
Q = 0
M = 1
W = 0
D = 0
H4 = 0
H1 = 0
OpenClose = 1
HighLow = 1
//1 Hour
if h1 then
if openhour <> openhour[1] then
h1index = h1index + 1
h1high = 0
h1low = close
h1open = open
h1close = close
if h1index > lookback then
for j = 1 to barindex
if h1index[j] = h1index - lookback then
myh1high = h1high[j]
myh1low = h1low[j]
myh1open = h1open[j]
myh1close = h1close[j]
break
endif
next
endif
endif
h1high = max(h1high,high)
h1low = min(h1low,low)
h1close = close
endif
//4 Hour
if h4 then
if openhour <> openhour[1] and (openhour = 1 or openhour = 5 or openhour = 9 or openhour = 13 or openhour = 17 or openhour = 21) then
h4index = h4index + 1
h4high = 0
h4low = close
h4open = open
h4close = close
if h4index > lookback then
for j = 1 to barindex
if h4index[j] = h4index - lookback then
myh4high = h4high[j]
myh4low = h4low[j]
myh4open = h4open[j]
myh4close = h4close[j]
break
endif
next
endif
endif
h4high = max(h4high,high)
h4low = min(h4low,low)
h4close = close
endif
//Day
if d then
if openday <> openday[1] and openday[1] <> 7 then
dayindex = dayindex + 1
dayhigh = 0
daylow = close
dayopen = open
dayclose = close
if dayindex > lookback then
for j = 1 to barindex
if dayindex[j] = dayindex - lookback then
mydayhigh = dayhigh[j]
mydaylow = daylow[j]
mydayopen = dayopen[j]
mydayclose = dayclose[j]
break
endif
next
endif
endif
dayhigh = max(dayhigh,high)
daylow = min(daylow,low)
dayclose = close
endif
//Week
if w then
if opendayofweek < opendayofweek[1] then
weekindex = weekindex + 1
weekhigh = 0
weeklow = close
weekopen = open
weekclose = close
if weekindex > lookback then
for j = 1 to barindex
if weekindex[j] = weekindex - lookback then
myweekhigh = weekhigh[j]
myweeklow = weeklow[j]
myweekopen = weekopen[j]
myweekclose = weekclose[j]
break
endif
next
endif
endif
weekhigh = max(weekhigh,high)
weeklow = min(weeklow,low)
weekclose = close
endif
//Month
if m then
if openmonth <> openmonth[1] then
monthindex = monthindex + 1
monthhigh = 0
monthlow = close
monthopen = open
monthclose = close
if monthindex > lookback then
for j = 1 to barindex
if monthindex[j] = monthindex - lookback then
mymonthhigh = monthhigh[j]
mymonthlow = monthlow[j]
mymonthopen = monthopen[j]
mymonthclose = monthclose[j]
break
endif
next
endif
endif
monthhigh = max(monthhigh,high)
monthlow = min(monthlow,low)
monthclose = close
endif
//Quarter
if q then
if openmonth <> openmonth[1] and (openmonth = 1 or openmonth = 4 or openmonth = 7 or openmonth = 10) then
quarterindex = quarterindex + 1
quarterhigh = 0
quarterlow = close
quarteropen = open
quarterclose = close
if quarterindex > lookback then
for j = 1 to barindex
if quarterindex[j] = quarterindex - lookback then
myquarterhigh = quarterhigh[j]
myquarterlow = quarterlow[j]
myquarteropen = quarteropen[j]
myquarterclose = quarterclose[j]
break
endif
next
endif
endif
quarterhigh = max(quarterhigh,high)
quarterlow = min(quarterlow,low)
quarterclose = close
endif
//Year
if y then
if openyear <> openyear[1] then
yearindex = yearindex + 1
yearhigh = 0
yearlow = close
yearopen = open
yearclose = close
if yearindex > lookback then
for j = 1 to barindex
if yearindex[j] = yearindex - lookback then
myyearhigh = yearhigh[j]
myyearlow = yearlow[j]
myyearopen = yearopen[j]
myyearclose = yearclose[j]
break
endif
next
endif
endif
yearhigh = max(yearhigh,high)
yearlow = min(yearlow,low)
yearclose = close
endif
//Remove zero value plotting at start and unwanted lines
if h1index < lookback or not h1 or not openclose then
myh1open = undefined
myh1close = undefined
endif
if h1index < lookback or not h1 or not highlow then
myh1high = undefined
myh1low = undefined
endif
if h4index < lookback or not h4 or not openclose then
myh4open = undefined
myh4close = undefined
endif
if h4index < lookback or not h4 or not highlow then
myh4high = undefined
myh4low = undefined
endif
if dayindex < lookback or not d or not openclose then
mydayopen = undefined
mydayclose = undefined
endif
if dayindex < lookback or not d or not highlow then
mydayhigh = undefined
mydaylow = undefined
endif
if weekindex < lookback or not w or not openclose then
myweekopen = undefined
myweekclose = undefined
endif
if weekindex < lookback or not w or not highlow then
myweekhigh = undefined
myweeklow = undefined
endif
if monthindex < lookback or not m or not openclose then
mymonthopen = undefined
mymonthclose = undefined
endif
if monthindex < lookback or not m or not highlow then
mymonthhigh = undefined
mymonthlow = undefined
endif
if quarterindex < lookback or not q or not openclose then
myquarteropen = undefined
myquarterclose = undefined
endif
if quarterindex < lookback or not q or not highlow then
myquarterhigh = undefined
myquarterlow = undefined
endif
if yearindex < lookback or not y or not openclose then
myyearopen = undefined
myyearclose = undefined
endif
if yearindex < lookback or not y or not highlow then
myyearhigh = undefined
myyearlow = undefined
endif
return myweekopen coloured(100,149,237) as "Week Open", myweekhigh coloured(0,128,0) as "Week High", myweeklow coloured(128,0,0) as "Week Low", myweekclose coloured(0,0,255) as "Week Close", mymonthopen coloured(100,149,237) as "Month Open", mymonthhigh coloured (0,128,0) as "Month High", mymonthlow coloured (128,0,0) as "Month Low", mymonthclose coloured (0,0,255) as "Month Close",mydayopen coloured(100,149,237) as "Day Open", mydayhigh coloured (0,128,0) as "Day High", mydaylow coloured (128,0,0) as "Day Low", mydayclose coloured (0,0,255) as "Day Close", myyearopen coloured(100,149,237) as "Year Open", myyearhigh coloured (0,128,0) as "Year High", myyearlow coloured (128,0,0) as "Year Low", myyearclose coloured (0,0,255) as "Year Close", myquarteropen coloured(100,149,237) as "Quarter Open", myquarterhigh coloured (0,128,0) as "Quarter High", myquarterlow coloured (128,0,0) as "Quarter Low", myquarterclose coloured (0,0,255) as "Quarter Close", myh4open coloured(100,149,237) as "H4 Open", myh4high coloured (0,128,0) as "H4 High", myh4low coloured (128,0,0) as "H4 Low", myh4close coloured (0,0,255) as "H4 Close", myh1open coloured(100,149,237) as "H1 Open", myh1high coloured (0,128,0) as "H1 High", myh1low coloured (128,0,0) as "H1 Low", myh1close coloured (0,0,255) as "H1 Close"
I forgot to say that the daily values are calculated starting at the open of the Monday candle to remove the issue of having Sunday OHLC values throughout Monday. You actually get the OHLC of Friday and Sunday combined shown on a Monday. The weekly values are calculated from the open of the Sunday candle. If there is no trading due to holidays then the OHLC starts on the first trading day of a week.
You have to have enough candles on a chart to display the values. The indicator has to wait until a complete year from Jan 1st to Dec 31st is displayed before it can display any OHLC values. The same for a month – it needs a whole month before it can display anything. Same for a week etc.
It can be slow to draw if you want everything displayed on a lot of bars!
Conversion TradingView to ProRealtime – Previous OHLC
This topic contains 3 replies,
has 2 voices, and was last updated by Vonasi
6 years, 10 months ago.
| Forum: | ProBuilder: Indicators & Custom Tools |
| Language: | English |
| Started: | 03/19/2019 |
| Status: | Active |
| Attachments: | 3 files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.