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

Re: [amibroker] Re: How do make this formula self adjust for entire data history?



PureBytes Links

Trading Reference Links

What is it you are actually trying to do in your exploration?

If you are only interested in the right-most point of the line, you can get 
that using LinearReg().

If you want a whole series of linear regression lines that overlap when 
plotted then the number of arrays
you would need would, at a minimum, equal PeriodsBack.  Not very practical.

You could recalculate every periodsback bars and come up with something you 
could plot in a single
array this way:

PeriodsBack = Param("PeriodsBack", 96, 53, 200, 2);
Lri=LinRegIntercept( Close , PeriodsBack );
Lrs=LinRegSlope( Close, PeriodsBack );
LRegLine=0;

for ( i = periodsback ; i < BarCount ; i++ ) {
    if ( i % periodsback == 0 || i == BarCount - 1 ) {
        aa = Lri[i];
        bb = Lrs[i];
        if ( i % periodsback == 0 ) {
            for ( j = i - periodsback, k = 0 ; j < i ; j++, k++ ) {
                LRegLine[j] = Aa + bb * k;
            }
        } else { // at the right edge, this segment will change
                    // with every new bar added.
            for ( j = i - (i % periodsback), k = 0 ; j < i + 1 ; j++, k++ ) 
{
                LRegLine[j] = Aa + bb * k;
            }
        }
    }
}
Plot( Close, "Close", colorBlack, styleCandle );
Plot( LRegLine, "LinReg", colorRed );

But... It won't give valid backtest results because on any given historical 
bar, the LRegLine is based on future data,
(except once every PeriodsBack days).  The same thing would be true if you 
tried to plot multiple overlapping
linear regression lines.  They'd mostly be based on future data as far as 
the backtest is concerned.

LinearReg() doesn't have that problem.  It's always giving you the rightmost 
point of the current PeriodsBack
linear regression line at every bar.

Regards,

Bob

----- Original Message ----- 
From: "Rick" <RickParsons@xxxxxxxxxxxxxxx>
To: <amibroker@xxxxxxxxxxxxxxx>
Sent: Friday, September 23, 2005 2:06 PM
Subject: [amibroker] Re: How do make this formula self adjust for entire 
data history?


> "SelectedValue" only works if I click on the chart.  I want these
> valude to adjust themselves like a MA would over time.
>
> Thank you for trying to help.  Do you have any other ideas?
>
> Thanks!!  :)
>
> --- In amibroker@xxxxxxxxxxxxxxx, Graham <kavemanperth@xxxx> wrote:
>> that si because you ahve used LastValue, which is the last value
>>
>> try selectedvalue
>>
>> On 9/23/05, Rick <RickParsons@xxxx> wrote:
>> > The following formula only gives me a plot for "PeriodsBack" from
> the
>> > last date in file.  If I scroll back in time, the lines will not
> adjust
>> > according to what is shown.
>> >
>> > I want to be able to backtest, so as the backtest goes thru time,
> I
>> > want this formula to self adjust for each day.
>> >
>> > Thanks !!  :) :)
>> >
>> > PeriodsBack = Param("PeriodsBack", 96, 53, 200, 2);
>> >
>> > x = Cum(1);
>> > lastx = LastValue( x );
>> > aa = LastValue( LinRegIntercept( Close, Periodsback) );
>> > bb = LastValue( LinRegSlope( Close, Periodsback ) );
>> > y = Aa + bb * ( x - (Lastx - PeriodsBack) );
>> > Plot( Close, "Close", colorBlack, styleCandle );
>> > Plot( IIf( x >= (lastx - Periodsback), y, -1e10 ), "LinReg",
> colorRed );
>> >
>> >
>> >
>> >
>> >
>> > 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 other support material please check also:
>> > http://www.amibroker.com/support.html
>> >
>> >
>> > Yahoo! Groups Links
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>>
>>
>> --
>> Cheers
>> Graham
>> AB-Write >< Professional AFL Writing Service
>> Yes, I write AFL code to your requirements
>> http://e-wire.net.au/~eb_kavan/ab_write.htm
>
>
>
>
>
>
> 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 other support material please check also:
> http://www.amibroker.com/support.html
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
> 




------------------------ Yahoo! Groups Sponsor --------------------~--> 
Try Online Currency Trading with GFT. Free 50K Demo. Trade 
24 Hours. Commission-Free. 
http://us.click.yahoo.com/RvFikB/9M2KAA/U1CZAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

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 other support material please check also:
http://www.amibroker.com/support.html

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> 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/