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?
Your code is fine. This is obviously an error in the data stream. Was this on an demo account?
Try replacing line 8 with:
IF BodyPerc < 75 THEN
Sorry for not being able to insert PRT code from My smartphone.
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!
AVTParticipant
Senior
just a quick idea: abs(high-low)
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.
High-Low cannot be negative, so using ABS() would not affect the outcome.
AVTParticipant
Senior
Damned guys, you’re right !! – already too late in the evening
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…
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.
I think you should report this to PRT. If you write a ticket directly via the platform you can even select data-errors.
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.