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

[amibroker] Re: What is wrong?



PureBytes Links

Trading Reference Links

It's a fairly standard programming dilemma that being out by one
thing. If HHVBars returns 10, and you do LinRegSlope with a period of
10, does that include the HHV bar itself or start from the bar after?

Usually you just have to think about things logically using
more-obvious values. HHVBars returns the number of bars since the HHV.
If the current bar was the HHV, you'd expect zero. If the bar before,
you'd expect one. If the HHV was the bar before, and you wanted the
regression to include both the current bar and the HHV bar (ie. the
two consecutive bars), then the period would need to be two. So if
HHVBars returns one, you want the LinRegSlope period to be two. Thus
you'd want:

slope = LinRegSlope(Close, HHVBars(High,20)+1);

Ultimately if you're not sure, and you think you'll know the correct
result if you see it, just try both.

Regards,
GP


--- In amibroker@xxxxxxxxxxxxxxx, "Louis P." <rockprog80@xxx> wrote:
>
> Hi gp_sydney,
> 
> Than you very much for your help.  I think I understand a bit better
now.
> You are right: I need to get better at AFL.  Someone helps me, but
there is
> so much stuff to learn and even someone who is good at AFL can't be
good at
> everything in it I guess.  If I understand corretly, I don't even need a
> function, and I did use the
> 
> slope = LinRegSlope(Close, HHVBars(High,20));
> 
> and it did work correctly with the code calculating the angle.
> 
> However, I was wondering: does it calculate from the actual HHV High
or from
> the HHV next day's bar?
> 
> I had that problem with rsquared as well where it was starting to
draw the
> line with next day's data.  With rsquared it is pretty straight
forward to
> see when it doesn't work (I posted a message on this issue some day
ago) but
> with LR it is more complicated as LR is a bit like an average of all the
> data...  (If anyone was able to tell me how to set it so it could
start from
> the hhv day and not the day after that, of course I would appreciate)
> 
> Anyway, thanks to everyone who helped me with this issue.   I was
finally
> able to get an angle from the LR.  Next step for me is to improve a
bit on
> that stuff.  Tried to read the manual, but in my humble opinion next
version
> of the manual should have more examples.
> 
> Thanks,
> 
> Louis
> 
> 2008/9/23 gp_sydney <gp.investment@xxx>
> 
> >   Louis,
> >
> > You need to understand more of the basics of AFL, as the problem
> > you're mainly having now has nothing to do with linear regression but
> > rather just AFL language structure.
> >
> > A function is a separate entity to the main code, and you need to
> > "return" the result from the function to use it elsewhere. Also, your
> > main code needs to call the function for it to do anything.
> >
> > That function is not a correlation function, but one that calculates
> > the linear regression slope and intercept (if I interpreted the
> > formula correctly). The array 'b' is the slope, and 'a' the intercept.
> > What I called "line" and you've renamed to "slope" is the formula for
> > the resulting line in array form.
> >
> > The parameters 'x' and 'y' are the generic coordinates for the data
> > points. In this case, 'x' would be the bar number (BarIndex()) and 'y'
> > the price (Close), giving a slope in dollars per bar.
> >
> > So to finish the function correctly, assuming you just want the slope,
> > add the statement:
> >
> > return b;
> >
> > The "a + b*x" line can be removed, as it was only to indicate the
> > formula for the resulting line.
> >
> > Then in the main code, add the lines:
> >
> > range = HHVBars(High, 20);
> > slope = CorrV(BarIndex(), Close, range);
> >
> > and use that "slope" variable in the arc-tangent formula to get an
> > array of slopes in degrees.
> >
> > Tomasz indicated elsewhere that the LinRegSlope function can take an
> > array as the period, so you probably don't need your own function.
> > Also try:
> >
> > slope = LinRegSlope(Close, HHVBars(High,20));
> >
> >
> > Regards,
> > GP
> >
> > --- In amibroker@xxxxxxxxxxxxxxx <amibroker%40yahoogroups.com>,
"Louis P."
> > <rockprog80@> wrote:
> > >
> > > Hi again,
> > >
> > > I did a small mistake in the last code. Here it is:
> > >
> > > range = HHVBars(High, 20);
> > > function CorrV( x, y, range )
> > > {
> > >
> > > avX = MA(x, range);
> > > avY = MA(y, range);
> > > avXY = MA(x*y, range);
> > > axXX = MA(x*x, range);
> > >
> > > b = (avXY - avX*avY) / (avXX - avX*avX);
> > > a = axY - b*avX;
> > >
> > > slope = a + b*x;
> > >
> > > }
> > >
> > > PI=3.14159265358979;
> > >
> > > Deg = atan(slope)*180/PI;
> > >
> > > Plot (deg,"deg",colorRed);
> > >
> > > I think I need to somehow "close" the function, but I don't know how
> > to do
> > > it. This code does not seem to work.
> > >
> > > Louis
> > >
> > > 2008/9/23 Louis P. <rockprog80@>
> > >
> > > > Hi again,
> > > >
> > > > Here is a code I tested:
> > > >
> > > > range = HHVBars(High, 20);
> > > > function CorrV( x, y, range )
> > > > {
> > > >
> > > > avX = MA(x, range);
> > > > avY = MA(y, range);
> > > > avXY = MA(x*y, range);
> > > > axXX = MA(x*x, range);
> > > >
> > > > b = (avXY - avX*avY) / (avXX - avX*avX);
> > > > a = axY - b*avX;
> > > >
> > > > slope = a + b*x;
> > > >
> > > > }
> > > >
> > > > PI=3.14159265358979;
> > > >
> > > > Deg = atan(range)*180/PI;
> > > >
> > > > Plot (deg,"deg",colorRed);
> > > >
> > > >
> > > > Unfortunately it does not seem to work. Degree is very often
> > between 75
> > > > and 85 where I see a slope that is not that steep! What could be
> > wrong?
> > > >
> > > > Thanks,
> > > >
> > > > Louis
> > > >
> > > > 2008/9/23 Louis P. <rockprog80@>
> >
> > > >
> > > > Hi,
> > > >>
> > > >> First of all, thank you very much for your help. I have been
> > struggling
> > > >> with this for the last month, and I feel like I am close to
get to
> > > >> something.
> > > >>
> > > >> @Barry: I did use the following
> > > >>
> > > >> vHHV = HHV(c,20);
> > > >> hhvValue = SelectedValue(Ref(vHHV, BarsSince(vHHV)));
> > > >> printf("HHV Value " + NumToStr(HHVValue, 1.2));
> > > >>
> > > >> but it does not seem to work, becasue I get a blank screen when
> > using it.
> > > >> And I feel (but I may be wrong) that the "Selectedvalue" might
> > still be a
> > > >> problem, because I want a formula that can be applied to any bar
> > on the
> > > >> chart, without having selected any one (something backtestable).
> > > >>
> > > >>
> > > >> @Tony: Before using that formula
> > > >>
> > > >> PI=3.14159265358979;
> > > >>
> > > >> Deg = atan(Slope)*180/PI;
> > > >>
> > > >>
> > > >> if I understand correctly I'd need to figure out what will be
> > "slope" and
> > > >> that "slope" should be the Linear Regression as gp_sydney said.
> > So I am
> > > >> still stuck as I have trouble establishing the LR outside of the
> > > >> selectedvalue.
> > > >>
> > > >> I understand what you say about the concept: it seems weird to
> > want to
> > > >> draw lines from each HHV to each bar; of course it would look
> > like a fan and
> > > >> would be useless. But this is not what I want; I don't want to
> > use it as a
> > > >> chart, but rather has something that can be backtested. I want
> > each bar to
> > > >> consider only its "own line" starting from its own HHV (c,X)
> > going to its
> > > >> own Close. The problem with Selectedvalue is that it consider
> > where I am
> > > >> on the chart, but as I see things I want to backtest the data so
> > I'd need
> > > >> something that can be used without seeing the chart.
> > > >>
> > > >> I'll try to explain again in different works.
> > > >>
> > > >> For any particular bar in the array (and without looking at the
> > chart; I
> > > >> want the whole thing to be backtestable) I want to get its
own Linear
> > > >> Regression and then calculate the slope of that LR to get the
> > angle and the
> > > >> degree. Then, maybe I could use Rsquared to check if the data
> > fits the
> > > >> angle or if there are bars very high over the LR and very low
> > under that
> > > >> same LR?
> > > >>
> > > >> @gp_sydney:
> > > >>
> > > >> The formula you posted is this:
> > > >>
> > > >> n = HHVBars(High, periods);
> > > >> avX = MA(x, n);
> > > >> avY = MA(y, n);
> > > >> avXY = MA(x*y, n);
> > > >> axXX = MA(x*x, n);
> > > >>
> > > >> b = (avXY - avX*avY) / (avXX - avX*avX);
> > > >> a = axY - b*avX;
> > > >>
> > > >> line = a + b*x;
> > > >>
> > > >> Please forgive my ignorance (I have really trouble to work
with this
> > > >> stuff), but I tried to use it but I got messages saying that x
> > variable had
> > > >> not been initialized, etc.
> > > >>
> > > >> But if I understand correctly, if I can make this thing work
I could
> > > >> simply use the "line" and put it in place of "slope" in Tony's
> > formula,
> > > >> right?
> > > >>
> > > >>
> > > >> Thank you very much for your help!
> > > >>
> > > >> Louis
> > > >>
> > > >>
> > > >>
> > > >>
> > > >> 2008/9/22 gp_sydney <gp.investment@>
> > > >>
> > > >> Louis,
> > > >>>
> > > >>> All I can suggest is using the LinRegSlope function to get
the slope
> > > >>> array (or calculate it yourself using the other formula I
> > posted), and
> > > >>> then the arc-tangent formula to convert it to degrees. That will
> > give
> > > >>> you an array where for every bar, the value will be the
slope of the
> > > >>> regression line that (I think) you want in degrees.
> > > >>>
> > > >>> Regards,
> > > >>> GP
> > > >>>
> > > >>> --- In amibroker@xxxxxxxxxxxxxxx
<amibroker%40yahoogroups.com><amibroker%
> > 40yahoogroups.com>,
> > "Louis
> > > >>> P." <rockprog80@> wrote:
> > > >>> >
> > > >>> > Hi,
> > > >>> >
> > > >>> > @Tony Grimes: I don't want a straight line between two
points; I
> > > >>> want the LR
> > > >>> > from the HHV to each point. Let's say that bar 1 is the
HHV, then
> > > >>> I'd like
> > > >>> > LR for bar 3, for bar 4, for bar 5, etc. until there is a new
> > HHV. The
> > > >>> > problem with the code I use is that it uses
"selectedvalue" which
> > > >>> mean it
> > > >>> > can only draw the line from where I am on the chart; I'd
like that
> > > >>> for each
> > > >>> > and every bar so it can be backtested! BTW, how would you use
> > that:
> > > >>> Deg =
> > > >>> > atan(Slope)*180/PI;? I am not sure how to set the variables
> > > >>> straight so it
> > > >>> > can work... Thanks!
> > > >>> >
> > > >>> > @gp_sydney: I know the 1$/bar idea is a bit stupid, but this
> > is the
> > > >>> only
> > > >>> > thing I have found for now. I asked support for help on
this, but
> > > >>> of course
> > > >>> > they don't do coding but they told me I had to be able to
set a Y
> > > >>> and an X
> > > >>> > that is not relative so I could draw an angle from this.
Can you
> > > >>> think of
> > > >>> > something else to do the trick?
> > > >>> >
> > > >>> > Thanks,
> > > >>> >
> > > >>> > Louis
> > > >>> >
> > > >>> > 2008/9/20 gp_sydney <gp.investment@>
> > > >>> >
> > > >>> > > Louis,
> > > >>> > >
> > > >>> > > You need to explain how you define steepness. The regression
> > formula
> > > >>> > > gives the slope in dollars per bar. What units do you want
> > it in?
> > > >>> > >
> > > >>> > > When you talk of the slope in degrees, how do you define
> > that? For
> > > >>> > > example, 45 degrees is delta Y (price) and delta X (bars)
> > being the
> > > >>> > > same, or $1 / bar. That seems like a pretty useless
figure to me
> > > >>> > > though, as it would be shallow on the graph of a $200 stock
> > but very
> > > >>> > > steep on the graph of a 20 cent stock (which is why I'd
> > probably be
> > > >>> > > using semi-log and trying to do linear regression based
on a log
> > > >>> scale
> > > >>> > > with percentage gain per bar - but even then, what would 45
> > degrees
> > > >>> > > be, 1% per bar?).
> > > >>> > >
> > > >>> > >
> > > >>> > > GP
> > > >>> > >
> > > >>> > > --- In amibroker@xxxxxxxxxxxxxxx
<amibroker%40yahoogroups.com>
> > <amibroker%40yahoogroups.com><amibroker%
> >
> > > >>> 40yahoogroups.com>,
> > > >>> "Louis P."
> > > >>> > > <rockprog80@> wrote:
> > > >>> > > >
> > > >>> > > > Hi,
> > > >>> > > >
> > > >>> > > > @Tony:Sorry I thought gradient was the good word. Maybe I
> > meant
> > > >>> > > angle, or
> > > >>> > > > degree? I want a LR slope of approx. 30-50 degrees. How
> > can I do
> > > >>> that?
> > > >>> > > > @gp_sydney: I need to go to work, but will check this
> > tomorrow or
> > > >>> > > Monday. I
> > > >>> > > > looked very quickly and was wondering where in that
> > formula can I
> > > >>> > > determine
> > > >>> > > > how steep the slope will be. That would help a lot!
> > > >>> > > >
> > > >>> > > > Thank you you two a lot!
> > > >>> > > >
> > > >>> > > > Louis
> > > >>> > > >
> > > >>> > > >
> > > >>> > > >
> > > >>> > > > 2008/9/20 gp_sydney <gp.investment@>
> > > >>> > > >
> > > >>> > > > > Sorry, a couple of typos in the formula. It should be:
> > > >>> > > > >
> > > >>> > > > >
> > > >>> > > > > n = HHVBars(High, periods);
> > > >>> > > > > avX = MA(x, n);
> > > >>> > > > > avY = MA(y, n);
> > > >>> > > > > avXY = MA(x*y, n);
> > > >>> > > > > avXX = MA(x*x, n);
> > > >>> > > > >
> > > >>> > > > > b = (avXY - avX*avY) / (avXX - avX*avX);
> > > >>> > > > > a = avY - b*avX;
> > > >>> > > > >
> > > >>> > > > > GP
> > > >>> > > > >
> > > >>> > > > >
> > > >>> > > > > --- In
amibroker@xxxxxxxxxxxxxxx<amibroker%40yahoogroups.com>
> > <amibroker%40yahoogroups.com>
> > > >>> <amibroker%40yahoogroups.com><amibroker%
> > > >>>
> > > >>> > > 40yahoogroups.com>,
> > > >>> > >
> > > >>> > > > > "gp_sydney" <gp.investment@> wrote:
> > > >>> > > > > >
> > > >>> > > > > > Louis,
> > > >>> > > > > >
> > > >>> > > > > > I gather you want to use regression to get a
best-fit line
> > > >>> from the
> > > >>> > > > > > most-recent HHV, not just draw a line between the end
> > points.
> > > >>> > > From my
> > > >>> > > > > > understanding of regression though, which isn't a
lot, I
> > > >>> gather that
> > > >>> > > > > > such a line may not actually pass through either end
> > point, so
> > > >>> > > may not
> > > >>> > > > > > go "from the HHV" exactly or end at the current bar
> > exactly
> > > >>> (to get
> > > >>> > > > > > that, just draw a line between those two points as
> > previously
> > > >>> > > > > > mentioned). Once you have the line though, you could
> > offset it
> > > >>> > > > > > vertically to get it to pass exactly through the
HHV or
> > > >>> current bar
> > > >>> > > > > > (but not both of course).
> > > >>> > > > > >
> > > >>> > > > > > From a response Tomasz gave you in another thread
> > about how to
> > > >>> > > > > > calculate Rsquared without a loop:
> > > >>> > > > > >
> > > >>> > > > > >
> > http://finance.groups.yahoo.com/group/amibroker/message/129392
> > > >>> > > > > >
> > > >>> > > > > > you can similarly do the regression itself.
According to
> > > >>> Tomasz,
> > > >>> > > > > > LinRegSlope already accepts variable periods (ie.
arrays),
> > > >>> so to get
> > > >>> > > > > > the slope you should be able to just use that
> > function. Or to
> > > >>> > > > > > calculate both coefficients yourself, then something
> > like this
> > > >>> > > (based
> > > >>> > > > > > on the formula given at
> > http://www.educalc.net/2104083.page):
> > > >>> > > > > >
> > > >>> > > > > > n = HHVBars(High, periods);
> > > >>> > > > > > avX = MA(x, n);
> > > >>> > > > > > avY = MA(y, n);
> > > >>> > > > > > avXY = MA(x*y, n);
> > > >>> > > > > > axXX = MA(x*x, n);
> > > >>> > > > > >
> > > >>> > > > > > b = (avXY - avX*avY) / (avXX - avX*avX);
> > > >>> > > > > > a = axY - b*avX;
> > > >>> > > > > >
> > > >>> > > > > > Hopefully I've got that right (I haven't tested it).
> > The line
> > > >>> > > formula
> > > >>> > > > > > is then:
> > > >>> > > > > >
> > > >>> > > > > > line = a + b*x;
> > > >>> > > > > >
> > > >>> > > > > > The slope is 'b' and the intercept 'a'. The slope
is in
> > > >>> dollars per
> > > >>> > > > > > bar. I'm not sure what you want by a percentage slope
> > > >>> though, as the
> > > >>> > > > > > 'x' and 'y' axes are in completely different units.
> > > >>> > > > > >
> > > >>> > > > > > Also note that the calculated lines would only be
> > straight on a
> > > >>> > > linear
> > > >>> > > > > > price scale (if they were plotted). If you use
semi-log,
> > > >>> then the
> > > >>> > > > > > formula for a straight line is different - and how
to do
> > > >>> regression
> > > >>> > > > > > for it would take some figuring out.
> > > >>> > > > > >
> > > >>> > > > > > Hope this helps.
> > > >>> > > > > >
> > > >>> > > > > > Regards,
> > > >>> > > > > > GP
> > > >>> > > > > >
> > > >>> > > > > >
> > > >>> > > > > > --- In
amibroker@xxxxxxxxxxxxxxx<amibroker%40yahoogroups.com>
> > <amibroker%40yahoogroups.com>
> > > >>> <amibroker%40yahoogroups.com><amibroker%
> > > >>>
> > > >>> > > 40yahoogroups.com>,
> > > >>> > >
> > > >>> > > "Louis
> > > >>> > > > > P." <rockprog80@> wrote:
> > > >>> > > > > > >
> > > >>> > > > > > > Hi,
> > > >>> > > > > > >
> > > >>> > > > > > > I need the gradient of the slope, and for each
bar. This
> > > >>> is where
> > > >>> > > > > it is
> > > >>> > > > > > > difficult...
> > > >>> > > > > > >
> > > >>> > > > > > > Thanks,
> > > >>> > > > > > >
> > > >>> > > > > > > Louis
> > > >>> > > > > > >
> > > >>> > > > > > > 2008/9/19 Tony Grimes <Tonez.Email@>
> > > >>> > > > > > >
> > > >>> > > > > > > > Louis,
> > > >>> > > > > > > >
> > > >>> > > > > > > > If your looking for the slope & difference between
> > HHV of
> > > >>> 20
> > > >>> > > bars
> > > >>> > > > > > & the
> > > >>> > > > > > > > current close, all you should need is this:
> > > >>> > > > > > > >
> > > >>> > > > > > > > Pds=20;
> > > >>> > > > > > > >
> > > >>> > > > > > > > LastHighBar = HHVBars(High, Pds);
> > > >>> > > > > > > > LastHighVal = HHV(High, Pds);
> > > >>> > > > > > > >
> > > >>> > > > > > > > Slope = IIf(LastHighBar,(Close - LastHighVal) /
> > > >>> LastHighBar,0);
> > > >>> > > > > > > > CloseDiff = Close - Ref(Close, -LastHighBar);
> > > >>> > > > > > > >
> > > >>> > > > > > > >
> > > >>> > > > > > > > On Fri, Sep 19, 2008 at 4:51 PM, Louis P.
> > <rockprog80@>
> > > >>> wrote:
> > > >>> > > > > > > >
> > > >>> > > > > > > >> Hi Tony,
> > > >>> > > > > > > >>
> > > >>> > > > > > > >> Thank you a lot for your response. I'm still very
> > weak
> > > >>> with
> > > >>> > > > > > loops. Last
> > > >>> > > > > > > >> time experimented with one, I had to reboot my
> > > >>> computer! :) So
> > > >>> > > > > > do you know
> > > >>> > > > > > > >> how such a loop could work? And if I run,
let's say 2
> > > >>> minutes
> > > >>> > > > > > bar for one
> > > >>> > > > > > > >> year, wouldn't that be really really long to deal
> > with?
> > > >>> I have
> > > >>> > > > > > PIV with 1.5
> > > >>> > > > > > > >> GHz ram.
> > > >>> > > > > > > >>
> > > >>> > > > > > > >> I am looking for a line that ends at each bar and
> > that
> > > >>> starts
> > > >>> > > > > > from the HHV
> > > >>> > > > > > > >> of 20 bars, and I want to do things with this
> > bar: e.g.
> > > >>> compare
> > > >>> > > > > > the closes
> > > >>> > > > > > > >> between current bar and the HHV to the bar and
> > > >>> establish the
> > > >>> > > > > > gradient of
> > > >>> > > > > > > >> that linear regression bar for each bar.
> > > >>> > > > > > > >>
> > > >>> > > > > > > >> Thanks a lot!
> > > >>> > > > > > > >>
> > > >>> > > > > > > >> Louis
> > > >>> > > > > > > >>
> > > >>> > > > > > > >> 2008/9/19 Tony Grimes <Tonez.Email@>
> > > >>> > > > > > > >>
> > > >>> > > > > > > >>> Hi Louis,
> > > >>> > > > > > > >>>
> > > >>> > > > > > > >>> A loop will work, but how slow - it depends
> > (Speed of
> > > >>> your
> > > >>> > > > > computer,
> > > >>> > > > > > > >>> number of bars loaded, how many loops your using
> > etc...).
> > > >>> > > > > > Without seeing
> > > >>> > > > > > > >>> what your actually looking for (The end
result), I
> > > >>> think you
> > > >>> > > > > > could do it
> > > >>> > > > > > > >>> with one loop, with only one pass through
the loop.
> > > >>> The speed
> > > >>> > > > > > should be OK.
> > > >>> > > > > > > >>>
> > > >>> > > > > > > >>> Good Luck.
> > > >>> > > > > > > >>>
> > > >>> > > > > > > >>> Tony
> > > >>> > > > > > > >>>
> > > >>> > > > > > > >>> On Fri, Sep 19, 2008 at 2:47 PM, Louis P.
> > > >>> <rockprog80@> wrote:
> > > >>> > > > > > > >>>
> > > >>> > > > > > > >>>> Hi Tony,
> > > >>> > > > > > > >>>>
> > > >>> > > > > > > >>>> Thanks for the tips. Basically, I'd need a
loop and
> > > >>> use it on
> > > >>> > > > > > each and
> > > >>> > > > > > > >>>> every bar of the array to determine the LR,
right?
> > > >>> > > > > > > >>>>
> > > >>> > > > > > > >>>> That will slow down my computer a lot, don't
> > you think?
> > > >>> > > > > > > >>>>
> > > >>> > > > > > > >>>> Thanks,
> > > >>> > > > > > > >>>>
> > > >>> > > > > > > >>>> Louis
> > > >>> > > > > > > >>>>
> > > >>> > > > > > > >>>> 2008/9/16 Tony Grimes <Tonez.Email@>
> > > >>> > > > > > > >>>>
> > > >>> > > > > > > >>>>> SelectedValue takes an array ( of numbers) and
> > returns
> > > >>> a
> > > >>> > > > > single
> > > >>> > > > > > > >>>>> number based on the bar that is selected in
> > the chart.
> > > >>> > > > > > > >>>>>
> > > >>> > > > > > > >>>>> The first formula worked because
SelectedValue was
> > > >>> > > giving you a
> > > >>> > > > > > > >>>>> number.
> > > >>> > > > > > > >>>>>
> > > >>> > > > > > > >>>>> Look at it this way: Array -->
SelectedValue --->
> > > >>> Number.
> > > >>> > > > > > > >>>>>
> > > >>> > > > > > > >>>>> Remove SelectedValue: Array---->Array.
> > > >>> > > > > > > >>>>>
> > > >>> > > > > > > >>>>> You can draw a line with single numbers,
but not
> > > >>> arrays.
> > > >>> > > > > > > >>>>>
> > > >>> > > > > > > >>>>> You can always use a loop.
> > > >>> > > > > > > >>>>>
> > > >>> > > > > > > >>>>> You might want to read: Understanding how AFL
> > works,
> > > >>> in the
> > > >>> > > > > > Amibroker
> > > >>> > > > > > > >>>>> users guide. Until you really understand AFL &
> > array
> > > >>> > > > > > processing, you are
> > > >>> > > > > > > >>>>> going to keep running into these problems,
which
> > > >>> will just
> > > >>> > > > > > slow you down.
> > > >>> > > > > > > >>>>>
> > > >>> > > > > > > >>>>>
> > > >>> > > > > > > >>>>> On Tue, Sep 16, 2008 at 10:34 PM, Louis P.
> > > >>> > > <rockprog80@>wrote:
> > > >>> > > > > > > >>>>>
> > > >>> > > > > > > >>>>>> Hi Tony,
> > > >>> > > > > > > >>>>>>
> > > >>> > > > > > > >>>>>> Why was the first formula working (the
one with
> > > >>> > > > > > selectedvalue) and not
> > > >>> > > > > > > >>>>>> the second one? Why simply deleting the
> > > >>> "selectedvalue"
> > > >>> > > > > > makes it an array
> > > >>> > > > > > > >>>>>> that will not be accept in "linearray"?
> > > >>> > > > > > > >>>>>>
> > > >>> > > > > > > >>>>>> Is there any way to draw a line without using
> > > >>> lastvalue or
> > > >>> > > > > > > >>>>>> selectedvalue? Do I need to use a loop?
> > > >>> > > > > > > >>>>>>
> > > >>> > > > > > > >>>>>> Thanks,
> > > >>> > > > > > > >>>>>>
> > > >>> > > > > > > >>>>>> Louis
> > > >>> > > > > > > >>>>>>
> > > >>> > > > > > > >>>>>> 2008/9/16 Tony Grimes <Tonez.Email@>
> > > >>> > > > > > > >>>>>>
> > > >>> > > > > > > >>>>>>> Louis,
> > > >>> > > > > > > >>>>>>>
> > > >>> > > > > > > >>>>>>> All of the variables you are creating
for the
> > > >>> LineArray
> > > >>> > > > > > function are
> > > >>> > > > > > > >>>>>>> arrays themselves. Although LineArray
> > generates an
> > > >>> > > array, it
> > > >>> > > > > > does not accept
> > > >>> > > > > > > >>>>>>> any arrays as inputs. Additionally, your
error
> > > >>> message was
> > > >>> > > > > > probably
> > > >>> > > > > > > >>>>>>> different. It probably went from complaining
> > about
> > > >>> > > argument
> > > >>> > > > > > #4 having the
> > > >>> > > > > > > >>>>>>> incorrect type (which you corrected) to
argument
> > > >>> #3 having
> > > >>> > > > > > the incorrect
> > > >>> > > > > > > >>>>>>> type.
> > > >>> > > > > > > >>>>>>>
> > > >>> > > > > > > >>>>>>> On Tue, Sep 16, 2008 at 9:10 PM, Louis P.
> > > >>> > > <rockprog80@>wrote:
> > > >>> > > > > > > >>>>>>>
> > > >>> > > > > > > >>>>>>>> Hi,
> > > >>> > > > > > > >>>>>>>>
> > > >>> > > > > > > >>>>>>>> Thank you for your help.
> > > >>> > > > > > > >>>>>>>>
> > > >>> > > > > > > >>>>>>>> @Ara:
> > > >>> > > > > > > >>>>>>>>
> > > >>> > > > > > > >>>>>>>> If in
> > > >>> > > > > > > >>>>>>>>
> > > >>> > > > > > > >>>>>>>> barhh1 = HHVBars( High, Periods ) ;
> > > >>> > > > > > > >>>>>>>> bi1 = BarIndex();
> > > >>> > > > > > > >>>>>>>> y11 = LinearReg( C, barhh1 ) ;
> > > >>> > > > > > > >>>>>>>> y01 = LinRegIntercept( C, barhh1 ) ;
> > > >>> > > > > > > >>>>>>>> sl1 = LineArray( bi1-barhh1+0, y01, bi1,
> > y11, 0,
> > > >>> True );
> > > >>> > > > > > > >>>>>>>>
> > > >>> > > > > > > >>>>>>>> I replace
> > > >>> > > > > > > >>>>>>>>
> > > >>> > > > > > > >>>>>>>> sl1 = LineArray( bi1-barhh1+0, y01, bi1,
> > y11, 0,
> > > >>> True );
> > > >>> > > > > > > >>>>>>>>
> > > >>> > > > > > > >>>>>>>> by
> > > >>> > > > > > > >>>>>>>>
> > > >>> > > > > > > >>>>>>>> sl1 = LineArray( bi1-barhh1+0, y01, bi1,
> > > >>> > > LastValue(y11), 0,
> > > >>> > > > > > True
> > > >>> > > > > > > >>>>>>>> );
> > > >>> > > > > > > >>>>>>>>
> > > >>> > > > > > > >>>>>>>> I still have the same error message. I
> > don't know
> > > >>> from
> > > >>> > > > > > where it is
> > > >>> > > > > > > >>>>>>>> coming.. unfortunately!
> > > >>> > > > > > > >>>>>>>>
> > > >>> > > > > > > >>>>>>>>
> > > >>> > > > > > > >>>>>>>> @gp_sydney:
> > > >>> > > > > > > >>>>>>>>
> > > >>> > > > > > > >>>>>>>> That was a typo, you are right; I arranged
> > that by
> > > >>> > > adding a
> > > >>> > > > > > 1. But
> > > >>> > > > > > > >>>>>>>> still, the problem remains: the last
line does
> > > >>> not work.
> > > >>> > > > > > > >>>>>>>>
> > > >>> > > > > > > >>>>>>>> One day, I asked support if I needed a loop
> > to do
> > > >>> such LR
> > > >>> > > > > > and they
> > > >>> > > > > > > >>>>>>>> said I should not need one.
> > > >>> > > > > > > >>>>>>>>
> > > >>> > > > > > > >>>>>>>> Here is the original code:
> > > >>> > > > > > > >>>>>>>>
> > > >>> > > > > > > >>>>>>>> barhh = SelectedValue( HHVBars( High,
> > Periods ) );
> > > >>> > > > > > > >>>>>>>> bi = SelectedValue( BarIndex() );
> > > >>> > > > > > > >>>>>>>> y1 = SelectedValue( LinearReg( C, barhh
) );
> > > >>> > > > > > > >>>>>>>> y0 = SelectedValue( LinRegIntercept( C,
> > barhh ) );
> > > >>> > > > > > > >>>>>>>> sl = LineArray( bi-barhh+0, y0, bi, y1, 0,
> > True );
> > > >>> > > > > > > >>>>>>>>
> > > >>> > > > > > > >>>>>>>> What I want to do is simply eliminate the
> > > >>> "selectedvalue"
> > > >>> > > > > > part and
> > > >>> > > > > > > >>>>>>>> use the code not only for the selected
data but
> > > >>> for the
> > > >>> > > > > > whole data. I want
> > > >>> > > > > > > >>>>>>>> to be able to draw a line from each HHV
to each
> > > >>> bar and
> > > >>> > > > > > then work with the
> > > >>> > > > > > > >>>>>>>> result.
> > > >>> > > > > > > >>>>>>>>
> > > >>> > > > > > > >>>>>>>> If it can't be done without a loop, I
feel like
> > > >>> I'll be
> > > >>> > > > > > lost in time
> > > >>> > > > > > > >>>>>>>> again; last time I tried to run a loop
on my
> > > >>> computer it
> > > >>> > > > > > freezed and after 2
> > > >>> > > > > > > >>>>>>>> minutes I decided to shut down AB...
> > > >>> > > > > > > >>>>>>>>
> > > >>> > > > > > > >>>>>>>>
> > > >>> > > > > > > >>>>>>>> Thanks for the help,
> > > >>> > > > > > > >>>>>>>>
> > > >>> > > > > > > >>>>>>>> Louis
> > > >>> > > > > > > >>>>>>>>
> > > >>> > > > > > > >>>>>>>>
> > > >>> > > > > > > >>>>>>>>
> > > >>> > > > > > > >>>>>>>>
> > > >>> > > > > > > >>>>>>>>
> > > >>> > > > > > > >>>>>>>>
> > > >>> > > > > > > >>>>>>>>
> > > >>> > > > > > > >>>>>>>> 2008/9/16 gp_sydney <gp.investment@>
> > > >>> > > > > > > >>>>>>>>
> > > >>> > > > > > > >>>>>>>>> As Ara said, in the shown code snippet you
> > don't
> > > >>> have
> > > >>> > > > > > "barhh"
> > > >>> > > > > > > >>>>>>>>> defined,
> > > >>> > > > > > > >>>>>>>>> only "barhh1".
> > > >>> > > > > > > >>>>>>>>>
> > > >>> > > > > > > >>>>>>>>> Beyond that, you have the same issue I
> > mentioned
> > > >>> > > > > > originally, that
> > > >>> > > > > > > >>>>>>>>> the
> > > >>> > > > > > > >>>>>>>>> linear regression functions and LineArray
> > > >>> function take
> > > >>> > > > > scalar
> > > >>> > > > > > > >>>>>>>>> values
> > > >>> > > > > > > >>>>>>>>> (ie. single numbers) as parameters, not
> > arrays.
> > > >>> > > > > > > >>>>>>>>>
> > > >>> > > > > > > >>>>>>>>> I gather you're trying to create a line
> > from the
> > > >>> > > > > > most-recent HHV
> > > >>> > > > > > > >>>>>>>>> value
> > > >>> > > > > > > >>>>>>>>> using the subsequent close data for every
> > bar on
> > > >>> the
> > > >>> > > > > > chart. As I
> > > >>> > > > > > > >>>>>>>>> don't
> > > >>> > > > > > > >>>>>>>>> think the linear regression functions
can take
> > > >>> arrays
> > > >>> > > > > for the
> > > >>> > > > > > > >>>>>>>>> period,
> > > >>> > > > > > > >>>>>>>>> I think you'd need to use a loop and do
> > the linear
> > > >>> > > > > regression
> > > >>> > > > > > > >>>>>>>>> yourself
> > > >>> > > > > > > >>>>>>>>> at each bar (you could call the array
> > functions
> > > >>> > > within the
> > > >>> > > > > > loop,
> > > >>> > > > > > > >>>>>>>>> but
> > > >>> > > > > > > >>>>>>>>> since they fill a whole array each
time, they
> > > >>> would do a
> > > >>> > > > > > lot of
> > > >>> > > > > > > >>>>>>>>> unnecessary work). If you do that yourself
> > > >>> inside the
> > > >>> > > > > > loop, then at
> > > >>> > > > > > > >>>>>>>>> each bar you'd have scalar 'x' and 'y'
> > values to
> > > >>> > > calculate
> > > >>> > > > > > the line
> > > >>> > > > > > > >>>>>>>>> slope and so on.
> > > >>> > > > > > > >>>>>>>>>
> > > >>> > > > > > > >>>>>>>>> For what it's worth, the BarIndex function
> > > >>> simply gives
> > > >>> > > > > > you the bar
> > > >>> > > > > > > >>>>>>>>> number. It provides a way of using the
> > current bar
> > > >>> > > number
> > > >>> > > > > > in array
> > > >>> > > > > > > >>>>>>>>> formula.
> > > >>> > > > > > > >>>>>>>>>
> > > >>> > > > > > > >>>>>>>>> Regards,
> > > >>> > > > > > > >>>>>>>>> GP
> > > >>> > > > > > > >>>>>>>>>
> > > >>> > > > > > > >>>>>>>>>
> > > >>> > > > > > > >>>>>>>>> --- In
> > > >>> > > amibroker@xxxxxxxxxxxxxxx
<amibroker%40yahoogroups.com><amibroker%
> > 40yahoogroups.com>
> > <amibroker%
> > > >>> 40yahoogroups.com><amibroker%
> > > >>> > > 40yahoogroups.com>
> > > >>> > > > > > <amibroker%40yahoogroups.com>,
> > > >>> > > > > > > >>>>>>>>> "Louis P." <rockprog80@> wrote:
> > > >>> > > > > > > >>>>>>>>> >
> > > >>> > > > > > > >>>>>>>>> > Hi,
> > > >>> > > > > > > >>>>>>>>> >
> > > >>> > > > > > > >>>>>>>>> > Sorry, You can replace "periods" by 50
> > if you
> > > >>> wish. I
> > > >>> > > > > > just forgot
> > > >>> > > > > > > >>>>>>>>> to
> > > >>> > > > > > > >>>>>>>>> > include that.
> > > >>> > > > > > > >>>>>>>>> >
> > > >>> > > > > > > >>>>>>>>> > barhh1 = HHVBars( High, *50* ) ;
> > > >>> > > > > > > >>>>>>>>> > bi1 = BarIndex() ;
> > > >>> > > > > > > >>>>>>>>> > y11 = LinearReg( C, barhh ) ;
> > > >>> > > > > > > >>>>>>>>> > y01 = LinRegIntercept( C, barhh ) ;
> > > >>> > > > > > > >>>>>>>>> > sl1 = LineArray( bi1-barhh1+0, y01, bi1,
> > y11, 0,
> > > >>> > > True );
> > > >>> > > > > > > >>>>>>>>> >
> > > >>> > > > > > > >>>>>>>>> > Still, it is not working, even if
barhh1 is
> > > >>> defined...
> > > >>> > > > > > > >>>>>>>>> >
> > > >>> > > > > > > >>>>>>>>> > Louis
> > > >>> > > > > > > >>>>>>>>> >
> > > >>> > > > > > > >>>>>>>>> > 2008/9/16 Ara Kaloustian <ara1@>
> > > >>> > > > > > > >>>>>>>>> >
> > > >>> > > > > > > >>>>>>>>> > > y11 and y01 use "barhh" which is not
> > defined.
> > > >>> > > > > > > >>>>>>>>> > >
> > > >>> > > > > > > >>>>>>>>> > > You have defined "barhh1"
> > > >>> > > > > > > >>>>>>>>> > >
> > > >>> > > > > > > >>>>>>>>> > >
> > > >>> > > > > > > >>>>>>>>> > >
> > > >>> > > > > > > >>>>>>>>> > > ----- Original Message -----
> > > >>> > > > > > > >>>>>>>>> > > *From:* Louis P. <rockprog80@>
> > > >>> > > > > > > >>>>>>>>> > > *To:*
> > > >>> > > amibroker@xxxxxxxxxxxxxxx
<amibroker%40yahoogroups.com><amibroker%
> > 40yahoogroups.com>
> > <amibroker%
> > > >>> 40yahoogroups.com><amibroker%
> > > >>> > > 40yahoogroups.com>
> > > >>> > > > > > <amibroker%40yahoogroups.com>
> > > >>> > > > > > > >>>>>>>>> > > *Sent:* Tuesday, September 16, 2008
> > 2:46 PM
> > > >>> > > > > > > >>>>>>>>> > > *Subject:* [amibroker] What is wrong?
> > > >>> > > > > > > >>>>>>>>> > >
> > > >>> > > > > > > >>>>>>>>> > > Hi,
> > > >>> > > > > > > >>>>>>>>> > >
> > > >>> > > > > > > >>>>>>>>> > > What is wrong in the following
formula?
> > > >>> > > > > > > >>>>>>>>> > >
> > > >>> > > > > > > >>>>>>>>> > > barhh1 = HHVBars( High, Periods ) ;
> > > >>> > > > > > > >>>>>>>>> > > bi1 = BarIndex() ;
> > > >>> > > > > > > >>>>>>>>> > > y11 = LinearReg( C, barhh ) ;
> > > >>> > > > > > > >>>>>>>>> > > y01 = LinRegIntercept( C, barhh ) ;
> > > >>> > > > > > > >>>>>>>>> > > sl1 = LineArray( bi1-barhh1+0, y01,
> > bi1, y11,
> > > >>> 0,
> > > >>> > > True );
> > > >>> > > > > > > >>>>>>>>> > >
> > > >>> > > > > > > >>>>>>>>> > >
> > > >>> > > > > > > >>>>>>>>> > > Thanks,
> > > >>> > > > > > > >>>>>>>>> > >
> > > >>> > > > > > > >>>>>>>>> > > Louis
> > > >>> > > > > > > >>>>>>>>> > >
> > > >>> > > > > > > >>>>>>>>> > > p.s. There was "Selectedvalue" in the
> > first
> > > >>> four
> > > >>> > > lines
> > > >>> > > > > > but I
> > > >>> > > > > > > >>>>>>>>> don't
> > > >>> > > > > > > >>>>>>>>> want to
> > > >>> > > > > > > >>>>>>>>> > > plot it on the chart based on where I
> > am on
> > > >>> that
> > > >>> > > > > > chart, but
> > > >>> > > > > > > >>>>>>>>> simply
> > > >>> > > > > > > >>>>>>>>> set the
> > > >>> > > > > > > >>>>>>>>> > > variable so I can use the stuff later.
> > > >>> > > > > > > >>>>>>>>> > >
> > > >>> > > > > > > >>>>>>>>> > >
> > > >>> > > > > > > >>>>>>>>> > >
> > > >>> > > > > > > >>>>>>>>> >
> > > >>> > > > > > > >>>>>>>>>
> > > >>> > > > > > > >>>>>>>>>
> > > >>> > > > > > > >>>>>>>>
> > > >>> > > > > > > >>>>>>>
> > > >>> > > > > > > >>>>>>
> > > >>> > > > > > > >>>>>
> > > >>> > > > > > > >>>>
> > > >>> > > > > > > >>>
> > > >>> > > > > > > >>
> > > >>> > > > > > > >
> > > >>> > > > > > > >
> > > >>> > > > > > >
> > > >>> > > > > >
> > > >>> > > > >
> > > >>> > > > >
> > > >>> > > > >
> > > >>> > > >
> > > >>> > >
> > > >>> > >
> > > >>> > >
> > > >>> >
> > > >>>
> > > >>>
> > > >>>
> > > >>
> > > >>
> > > >
> > >
> >
> >  
> >
>



------------------------------------

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