Wrong Percentage Calculation

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #50153 quote
    Vonasi
    Moderator
    Master
    BodyPerc = ((ABS(close - open))/(High-Low))*100
    
    IF BodyPerc <= 25 THEN
    R = 255
    G = 0
    B = 0
    ELSE
    IF BodyPerc > 25 and BodyPerc < 75 THEN
    R = 0
    G = 0
    B = 255
    ELSE
    R = 0
    G = 255
    B = 0
    ENDIF
    ENDIF
    
    
    Return BodyPerc coloured (R,G,B) Style(Histogram,2) as "Body Percentage"
    

    I wrote a simple indicator to show what percentage the body of a candle is compared to the total range but I’m getting some rogue percentages as the data for some candle is showing their range to be smaller than the candle body – which is impossible. Why is this?

    #50159 quote
    Despair
    Blocked
    Master

    Your code is fine. This is obviously an error in the data stream. Was this on an demo account?

    #50160 quote
    robertogozzi
    Moderator
    Master

    Try replacing line 8 with:

    IF BodyPerc < 75 THEN

    Sorry for not being able to insert PRT code from My smartphone.

    #50162 quote
    Vonasi
    Moderator
    Master

    Despair – No this was a live account – I gave up on demo account data a long time ago!

    RobertoGozzi – Line 8 is just about colour choice and nothing to do with the calculation.

    The screenshot shows the fault in the high low close and open values that lead to the bad calculation. There are several of these over the years. Makes coding a strategy a little difficult if the data stream is rubbish!

    #50170 quote
    AVT
    Participant
    Senior

    just a quick idea: abs(high-low)

    #50171 quote
    Vonasi
    Moderator
    Master

    Thanks for the suggestion AVT but a high will always be higher than a low so the result will always be a positive from (high-low). The fault is in the data supplied from IG/PRT as if you check the numbers in the cursor details panel shown in the image the range is smaller than the body of the candle, which is impossible.

    AVT thanked this post
    #50172 quote
    robertogozzi
    Moderator
    Master

    High-Low cannot be negative, so using ABS() would not affect the outcome.

    AVT thanked this post
    #50174 quote
    AVT
    Participant
    Senior

    Damned guys, you’re right !! – already too late in the evening

    #50175 quote
    JC_Bywan
    Moderator
    Master

    Are the wrong ones you found only sundays like the one in your attached graph? If yes, at least it would be contained to the usual sunday night data issue, rather than affecting normal week days… If no it might be worth graphing the day close in smaller timeframe and check for the instrument you look at where actual day close is relative to midnight, problem being with 24h dataflow that open and close might not be sctritly “on the same day” and generate weird stuff if high and low are on the same day…

    #50183 quote
    Vonasi
    Moderator
    Master

    No they are not all Sundays. Screenshot attached of a particularly bad period in 2003. Not sure how that data could be used for making decisions on when to trade if you can’t trust the basic data of high, low and open,close to be correct.

    #50194 quote
    Despair
    Blocked
    Master

    I think you should report this to PRT. If you write a ticket directly via the platform you can even select data-errors.

    #50210 quote
    Vonasi
    Moderator
    Master

    Report sent.

    Despair thanked this post
    #50254 quote
    robertogozzi
    Moderator
    Master

    I run it on DAX 1-hour TF and everything worked fine, but not as fine when I run it on a Daily and 4-hour TF, so I think the problem is the one Noobywan talked about, that is candles across the end of the day.

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

Wrong Percentage Calculation


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Vonasi @vonasi Moderator
Summary

This topic contains 12 replies,
has 5 voices, and was last updated by robertogozzi
8 years, 3 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 10/21/2017
Status: Active
Attachments: 2 files
Logo Logo
Loading...