PureBytes Links
Trading Reference Links
|
Brian, thank you for the very thorough response and examples.
I have included below a section of code which demonstrates the very different results computed using two different techniques.
One uses TimeFrameSet() and TimeFrameRestore().
The other uses TimeFrameCompress() and TimeFrameExpand().
Now matter how I setup the database market hours the time frame set/restore method gives inaccurate results, as compared to values calculated manually in an excel spread sheet.
The time frame compress/expand is the only method I've found which produces accurate results. However, when you have to call these functions dozens of times in a AFL code it drastically slows the processing time of backtests and optimizations.
It is a multi-stage process. First determine values during market hours, then compress the result into daily time frame. Once in the daily time frame it is now possible to perform operations involving multiple days, like calculating moving averages. Once the values are calculated you must then expand the variable before it can be used in the intra-day time frame.
This is the reason I am searching for a better solution. If I could nest all of my calculations within a single time frame set/restore statement I could drastically reduce processing time.
If someone has a solution to this I would be very grateful to know it.
Thanks.
Pete :-)
_Section_Begin("Time Frame Test");
MrktOpn = TimeNum() == 093000;
MrktCls = TimeNum() == 160000;
TimeBar = TimeNum() >= 160000;
TimeBar2 = TimeNum() < 160000;
EOSTimeBar = TimeBar == 1 AND Ref(Timebar2,-1) == 1;
//the only way I've found to calculate the true difference
//between daily H and L which are only taken during market hours
DlyHighest = HighestSince(MrktOpn , H);
HighAtClose = ValueWhen(EOSTimeBar , Ref(DlyHighest,-1));
DlyLowest = LowestSince(MrktOpn , L);
LowAtClose = ValueWhen(EOSTimeBar , Ref(DlyLowest,-1));
TRUE_DlyDiff = HighAtClose - LowAtClose ;
//then it needs to be compressed before using it to calculate
//a daily moving average of the difference between H and L
tfc_DlyDiff = TimeFrameCompress(TRUE_DlyDiff, inDaily, compressLast);
TRUE_DlyMA = MA(tfc_DlyDiff,10);
//then it gets expanded for use in Ploting to other method of
//display
tfeDlyMA = TimeFrameExpand(TRUE_DlyMA,inDaily);
//What I would prefer to use is the timeframeset, use it once
//and perform various calcluations like the one above and have
//it accurately produce results. If you check the values calculated
//using the timeframeset section below against values manually
//calculated in a spread sheet you will see they are including
//data from outside of market trading hours.
TimeFrameSet(inDaily);
FALSE_DlyDiff = H-L;
FALSE_DlyMA = MA(HighAtClose - LowAtClose, 10);
/*
it does not work no matter what you try here:
FALSE_DlyMA = MA(H - L, 10);
FALSE_DlyMA = MA(FALSE_DlyDiff, 10);
*/
TimeFrameRestore(inDaily);
//plot to compare false results to true.
Plot(TimeFrameExpand(FALSE_DlyDiff,inDaily), "FALSE Daily Diff", colorBlue, styleDashed);
Plot(TRUE_DlyDiff, "TRUE Daily Diff", colorBlack, styleDots);
Plot(TimeFrameExpand(FALSE_DlyMA,inDaily), "FALSE Dly MA", colorRed, styleDashed);
Plot(tfeDlyMA , "TRUE Dly MA", colorRed, styleLine);
_Section_End();
------------------------------------
**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.
TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com
TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/amibroker/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:amibroker-digest@xxxxxxxxxxxxxxx
mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx
<*> To unsubscribe from this group, send an email to:
amibroker-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|