Help with coding average price based on pivots and moving averages

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #77903 quote
    skfomx
    Participant
    Average

    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!

    #77904 quote
    skfomx
    Participant
    Average

    This is the code:

    //Pivot calculation method
    Once mode = 1
    
    Once dailyPivot = 1
    
    Once lastWeekBarIndex = 1
    Once weeklyHigh = undefined
    Once weeklyLow = undefined
    Once weeklyPivot = undefined
    
    Once lastMonthBarIndex = 0
    Once monthlyHigh = undefined
    Once monthlyLow = undefined
    Once monthlyPivot = undefined
    
    If Day>Day[1] then
    If mode = 1 then
    dailyPivot = (DHigh(1) + DLow(1) + Close[1]) / 3
    Elsif mode = 1 then
    dailyPivot = (Open + DHigh(1) + DLow(1) + Close[1]) / 4
    Elsif mode = 2 then
    dailyPivot = (DHigh(1) + DLow(1) + Close[1]*2) / 4
    Else
    dailyPivot = (Open*2 + DHigh(1) + DLow(1)) / 4
    Endif
    
    Endif
    
    If DayOfWeek<DayOfWeek[1] then
    weeklyHigh = Highest[BarIndex – lastWeekBarIndex](High)[1]
    weeklyLow = Lowest[BarIndex – lastWeekBarIndex](Low)[1]
    lastWeekBarIndex = BarIndex
    
    If mode = 1 then
    weeklyPivot = (weeklyHigh + weeklyLow + Close[1]) / 3
    Elsif mode = 1 then
    weeklyPivot = (Open + weeklyHigh + weeklyLow + Close[1]) / 4
    Elsif mode = 2 then
    weeklyPivot = (weeklyHigh + weeklyLow + Close[1]*2) / 4
    Else
    weeklyPivot = (Open*2 + weeklyHigh + weeklyLow) / 4
    Endif
    
    Endif
    
    If Month<>Month[1] then
    monthlyHigh = Highest[BarIndex – lastMonthBarIndex](High)[1]
    monthlyLow = Lowest[BarIndex – lastMonthBarIndex](Low)[1]
    lastMonthBarIndex = BarIndex
    
    If mode = 1 then
    monthlyPivot = (monthlyHigh + monthlyLow + Close[1]) / 3
    Elsif mode = 1 then
    monthlyPivot = (Open + monthlyHigh + monthlyLow + Close[1]) / 4
    Elsif mode = 2 then
    monthlyPivot = (monthlyHigh + monthlyLow + Close[1]*2) / 4
    Else
    monthlyPivot = (Open*2 + monthlyHigh + monthlyLow) / 4
    Endif
    
    Endif
    
    c1= (DailyPivot *2 + weeklyPivot *2 + monthlyPivot *2 + average [5] + average [20] + average [50] + average [100] + average [200]) / 11
    
    Return c1

     

     

    #77905 quote
    robertogozzi
    Moderator
    Master

    To write code, please use the <> “insert PRT code” button, to make code easier to read and understand. Thank you.

    #77906 quote
    robertogozzi
    Moderator
    Master

    It’s because in line 6 you set

    Once lastWeekBarIndex = 1

    so in line 30 the expression

    Highest[BarIndex – lastWeekBarIndex]

    the first time will evaluate to

    Highest[0]

    which is not allowed.

     

     

     

     

    skfomx thanked this post
    #77930 quote
    Nicolas
    Keymaster
    Master

    Roberto is right, because the first barindex is 1 and obviously 1 minus 1 = 0.

    You can modify your line 30 with: 

    Highest[max(1,BarIndex – lastWeekBarIndex)]

    Do the same for lines 31, 47 and 48.

    robertogozzi and skfomx thanked this post
    #77991 quote
    skfomx
    Participant
    Average
    Thanks a lot for taking the time to help out!
    #79527 quote
    skfomx
    Participant
    Average
    //Pivot calculation method
    Once mode = 1
    
    Once dailyPivot = 1
    
    
    Once lastWeekBarIndex = 1
    Once weeklyHigh = undefined
    Once weeklyLow = undefined
    Once weeklyPivot = undefined
    
    
    
    Once lastMonthBarIndex = 1
    Once monthlyHigh = undefined
    Once monthlyLow = undefined
    Once monthlyPivot = undefined
    
    
    
    If Day>Day[1] then
    If mode = 1 then
    dailyPivot = (DHigh(1) + DLow(1) + Close[1]) / 3
    Elsif mode = 1 then
    dailyPivot = (Open + DHigh(1) + DLow(1) + Close[1]) / 4
    Elsif mode = 2 then
    dailyPivot = (DHigh(1) + DLow(1) + Close[1]*2) / 4
    Else
    dailyPivot = (Open*2 + DHigh(1) + DLow(1)) / 4
    Endif
    
    
    Endif
    
    If DayOfWeek<DayOfWeek[1] then
    weeklyHigh = Highest[max(1,BarIndex - lastWeekBarIndex)](High)[1]
    weeklyLow = Lowest[max(1,BarIndex - lastWeekBarIndex)](Low)[1]
    lastWeekBarIndex = BarIndex
    
    If mode = 1 then
    weeklyPivot = (weeklyHigh + weeklyLow + Close[1]) / 3
    Elsif mode = 1 then
    weeklyPivot = (Open + weeklyHigh + weeklyLow + Close[1]) / 4
    Elsif mode = 2 then
    weeklyPivot = (weeklyHigh + weeklyLow + Close[1]*2) / 4
    Else
    weeklyPivot = (Open*2 + weeklyHigh + weeklyLow) / 4
    Endif
    
    
    Endif
    
    If Month<>Month[1] then
    monthlyHigh = Highest[max(1,BarIndex - lastMonthBarIndex)](High)[1]
    monthlyLow = Lowest[max(1,BarIndex - lastMonthBarIndex)](Low)[1]
    lastMonthBarIndex = BarIndex
    
    If mode = 1 then
    monthlyPivot = (monthlyHigh + monthlyLow + Close[1]) / 3
    Elsif mode = 1 then
    monthlyPivot = (Open + monthlyHigh + monthlyLow + Close[1]) / 4
    Elsif mode = 2 then
    monthlyPivot = (monthlyHigh + monthlyLow + Close[1]*2) / 4
    Else
    monthlyPivot = (Open*2 + monthlyHigh + monthlyLow) / 4
    Endif
    
    Endif
    
    c1= (DailyPivot *2 + weeklyPivot *2 + monthlyPivot *2 + average [5] + average [20] + average [50] + average [100] + average [200]) / 11
    
    
    return c1
    
    #79528 quote
    skfomx
    Participant
    Average
    I 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!
Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.

Help with coding average price based on pivots and moving averages


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
skfomx @skfomx Participant
Summary

This topic contains 7 replies,
has 3 voices, and was last updated by skfomx
7 years, 5 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 08/09/2018
Status: Active
Attachments: No files
Logo Logo
Loading...