Conversion TradingView to ProRealtime – Previous OHLC
Forums › ProRealTime English forum › ProBuilder support › Conversion TradingView to ProRealtime – Previous OHLC
- This topic has 3 replies, 2 voices, and was last updated 5 years ago by Vonasi.
-
-
03/19/2019 at 9:55 AM #94002
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!
03/21/2019 at 8:47 AM #9424204/08/2019 at 2:54 PM #95716Try this:
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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272//SettingsLookBack = 1Y = 0Q = 0M = 1W = 0D = 0H4 = 0H1 = 0OpenClose = 1HighLow = 1//1 Hourif h1 thenif openhour <> openhour[1] thenh1index = h1index + 1h1high = 0h1low = closeh1open = openh1close = closeif h1index > lookback thenfor j = 1 to barindexif h1index[j] = h1index - lookback thenmyh1high = h1high[j]myh1low = h1low[j]myh1open = h1open[j]myh1close = h1close[j]breakendifnextendifendifh1high = max(h1high,high)h1low = min(h1low,low)h1close = closeendif//4 Hourif h4 thenif openhour <> openhour[1] and (openhour = 1 or openhour = 5 or openhour = 9 or openhour = 13 or openhour = 17 or openhour = 21) thenh4index = h4index + 1h4high = 0h4low = closeh4open = openh4close = closeif h4index > lookback thenfor j = 1 to barindexif h4index[j] = h4index - lookback thenmyh4high = h4high[j]myh4low = h4low[j]myh4open = h4open[j]myh4close = h4close[j]breakendifnextendifendifh4high = max(h4high,high)h4low = min(h4low,low)h4close = closeendif//Dayif d thenif openday <> openday[1] and openday[1] <> 7 thendayindex = dayindex + 1dayhigh = 0daylow = closedayopen = opendayclose = closeif dayindex > lookback thenfor j = 1 to barindexif dayindex[j] = dayindex - lookback thenmydayhigh = dayhigh[j]mydaylow = daylow[j]mydayopen = dayopen[j]mydayclose = dayclose[j]breakendifnextendifendifdayhigh = max(dayhigh,high)daylow = min(daylow,low)dayclose = closeendif//Weekif w thenif opendayofweek < opendayofweek[1] thenweekindex = weekindex + 1weekhigh = 0weeklow = closeweekopen = openweekclose = closeif weekindex > lookback thenfor j = 1 to barindexif weekindex[j] = weekindex - lookback thenmyweekhigh = weekhigh[j]myweeklow = weeklow[j]myweekopen = weekopen[j]myweekclose = weekclose[j]breakendifnextendifendifweekhigh = max(weekhigh,high)weeklow = min(weeklow,low)weekclose = closeendif//Monthif m thenif openmonth <> openmonth[1] thenmonthindex = monthindex + 1monthhigh = 0monthlow = closemonthopen = openmonthclose = closeif monthindex > lookback thenfor j = 1 to barindexif monthindex[j] = monthindex - lookback thenmymonthhigh = monthhigh[j]mymonthlow = monthlow[j]mymonthopen = monthopen[j]mymonthclose = monthclose[j]breakendifnextendifendifmonthhigh = max(monthhigh,high)monthlow = min(monthlow,low)monthclose = closeendif//Quarterif q thenif openmonth <> openmonth[1] and (openmonth = 1 or openmonth = 4 or openmonth = 7 or openmonth = 10) thenquarterindex = quarterindex + 1quarterhigh = 0quarterlow = closequarteropen = openquarterclose = closeif quarterindex > lookback thenfor j = 1 to barindexif quarterindex[j] = quarterindex - lookback thenmyquarterhigh = quarterhigh[j]myquarterlow = quarterlow[j]myquarteropen = quarteropen[j]myquarterclose = quarterclose[j]breakendifnextendifendifquarterhigh = max(quarterhigh,high)quarterlow = min(quarterlow,low)quarterclose = closeendif//Yearif y thenif openyear <> openyear[1] thenyearindex = yearindex + 1yearhigh = 0yearlow = closeyearopen = openyearclose = closeif yearindex > lookback thenfor j = 1 to barindexif yearindex[j] = yearindex - lookback thenmyyearhigh = yearhigh[j]myyearlow = yearlow[j]myyearopen = yearopen[j]myyearclose = yearclose[j]breakendifnextendifendifyearhigh = max(yearhigh,high)yearlow = min(yearlow,low)yearclose = closeendif//Remove zero value plotting at start and unwanted linesif h1index < lookback or not h1 or not openclose thenmyh1open = undefinedmyh1close = undefinedendifif h1index < lookback or not h1 or not highlow thenmyh1high = undefinedmyh1low = undefinedendifif h4index < lookback or not h4 or not openclose thenmyh4open = undefinedmyh4close = undefinedendifif h4index < lookback or not h4 or not highlow thenmyh4high = undefinedmyh4low = undefinedendifif dayindex < lookback or not d or not openclose thenmydayopen = undefinedmydayclose = undefinedendifif dayindex < lookback or not d or not highlow thenmydayhigh = undefinedmydaylow = undefinedendifif weekindex < lookback or not w or not openclose thenmyweekopen = undefinedmyweekclose = undefinedendifif weekindex < lookback or not w or not highlow thenmyweekhigh = undefinedmyweeklow = undefinedendifif monthindex < lookback or not m or not openclose thenmymonthopen = undefinedmymonthclose = undefinedendifif monthindex < lookback or not m or not highlow thenmymonthhigh = undefinedmymonthlow = undefinedendifif quarterindex < lookback or not q or not openclose thenmyquarteropen = undefinedmyquarterclose = undefinedendifif quarterindex < lookback or not q or not highlow thenmyquarterhigh = undefinedmyquarterlow = undefinedendifif yearindex < lookback or not y or not openclose thenmyyearopen = undefinedmyyearclose = undefinedendifif yearindex < lookback or not y or not highlow thenmyyearhigh = undefinedmyyearlow = undefinedendifreturn 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"04/08/2019 at 3:08 PM #95720I 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!
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on