I have a strange problem. I want my condition to be true if a moving average goes flat (sideways). So i have something like:
once i=0
if ema=ema[1] then
i=i+1
endif
graph ema as "ema"
graph ema[1] as "ema[1]"
graph i as "i"
When i run the code the condition obviously never comes true since i remains zero all the time. Anyway when i look at the graphed variables the backtest shows many periods when ema=ema[1]. How can this be? Is that maybe that PRT intern calculates the emas with more than 5 digits and then cuts off the last digits when graphing them? This way there is a tiny difference between ema and ema[1] though graph shows the same value for them?
This takes me to the question, with how many digits behind the comma is PRT calculating?
Obviously there is a problem with hidden digits. PRT shows 5 digits but internally it must calculate with more digits. Does anybody know with how many?
Which TF did you use?
I your assumption might be possible for very low TF’s, say 1 minute or lower, I think it would be extremely odd to have EMA’s matching the first 5 digits in a, say, 4-hour TF!
I was using 5 minute TF. And it is definitely th case with some hidden digits. When you graph the variables it comes back sometimes as “0” and sometimes as “-0.00” so obviously there is something going on one doesnt see (again!).
I had to modify your code as follows to be executed:
once i=0
ema = average[20]
if ema=ema[1] then
i=i+1
endif
if i < 0 then
buy 1 contract at market //useless condition just to add a BUY order
endif
graph ema as "ema"
graph ema[1] as "ema[1]"
graph i as "i"
I run it on DAX 5-min TF and it was executed regularly, I found a match on Friday July 7th at 09:35 (gmt +2), as from the picture.
Variable i was set at 11, so there must have been 10 matches before.
Prices seem regular with the full 5 digits + 5 decimal digits.