Bizarre looping problem

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #105184 quote
    Grantx
    Participant
    Average

    This is bizarre. I basically want to get the average of the last x amount of bars.

    Even when I set the loop to 1 it doesnt calculate properly.

    Pseudo code should be something like this:

    1. Go back 10 bars and add up all the bar ranges
    2. Divide the total amount by the lookbackperiod when the loop has completed

     

    The calculations are completely incorrect. Im stuck as I cant see anything wrong with the code. Line 15 seems to be the problem but why?

    Note: I am running this on the m6e futures which is why I multiply by 10000

    //Grantx
    
    defparam drawonlastbaronly=true
    
    //--- settings
    Loockbackperiod = 10
    //--- end of settings
    
    RngeSum = 0
    largestBar = 0
    FOR i = 0 TO Loockbackperiod DO
    if (Range[i]>largestBar) THEN
    largestBar = Range[i]
    ENDIF
    RngeSum = RngeSum + Range[i]
    NEXT
    //RngeSum = Round((RngeSum / Loockbackperiod)*10000)
    RngeSum = Round(RngeSum*10000)
    largestBar = largestBar*10000
    
    drawtext("                                                                                            ABR(#Loockbackperiod#) = #RngeSum# ¬ LB = #largestBar#",barindex,High,Dialog,Standard,10) coloured(0,0,255)
    
    RETURN
    
    #105185 quote
    GraHal
    Participant
    New

    Does below (for Lines 9 and 10) make any difference?

    ONCE RngeSum = 0
    ONCE largestBar = 0
    Grantx thanked this post
    #105186 quote
    robertogozzi
    Moderator
    New

    You are summing up 11 bars (0 – 10), not 10.

    will

    LookBackPeriod = 10
    AverageRange   = summation[LookBackPeriod](range) / LookBackPeriod

    do?

    Grantx thanked this post
    #105188 quote
    Grantx
    Participant
    Average

    Yep. This works. Thank you!

    Also, thanks @GraHal for replying.

    Much appreciated.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Bizarre looping problem


ProBuilder support

New Reply
Author
author-avatar
Grantx @grantx Participant
Summary

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

Topic Details
Forum: ProBuilder support
Language: English
Started: 08/21/2019
Status: Active
Attachments: No files
Logo Logo
Loading...