I am noticing some strange behaviour in my coding.
I try to calculate the 20 period atr value of a list off 28 forex symbols from a higher timeframe.
The strange thing is, it is caluated correctly only for 10 symbols, the other 18 symbols get really high values.
This is the code i use, it is run on a 5 minute chart:
I have checked the realtime quote window and all quotes for all forex symbols are there.
I really don't get it why only 10 symbols are calculated correctly and the other 18 symbols give strange high values ( around 29 million).
I use Amibroker Pro 6.20.1 64 bit version.
Hope you could shed some light and point me in the right direction.
Thanks for your reaction.
As i read in the bottom of the link you send:
TimeFrameRestore and RestorePriceArrays
is essentially the same function. So please note that calling RestorePriceArrays also resets the time interval set by eventual previous call to TimeFrameSet
Sorry, you are right about that, i tried to be complete but i guess there was some info missing.
I have to get out now, but will be back soon and comment on the second part.
Also, having holes or having unaligned timestamps at times will cause unexpected behaviour behaviour.
Are you sure that all symbols are aligned correctly ?
Can You post a TRACE() for the last few bars of the base symbol and the Foreign one where you have problems.
Run it from a loop with / without TimeFrameSet().
For eg. If the Foreign symbol has future data relative to the base symbol, its a problem.
Are all the symbols from the same Market timings ?
Now you can see that it itterates through a watchlist off tickers.
Each [n] is another ticker, that's why i coded atr20[n] = ...
How to pass this to a function that expects an array is a good question.
Maybe it cannot, i'm not sure, I thought it would fill the array with all equal numbers (lastvalue(atr(20))).
If i did like you then how would i store the values for each ticker? use staticvars?
If you run codes like this from indicator (you are not saying that so guessing games here)
you must have data cache large enough to keep those 28 symbols (Tools->Preferences->Data). Also when compressing from 5 minute to daily you need at least 5760 (24 * 60 / 5 ) 5-minute bars to get 20 days worth of data required for ATR. So you might need to make sure that BarCount is actually higher, otherwise you won't be able to calculate ATR. Again, you should debug your formula as explained here: How do I debug my formula?
It is your code and your data. No one can debug your setup except yourself.
I know, the code has some weird stuff in it, i'm not a professional coder so all this is a lot off trail and error really.
I've got rid off the lastvalue errors, and trying hard to understand why I see these traces my code is producing.
Right now i don't get it, that's why i reached out to this forum, maybe somebody could point me in the right direction.
I've checked the data cache it says: 10000 max. symbols, 4096 max. MB and no limit on saved quotations.
Looks ok to me.
Also barcount exceeds 25000 5-minute bars on all symbols, should be ok too.
Offcourse I know that I need to do the debugging and i'm trying to do that, but on this one i'm a bit stuck.
I think i've reached the ceiling of my programming/analyzing skills .
If there are no further ideas what to do or to test i'll leave it here and stop developing this idea, that is no problem.
As explained in linked document, get the insight into what your formula is doing by displaying intermediate values, for example, put _TRACE or debug breakpoint on line
....
atr20 = ATR( 20 ); // put breakpoint in debugger or...
_TRACE("atr20 for " + Name() + " is " + LastValue( atr20 ) + "\n");
...
and use Watch window (or Log window) to see the values in atr20 variable (prior to any subsequent transformations)
In quote editor (Menu bar -> Symbol -> Quote Editor) check whether some of your symbols (resulting in millions values of ATR) have invalid DateTime entries with OHLC zero. (Me thinks you are using DDE plugin)
See example picture below
Delete those ones if they are there
If having some of those symbols in your watchlist being iterated then you would get exactly that.... million values in ATR.