Hi again,

I've searched thru the manual and I think that += is simply a shortcut.  I
wrote total = total+ raw[i];  instead and there is no more error!

I did exactly as you said and got the sign with those huge bars all topping
at 0.267615.  I think I understand what you say, but what is OI?

The thing is: I am not sure how to use this.  I think what I need is to make
an average of all this data and then subtract this average from each day log
of the actual stock to detrend.  Am I correct?  Would you be kind enough to
give me some tips about how to use this new information to actually backtest
one of my rules and see how it performs when it is detrended?

Thanks a lot!

Louis

2008/3/2, Louis Préfontaine <[EMAIL PROTECTED]>:
>
> Hi Mike,
>
> Thank you so much for your reply!
>
> This is EXACTLY what I am looking for, from the Aronson's book!
>
> I can't wait to make it work... Right now there is a small problem with
> the formula...  I get an error message for this parti total += raw[i];   Ln12:
> col:8:Error 30. Syntax error.
>
> I tried to change the += for = or == and it works...  Is it possible that
> the AB version that I have doesn't recognize the +=?  Or maybe there is an
> error with the +=?  Is it possible to get to the same result in any other
> way?
>
> Thanks a lot!
>
> Louis
>
> 2008/3/2, Mike <[EMAIL PROTECTED]>:
> >
> >   Hi,
> >
> > Based on your formula, I assume that you are referring to Chapter 1
> > of David Aronson's book: Evidence Based Technical Analysis.
> >
> > That being the case, I am providing a script below.
> >
> > However, I believe that the formula that you originally posted is not
> > correct. Aronson's formula calls for multiplying your boolean
> > strategy signal (i.e. +1 for long vs. -1 for short) by the detrended
> > daily returns, *not* the Close by the returns!
> >
> > Also, the book does not go into detail for tri-state strategies (i.e.
> > long/neutral/short) nor for long/neutral or short/neutral strategies.
> > I'm assuming that plugging in a signal value of 0 would be acceptable
> > for a neutral position, but haven't researched that yet. So, just be
> > careful how you use the data once you've detrended it.
> >
> > Anyway, here is a script that I believe will detrend the market
> > returns as per the book. Currently, the script is intended for
> > detrending a single symbol. I have not yet got around to making it
> > work against a watchlist of symbols (coming soon).
> >
> > 1. Copy paste the script below to a file on your machine (say
> > c:\Program Files\AmiBroker\Formulas\Custom\Detrend.afl). Make sure
> > that you correct any formatting that gets messed up from this post,
> > such that AmiBroker likes everything. Use the Tools | Verify Syntax
> > menu from the code editor.
> >
> > 2. Open a chart on the symbol that you want to detrend. For example;
> > Aronson used the SP-500 for all his tests.
> >
> > 3. Open the Automatic Analysis Window
> >
> > 4. Click the "Pick" button and select the script that you just saved
> > (i.e. Detrend.afl).
> >
> > 5. Select "current symbol" for the Apply To.
> >
> > 6. Select "from" for the Range, and enter a from date and a to date
> > (e.g. from 1/1/2007 to 12/31/2007).
> >
> > 7. Click on Backtest
> >
> > A new symbol will be added to your system having the same name as the
> > original, but prefixed with a "~", for example "~SP-500". This symbol
> > will appear in Market 253 and contain detrended market information
> > for the range selected (e.g. all of 2007 as above) and zeros for all
> > other dates.
> >
> > For each bar in the detrended symbol, the information will be
> > arranged as follows:
> >
> > Open: The unadjusted log daily return (i.e. log(Open2/Open1)).
> >
> > High: The total sum of all unadjusted log daily returns.
> >
> > Low: The average of all unadjusted log daily returns (i.e. ALR).
> >
> > Close: The detrended log daily return (i.e. log(Open2/Open1) - ALR).
> >
> > OI: The number of bars over which the data has been detrended.
> >
> > Note: As per Aronson, Open2 refers to the Open two days from now,
> > Open1 refers to the Open one day from now, ALR refers to the average
> > log return over the period being detrended.
> >
> > Note: I have used the natural logarithm in my code (i.e. ln), as
> > opposed to the base 10 logarithm (i.e. log10). I don't know if that
> > makes a difference.
> >
> > Note: To find your detrended strategy results, you still must write
> > your own code to calculate which of the detrended daily returns your
> > strategy would pick up, and which sign to use (+/-) when multiplying
> > by the detrended return for that day.
> >
> > Note: I ran this script against SP-500 for the entire year of 2007.
> > With my data source, the average detrended log daily return (i.e. all
> > the Close values of ~SP-500 divided by 251 actual trading days) ended
> > up being -6.00797E-10 which is effectively zero. So, I'm assuming
> > that it works.
> >
> > Corrections and enhancements welcomed :)
> >
> > Mike
> >
> > procedure Detrend(compositeName) {
> > local range; range = Status("barinrange");
> > local raw; raw = log(Ref(Open, 2)/Ref(Open, 1));
> > local total; total = 0;
> > local count; count = 0;
> > local offset; offset = 0;
> >
> > for (i = 0; i < BarCount; i++) {
> > if (range[i]) {
> > if (NOT IsNull(raw[i])) {
> > count++;
> > total += raw[i];
> > }
> > }
> > }
> >
> > if (count > 0) {
> > AddToComposite(IIF(range, raw, Null), "~" + compositeName, "O",
> > atcFlagDefaults | atcFlagEnableInBackTest);
> >
> > offset = total/count;
> > raw = IIF(IsNull(raw), offset, raw);
> >
> > AddToComposite(IIF(range, raw - offset, Null), "~" +
> > compositeName, "C", atcFlagDefaults | atcFlagEnableInBackTest);
> > AddToComposite(IIF(range, total, Null), "~" + compositeName, "H",
> > atcFlagDefaults | atcFlagEnableInBackTest);
> > AddToComposite(IIF(range, offset, Null), "~" +
> > compositeName, "L", atcFlagDefaults | atcFlagEnableInBackTest);
> > AddToComposite(IIF(range, count, Null), "~" + compositeName, "I",
> > atcFlagDefaults | atcFlagEnableInBackTest);
> > } else {
> > AddToComposite(Null, "~" + compositeName, "X", atcFlagDefaults |
> > atcFlagEnableInBackTest);
> > }
> > }
> >
> > Buy = Sell = Short = Cover = 0;
> > Detrend(Name());
> >
> > --- In [email protected] <amibroker%40yahoogroups.com>,
> > "louisprefontaine" <[EMAIL PROTECTED]>
> > wrote:
> > >
> > > Anybody can help?
> > >
> > > Thanks,
> > >
> > > Louis
> > >
> > > --- In [email protected] <amibroker%40yahoogroups.com>, "Louis
> > Préfontaine" <rockprog80@>
> > > wrote:
> > > >
> > > > I am trying to build a formula to "detrend" the market.
> > > >
> > > > What I want to set is something like this
> > > >
> > > > Close of day 0 * ( log (open day2/open day 1) - average log
> > > return of
> > > > every day of the data available.
> > > >
> > > > Anybody can do that?
> > > >
> > > > Thanks,
> > > >
> > > > Louis
> > > >
> > >
> >
> >  
> >
>
>

Reply via email to