Average in indicator returns flat spots

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #123156 quote
    Vonasi
    Moderator
    Master

    This simple indicator that just calculates an average of the closing position as a percentage of range returns flat spots on the indicator where the average is clearly not being calculated correctly and the value does not change over many candles.

    The attached images are of DJI daily.

    p = 3
    
    closeperc = ((close-low)/(high-low))*100
    avg = average[p,1](closeperc)
    
    return avg
    Screenshot_3-3.png Screenshot_3-3.png Screenshot_4-2.png Screenshot_4-2.png
    #123167 quote
    Nicolas
    Keymaster
    Master

    Congratulations for being able to successfully recode a stochastic from scratch! 😆 (no offense)

    sto = Stochastic[1,1]
    avg = average[p,1](sto)

    EDIT: topic is not in the right section! 😉

    #123171 quote
    robertogozzi
    Moderator
    Master

    Vonasi, you’ll have to move it yourself to the correct support forum!

    #123180 quote
    Vonasi
    Moderator
    Master

    Congratulations for being able to successfully recode a stochastic from scratch!

    I actually hadn’t twigged that it was the same calculation!

    Interestingly if you put the two calculations on in the same indicator the stochastic one calculates just fine but my version doesn’t.

    p = 3
    
    closeperc = ((close-low)/(high-low))*100
    avg = average[p,1](closeperc)
    
    sto = Stochastic[1,1]
    avg2 = average[p,1](sto)
    
    return avg,avg2
    

    I actually think this is the right place for this topic as it is clearly a data or calculation error which is a platform issue.

    Screenshot_5.png Screenshot_5.png
    #123182 quote
    Vonasi
    Moderator
    Master

    I’ve done a little more testing and the variable closeperc calculates correctly. The issue is with the exponential average calculation. If I use a simple average then it calculates correctly.

    GraHal thanked this post
    #123184 quote
    GraHal
    Participant
    Master

    More worrying revelations?

    #123185 quote
    robertogozzi
    Moderator
    Master

    Your code works fine for me, both lines overlap.

    #123189 quote
    Vonasi
    Moderator
    Master

    Your code works fine for me, both lines overlap.

    Really? That is very odd. On the DJI daily?

    I feel a switch it off and back on again happening if so.

    #123192 quote
    robertogozzi
    Moderator
    Master

    DAX Daily.

    x-5.jpg x-5.jpg
    #123196 quote
    Vonasi
    Moderator
    Master

    Dow Jones not DAX

    #123203 quote
    robertogozzi
    Moderator
    Master

    DJI daily.

    The one below is your original code.

    The one above is this one (with modifications to avoid division by 0):

    p = 3
    x = max(pipsize,range)
    //closeperc = ((close-low)/(high-low))*100
    closeperc = ((close-low)/x)*100
    avg = average[p,1](closeperc)
     
    sto = Stochastic[1,1]
    avg2 = average[p,1](sto)
    return avg AS "Avg",avg2 AS "Stoch"

    Apart from a few candles, both blue and red lines overlap.

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

Average in indicator returns flat spots


Platform Support: Charts, Data & Broker Setup

New Reply
Author
author-avatar
Vonasi @vonasi Moderator
Summary

This topic contains 10 replies,
has 4 voices, and was last updated by robertogozzi
5 years, 11 months ago.

Topic Details
Forum: Platform Support: Charts, Data & Broker Setup
Language: English
Started: 03/24/2020
Status: Active
Attachments: 5 files
Logo Logo
Loading...