Monthly High Low Close Indicator
Forums › ProRealTime English forum › ProBuilder support › Monthly High Low Close Indicator
- This topic has 49 replies, 13 voices, and was last updated 3 years ago by MacroT.
-
-
04/05/2019 at 12:50 PM #9553704/05/2019 at 2:28 PM #9554304/05/2019 at 4:32 PM #95560
This might help:
1234567891011121314151617181920212223242526272829303132if (opendayofweek = 1) or (opendayofweek < opendayofweek[1] and opendayofweek <> 0) thenlastweekhigh = weekhighlastweeklow = weeklowlastweekopen = weekopenlastweekclose = weekcloseweekhigh = 0weeklow = closeweekopen = openweekclose = closeendifweekhigh = max(weekhigh,high)weeklow = min(weeklow,low)weekclose = closeif openmonth <> openmonth[1] thenlastmonthhigh = monthhighlastmonthlow = monthlowlastmonthopen = monthopenlastmonthclose = monthclosemonthhigh = 0monthlow = closemonthopen = openmonthclose = closeendifmonthhigh = max(monthhigh,high)monthlow = min(monthlow,low)monthclose = closereturn lastweekhigh as "Last Weeks High",lastweeklow as "Last Weeks Low",lastweekclose as "Last Weeks Close",lastweekopen as "Last Weeks Open", lastmonthhigh as "Last Months High",lastmonthlow as "Last Months Low",lastmonthclose as "Last Months Close",lastmonthopen as "Last Months Open"It recognises the start of a new week (even if it is not a Monday) and the start of a new month and starts recording highs, lows, open and close. At the start of every new week and new month it records the previous weeks/months values.
04/05/2019 at 7:42 PM #95582I just realised that my code in the last post starts the week at the open of the first weekly candle from Monday onwards when it should really be the Sunday candle onwards as this is when a week actually starts trading. Just change line 1 to:
1if opendayofweek < opendayofweek[1] then04/06/2019 at 10:57 AM #9560104/06/2019 at 11:29 AM #95604how to get the weekly / monthly OHLC from N weeks /months ago ?
By creating our own index that updates whenever a new month or new week start is detected and then searching back using a FOR NEXT or WHILE WEND loop this should be possible. I will try to code something – lunch first though!
04/06/2019 at 12:19 PM #95609Easier to separate it into two indicators – a weekly one and a monthly one.
weeklookback is the variable for how many weeks you want to look back (1 = last week, 2 = two weeks ago). monthlookback in the monthly version.
Weekly123456789101112131415161718192021222324252627weeklookback = 2if opendayofweek < opendayofweek[1] thenweekindex = weekindex + 1weekhigh = 0weeklow = closeweekopen = openweekclose = closeendifweekhigh = max(weekhigh,high)weeklow = min(weeklow,low)weekclose = closeif weekindex > weeklookback thenfor j = 1 to barindexif weekindex[j] = weekindex - weeklookback thenmyweekhigh = weekhigh[j]myweeklow = weeklow[j]myweekopen = weekopen[j]myweekclose = weekclose[j]breakendifnextendifreturn myweekhigh as "Week High", myweeklow as "Week Low", myweekclose as "Week Close", myweekopen as "Week Open"Monthly123456789101112131415161718192021222324252627monthlookback = 2if openmonth <> openmonth[1] thenmonthindex = monthindex + 1monthhigh = 0monthlow = closemonthopen = openmonthclose = closeendifmonthhigh = max(monthhigh,high)monthlow = min(monthlow,low)monthclose = closeif monthindex > monthlookback thenfor j = 1 to barindexif monthindex[j] = monthindex - monthlookback thenmymonthhigh = monthhigh[j]mymonthlow = monthlow[j]mymonthopen = monthopen[j]mymonthclose = monthclose[j]breakendifnextendifreturn mymonthhigh as "Month High", mymonthlow as "Month Low", mymonthclose as "Month Close", mymonthopen as "Month Open"1 user thanked author for this post.
04/06/2019 at 3:36 PM #95614Wow, amazing code @vonasi !
I just moved the second IF inside the first IF block and it seems to run faster. In fact we only need to check past OHLC data when month or week changes, not on every bar.
monthly1234567891011121314151617181920212223242526272829monthlookback = 2if openmonth <> openmonth[1] thenmonthindex = monthindex + 1monthhigh = 0monthlow = closemonthopen = openmonthclose = closeif monthindex > monthlookback thenfor j = 1 to barindexif monthindex[j] = monthindex - monthlookback thenmymonthhigh = monthhigh[j]mymonthlow = monthlow[j]mymonthopen = monthopen[j]mymonthclose = monthclose[j]breakendifnextendifendifmonthhigh = max(monthhigh,high)monthlow = min(monthlow,low)monthclose = closereturn mymonthopen as "Month Open", mymonthhigh as "Month High", mymonthlow as "Month Low", mymonthclose as "Month Close"Weekly12345678910111213141516171819202122232425262728weeklookback = 2if opendayofweek < opendayofweek[1] thenweekindex = weekindex + 1weekhigh = 0weeklow = closeweekopen = openweekclose = closeif weekindex > weeklookback thenfor j = 1 to barindexif weekindex[j] = weekindex - weeklookback thenmyweekhigh = weekhigh[j]myweeklow = weeklow[j]myweekopen = weekopen[j]myweekclose = weekclose[j]breakendifnextendifendifweekhigh = max(weekhigh,high)weeklow = min(weeklow,low)weekclose = closereturn myweekopen as "Week Open", myweekhigh as "Week High", myweeklow as "Week Low", myweekclose as "Week Close"04/06/2019 at 4:08 PM #95617Well spotted pableitor. In my defence I did code it while eating lunch as I was too impatient to get started on it!
Glad you like it – although I’m not sure what use there is in knowing what the OHLC was several months ago? Personally I’ve never found previous OHLC levels to offer any support or resistance of any worth but I’m willing to be proved wrong.
04/06/2019 at 7:28 PM #95626Here is a minor improvement that gets rid of the problem of values being zero until the first new week or month has been recognised. They are now all equal to close and not drawn on the chart. I’ve added some colour too.
Weekly123456789101112131415161718192021222324252627282930313233343536weeklookback = 2if opendayofweek < opendayofweek[1] thenweekindex = weekindex + 1weekhigh = 0weeklow = closeweekopen = openweekclose = closeif weekindex > weeklookback thenfor j = 1 to barindexif weekindex[j] = weekindex - weeklookback thenmyweekhigh = weekhigh[j]myweeklow = weeklow[j]myweekopen = weekopen[j]myweekclose = weekclose[j]breakendifnextendifendifweekhigh = max(weekhigh,high)weeklow = min(weeklow,low)weekclose = closec = 255if myweekopen = 0 thenmyweekopen = closemyweekclose = closemyweekhigh = closemyweeklow = closec = 0endifreturn myweekopen coloured(0,0,0,c)as "Week Open", myweekhigh coloured(0,128,0,c) as "Week High", myweeklow coloured(128,0,0,c) as "Week Low", myweekclose coloured(0,0,255,c) as "Week Close"Monthly123456789101112131415161718192021222324252627282930313233343536monthlookback = 2if openmonth <> openmonth[1] thenmonthindex = monthindex + 1monthhigh = 0monthlow = closemonthopen = openmonthclose = closeif monthindex > monthlookback thenfor j = 1 to barindexif monthindex[j] = monthindex - monthlookback thenmymonthhigh = monthhigh[j]mymonthlow = monthlow[j]mymonthopen = monthopen[j]mymonthclose = monthclose[j]breakendifnextendifendifmonthhigh = max(monthhigh,high)monthlow = min(monthlow,low)monthclose = closec = 255if mymonthopen = 0 thenmymonthopen = closemymonthclose = closemymonthhigh = closemymonthlow = closec = 0endifreturn mymonthopen coloured(0,0,0,c)as "Month Open", mymonthhigh coloured (0,128,0,c) as "Month High", mymonthlow coloured (128,0,0,c) as "Month Low", mymonthclose coloured (0,0,255,c) as "Month Close"04/08/2019 at 7:17 AM #9565801/08/2021 at 10:28 AM #156871One of the codes posted in this thread works fine on prt v 10.3 but not on v11.1.
I am displayed with the error ‘A positive integer field is expected with highest’ message
Thanks
12345678910111213141516171819If Month<>Month[1] thenmonthlyH = Highest[BarIndex – lastMonthBarIndex](High)[1]monthlyL = Lowest[BarIndex – lastMonthBarIndex](Low)[1]lastMonthBarIndex = BarIndexif trimH=0 thentrimH=monthlyHendiftrimH=max(trimH,monthlyH)if trimL=0 thentrimL=monthlyLendiftrimL=min(trimL,monthlyL)if openmonth=4 or openmonth=7 or openmonth=10 or openmonth=1 thentrimestrialH=trimHtrimestrialL=trimLendifEndifreturn trimestrialH,trimestrialL01/08/2021 at 10:42 AM #156875Always use the ‘Insert PRT Code’ button when putting code in your posts to make it easier for others to read.
Thank you 🙂
01/08/2021 at 11:13 AM #156882MacroT – Try this:
123456789101112131415161718192021if barindex >= 1 thenIf Month<>Month[1] thenmonthlyH = Highest[BarIndex - lastMonthBarIndex](High)[1]monthlyL = Lowest[BarIndex - lastMonthBarIndex](Low)[1]lastMonthBarIndex = BarIndexif trimH=0 thentrimH=monthlyHendiftrimH=max(trimH,monthlyH)if trimL=0 thentrimL=monthlyLendiftrimL=min(trimL,monthlyL)if openmonth=4 or openmonth=7 or openmonth=10 or openmonth=1 thentrimestrialH=trimHtrimestrialL=trimLendifEndifendifreturn trimestrialH,trimestrialL01/08/2021 at 12:11 PM #156892 -
AuthorPosts
Find exclusive trading pro-tools on