Help with coding average price based on pivots and moving averages
Forums › ProRealTime English forum › ProBuilder support › Help with coding average price based on pivots and moving averages
- This topic has 7 replies, 3 voices, and was last updated 6 years ago by skfomx.
-
-
08/09/2018 at 9:51 PM #77903
Hi there!
I am a newbie trying to create an indicator that produces an average daily price by combining daily, weekly, and monthly pivots and simple moving average 5, 20,50,100,200. I want to give more weight to the pivot points compared to the moving averages so I duplicate the pivot point numbers before dividing all of them.
Pro realtime does not like the indicator. It works on some instruments but not on others. For example it works on aud/cad but not on eur/usd.
Calculation error: “A positive integer field is expected with highest”
Can anyone help? It would be much appreciated!
08/09/2018 at 9:52 PM #77904This is the code:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465//Pivot calculation methodOnce mode = 1Once dailyPivot = 1Once lastWeekBarIndex = 1Once weeklyHigh = undefinedOnce weeklyLow = undefinedOnce weeklyPivot = undefinedOnce lastMonthBarIndex = 0Once monthlyHigh = undefinedOnce monthlyLow = undefinedOnce monthlyPivot = undefinedIf Day>Day[1] thenIf mode = 1 thendailyPivot = (DHigh(1) + DLow(1) + Close[1]) / 3Elsif mode = 1 thendailyPivot = (Open + DHigh(1) + DLow(1) + Close[1]) / 4Elsif mode = 2 thendailyPivot = (DHigh(1) + DLow(1) + Close[1]*2) / 4ElsedailyPivot = (Open*2 + DHigh(1) + DLow(1)) / 4EndifEndifIf DayOfWeek<DayOfWeek[1] thenweeklyHigh = Highest[BarIndex – lastWeekBarIndex](High)[1]weeklyLow = Lowest[BarIndex – lastWeekBarIndex](Low)[1]lastWeekBarIndex = BarIndexIf mode = 1 thenweeklyPivot = (weeklyHigh + weeklyLow + Close[1]) / 3Elsif mode = 1 thenweeklyPivot = (Open + weeklyHigh + weeklyLow + Close[1]) / 4Elsif mode = 2 thenweeklyPivot = (weeklyHigh + weeklyLow + Close[1]*2) / 4ElseweeklyPivot = (Open*2 + weeklyHigh + weeklyLow) / 4EndifEndifIf Month<>Month[1] thenmonthlyHigh = Highest[BarIndex – lastMonthBarIndex](High)[1]monthlyLow = Lowest[BarIndex – lastMonthBarIndex](Low)[1]lastMonthBarIndex = BarIndexIf mode = 1 thenmonthlyPivot = (monthlyHigh + monthlyLow + Close[1]) / 3Elsif mode = 1 thenmonthlyPivot = (Open + monthlyHigh + monthlyLow + Close[1]) / 4Elsif mode = 2 thenmonthlyPivot = (monthlyHigh + monthlyLow + Close[1]*2) / 4ElsemonthlyPivot = (Open*2 + monthlyHigh + monthlyLow) / 4EndifEndifc1= (DailyPivot *2 + weeklyPivot *2 + monthlyPivot *2 + average [5] + average [20] + average [50] + average [100] + average [200]) / 11Return c108/09/2018 at 9:58 PM #77905To write code, please use the <> “insert PRT code” button, to make code easier to read and understand. Thank you.
08/09/2018 at 10:09 PM #77906It’s because in line 6 you set
1Once lastWeekBarIndex = 1so in line 30 the expression
1Highest[BarIndex – lastWeekBarIndex]the first time will evaluate to
1Highest[0]which is not allowed.
1 user thanked author for this post.
08/10/2018 at 8:30 AM #77930Roberto is right, because the first barindex is 1 and obviously 1 minus 1 = 0.
You can modify your line 30 with:
1Highest[max(1,BarIndex – lastWeekBarIndex)]Do the same for lines 31, 47 and 48.
2 users thanked author for this post.
08/10/2018 at 10:35 PM #7799109/01/2018 at 5:12 PM #79527This is what the code looks like now12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273//Pivot calculation methodOnce mode = 1Once dailyPivot = 1Once lastWeekBarIndex = 1Once weeklyHigh = undefinedOnce weeklyLow = undefinedOnce weeklyPivot = undefinedOnce lastMonthBarIndex = 1Once monthlyHigh = undefinedOnce monthlyLow = undefinedOnce monthlyPivot = undefinedIf Day>Day[1] thenIf mode = 1 thendailyPivot = (DHigh(1) + DLow(1) + Close[1]) / 3Elsif mode = 1 thendailyPivot = (Open + DHigh(1) + DLow(1) + Close[1]) / 4Elsif mode = 2 thendailyPivot = (DHigh(1) + DLow(1) + Close[1]*2) / 4ElsedailyPivot = (Open*2 + DHigh(1) + DLow(1)) / 4EndifEndifIf DayOfWeek<DayOfWeek[1] thenweeklyHigh = Highest[max(1,BarIndex - lastWeekBarIndex)](High)[1]weeklyLow = Lowest[max(1,BarIndex - lastWeekBarIndex)](Low)[1]lastWeekBarIndex = BarIndexIf mode = 1 thenweeklyPivot = (weeklyHigh + weeklyLow + Close[1]) / 3Elsif mode = 1 thenweeklyPivot = (Open + weeklyHigh + weeklyLow + Close[1]) / 4Elsif mode = 2 thenweeklyPivot = (weeklyHigh + weeklyLow + Close[1]*2) / 4ElseweeklyPivot = (Open*2 + weeklyHigh + weeklyLow) / 4EndifEndifIf Month<>Month[1] thenmonthlyHigh = Highest[max(1,BarIndex - lastMonthBarIndex)](High)[1]monthlyLow = Lowest[max(1,BarIndex - lastMonthBarIndex)](Low)[1]lastMonthBarIndex = BarIndexIf mode = 1 thenmonthlyPivot = (monthlyHigh + monthlyLow + Close[1]) / 3Elsif mode = 1 thenmonthlyPivot = (Open + monthlyHigh + monthlyLow + Close[1]) / 4Elsif mode = 2 thenmonthlyPivot = (monthlyHigh + monthlyLow + Close[1]*2) / 4ElsemonthlyPivot = (Open*2 + monthlyHigh + monthlyLow) / 4EndifEndifc1= (DailyPivot *2 + weeklyPivot *2 + monthlyPivot *2 + average [5] + average [20] + average [50] + average [100] + average [200]) / 11return c109/01/2018 at 5:25 PM #79528I would like to create another version of this indicator for intraday timeframes. I would like to use a 10 minute chart and create the average price by combining moving average 5, 20, 50, 100, 200 and then combine that with hourly pivot, 4 hour pivot and daily pivot points.
Can anyone guide me in how to achieve this? Thanks again to Roberto Gozzi and Nicolas for helping out with the first version!
-
AuthorPosts
Find exclusive trading pro-tools on