[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] TimeFrame Problem



PureBytes Links

Trading Reference Links

Hi Ocean --

Here is an afl program that begins with daily data, and plots both daily and weekly data.  It is easy (for me at least) to get confused and omit one of the necessary TimeFrameExpand commands and not get the alignment I was planning.

//    TimeFrameWeekly.afl
//
//    This is not a good trading system.
//    Its purpose is to illustrate the use
//    of TimeFrameSet, TimeFrameExpand, and
//    TimeFrameRestore.
//
//    The time frame modification features of AmiBroker
//    are very powerful, but it is easy to overlook
//    a necessary conversion and get incorrect results.
//
SetTradeDelays(0,0,0,0);
BuyPrice = C;
SellPrice = C;

//    Start out working with daily data, as is normal
//
//    Compute the Position In Range indicator on daily data.
//    If the term stochastic had not been coined first,
//    what is now called the stochastic oscillator might
//    be called the PositionInRange indicator.
//    PIR is an unsmoothed stochastic.
//
//    In pseudo-code, PIR = (C-LLV)/(HHV-LLV);
//
//    Set the lookback length for the daily indicator
//    As usual, this could be a Param or Optimize statement
DailyLB = 20;

//    Compute the PIR using Daily data
PIRDaily = (C - LLV(C,DailyLB))
        / (HHV(C,DailyLB) - LLV(C,DailyLB));
//    Plot the Daily PIR
Plot(PIRDaily, "PIRDaily", colorRed,styleLine);

//    Switch to weekly data
TimeFrameSet(inWeekly);

//    C is now the Weekly Close
//    As are O, H, L, V, OI
//    There are only one-fifth as many data points
//    for the weekly data, and they are stored in
//    the data arrays near the "current date" end.
//
//    Set the lookback length for the weekly indicator
//    This can also be an Optimize statement
WeeklyLB = 5;

//    Compute the PIR using Weekly data
PIRWeekly = (C - LLV(C,WeeklyLB)) / (HHV(C, WeeklyLB) - LLV(C,WeeklyLB));

//    Plot the Weekly PIR
//    If the "TimeFrameExpand" is omitted from the plot command,
//    there will be a blue line at the current end of the chart,
//    but it will not extend all the way to the left.
Plot(TimeFrameExpand(PIRWeekly,inWeekly),
            "PIRWeekly", colorBlue, styleLine);

//    Switch back to daily data
TimeFrameRestore();

//    Set the levels at which signals are triggered.
WeeklyLevel = 0.10;
DailyLevel = 0.15;

//    Check for signals
//    If the "TimeFrameExpand" is omitted from this line,
//    the PIRWeekly data will be concentrated at the current end
//    of the chart, and the dates will be misaligned.
//    Signals will be generated, but since they are using
//    misaligned data, they are wrong.
Buy = (TimeFrameExpand(PIRWeekly,inWeekly) <= WeeklyLevel)
            AND (Ref(PIRDaily,-1) <= DailyLevel)
            AND (PIRDaily>Ref(PIRDaily,-1));
Sell = BarsSince(Buy) >=3;

//    To see what is happening, remove one or more of
//    the "TimeFrameExpand" from the lines above,
//    and look at the data produced by the
//    Exploration that follows.
Filter = 1;
AddColumn(C,"C",1.4);
AddColumn(PIRDaily,"PIRDaily",1.4);
AddColumn(TimeFrameExpand(PIRWeekly, inWeekly),"PIRWeekly", 1.4);
//Figure 17.5 Time Frame Weekly

Thanks,
Howard
www.quantitativetradingsystems.com


On 9/22/07, oceanchimes <oceanchimes@xxxxxxxxx> wrote:

Hi All,
This is causing me a real headache.
The plot of weekly and/or daily data doesn't align. I'm at a loss.
Suggestions most welcome. Here is the code.
I want to plot any symbol and see the weekly and/or daily plot. First,
I get the weekly variable, then expand to obtain the daily. Finally I
plot the sybol itself. The symbol and weekly plots are exactly the
same whether timeframe weekly or daily!!!! More confusing, the
expanded plot,....well no idea really as it isn't related at all. I
must be coding incorrectly. Comments please. New remarks/banter
welcome. Many thanks.

TimeFrameSet(inWeekly);
wTik = Foreign("XAO", "C");
TimeFrameRestore();

TimeFrameSet(inDaily);
Tik = TimeFrameExpand(wTik,inWeekly,expandLast);

if (Status("action") == actionIndicator )
{
GraphXSpace = 10;
BackGround = ""> Plot(Close,"CLOSE",colorWhite,styleBar);
Plot(wTik,"wTik",colorBlue,styleDots|styleLine|styleThick);
Plot(Tik,"Tik",colorSeaGreen,styleLine);
} // End actionIndicator
TimeFramerestore();


__._,_.___

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html




Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___