Exponential Average of Candle Value Intermittently Flat Lines

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #170079 quote
    Nelson
    Participant
    New

    I am trying to code a very simple exponential average (60) of a calculated candle value, it sometimes stops calculating and flatlines which is strange. There has to be an error in my code as the candle value still calculates. To see it better I have scaled the values up

    Does anyone have any idea as to why this is happening I have tried a few things to no success.

    //Flow
    
    // Works out the candle value and to see result is scaled up by * 200
    
    //Zero Line
    DRAWHLINE(0)coloured(0,0,0)
    
    CandleValue = (close - open) / (high - low)
    CV = CandleValue * 200
    
    // Exponential average of scaled up Candle Value and this is scaled up * 50 to see result
    MVC = Average[60,1](CV)
    MVC1 = MVC * 50
    
    Return MVC1 as "MVC", CandleValue as "CV", CV as "Scale Up CV", 0 as "0"
    Flats-on-Exponential-Calculation.jpg Flats-on-Exponential-Calculation.jpg
    #170090 quote
    robertogozzi
    Moderator
    Master

    It’s quite weird, I tested it on DAX, different TF’s, even replacing AVERAGE with EXPONENTIALAVERAGE, but it still plots flat lines almost everyday.

    It occurs mainly on Indices (Dax, Ftse, Nikkei, Cac40, Russel, Nasdaq, S&P500 and Dow Jones ). As to FX pairs I experienced the same issue on NZD/CHF, GBP/CAD and GBP/CHF (I did only test it on about 15 pairs).

    I have no idea why.

    I suggest that you open a ticket for assistamce (press Ctrl+M from the platform).

    #170107 quote
    Nelson
    Participant
    New

    Yeah same Robertogozzi I also tried EXPONENTIALAVERAGE and same issue I shall raise a ticket and update with the feedback. Thanks for looking into this

    #170108 quote
    JC_Bywan
    Moderator
    Master

    You divide by (high-low) in line 8, which creates undefined values when high=low because of division by 0, and propagates the undefined through the averages. You can try to surround your line 8 by “if high<>low then … endif” and see if it achieves what you expect.

    robertogozzi and Nelson thanked this post
    #170123 quote
    robertogozzi
    Moderator
    Master

    Well spotted Noobywan!

    You can replace line 8 with this one:

    CandleValue = (close - open) / max(0.00001,(high - low))
    #170124 quote
    robertogozzi
    Moderator
    Master

    Maybe this a better solution, replace lines 8-9 with:

    IF (high - low) >0 THEN
       CandleValue = (close - open) / (high - low)
       CV = CandleValue * 200
    ENDIF
    Nelson thanked this post
    #170160 quote
    Nelson
    Participant
    New

    Great spot Noobywan, Robertogozzi that last code works great as expected thanks guys.

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

Exponential Average of Candle Value Intermittently Flat Lines


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Nelson @nelson Participant
Summary

This topic contains 6 replies,
has 3 voices, and was last updated by Nelson
4 years, 8 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 05/21/2021
Status: Active
Attachments: 1 files
Logo Logo
Loading...