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

[amibroker] Re: Recursive Boolean Expressions... Possible?



PureBytes Links

Trading Reference Links

Well it depends on exactly what you want to achieve, which is why I
said "in the general case". If Graham's solution does achieve what you
want, then it's not really an iterative problem. For example, with the
first code I wrote, you could easily rewrite it in one line so that
varx doesn't appear on the right-hand side at all:

varx = BarIndex()<10 AND NOT Ref((BarIndex()<10),-1);

Using the "temp" variable simply prevents having to call the BarIndex
function twice.

Graham's solution could similarly be rewritten as:

varx = (C<Ref(L,-6) AND vary<6) AND NOT Ref((C<Ref(L,-6) AND vary<6),-6);

Again, no varx on the right-hand side, but this is not the same thing
as what you originally wrote (it's possibly what you meant, but not
what you wrote).

Regards,
GP


--- In amibroker@xxxxxxxxxxxxxxx, "sidhartha70" <sidhartha70@xxx> wrote:
>
> GP,
> 
> Thanks for your detailed response here.
> I'm not sure I can see why the solution suggested by Graham won't
> work. Sorry if I'm being dense, but while you absolutely prove that,
> 
> temp = BarIndex() < 10;
> varx = temp AND NOT Ref(temp,-1);
> 
> and
> 
> varx = BarIndex() < 10 AND NOT Ref(varx,-1);
> 
> are indeed not the same solution... it seems to me that the former
> does actually get me what I want. And does so by evaluating temp
> first. Again, I might be missing something here. I try and implement
> that solution into my code and let you know if I get the desired result.
> 
> TIA
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "gp_sydney" <gp.investment@> wrote:
> >
> > Graham,
> > 
> > That doesn't work either, in the general case, as varx is still not
> > dependent on previous values of varx, only on previous values of your
> > first "temp" statement.
> > 
> > Consider the simpler case:
> > 
> > temp = BarIndex() < 10;
> > varx = temp AND NOT Ref(temp,-1);
> > 
> > temp now has the first 10 bars set to one and all other bars set to
> > zero. varx will have the first 11 bars set to zero, since Ref(temp,-1)
> > is one (actually the first bar will probably be null) and then all
> > subsequent bars will also be zero since temp is then zero.
> > Consequently, varx would be completely zero, except perhaps for the
> > first null.
> > 
> > Assuming this did work as suggested, compare to:
> > 
> > varx = BarIndex() < 10 AND NOT Ref(varx,-1);
> > 
> > Actually if the first bar was null due to Ref(varx,-1) being null,
> > then varx would end up completely full of nulls (a problem to be wary
> > of with nulls in loops). But say the first bar ended up being zero
> > (perhaps the nz function was used), then the second bar would be one,
> > since BarIndex is less than 10 and Ref(varx,-1) refers to the first
> > bar which we just said was zero. The third bar would be zero, since
> > Ref(varx,-1) now refers to the second bar which we just set to one,
> > and the fourth bar would be one again. This would continue up to the
> > 10th bar, after which all bars would be zero due to the BarIndex term.
> > The first 10 bars of varx alternating between one and zero make the
> > result different to the first version.
> > 
> > Regards,
> > GP
> > 
> > 
> > --- In amibroker@xxxxxxxxxxxxxxx, Graham <kavemanperth@> wrote:
> > >
> > > try this
> > > temp = C<Ref(L,-6) AND vary<6;
> > > varx = temp AND NOT Ref(temp ,-6);
> > > 
> > > -- 
> > > Cheers
> > > Graham Kav
> > > AFL Writing Service
> > > http://www.aflwriting.com
> > > 
> > > 
> > > 
> > > 
> > > 2008/9/18 gp_sydney <gp.investment@>:
> > > > No, you can't do that as the right-hand expression is evaluated
> on the
> > > > whole array before anything is assigned to the left-hand variable.
> > > > That means that "varx" is effectively constant during the
expression
> > > > evaluation for the whole array. It's essentially the same as:
> > > >
> > > > temp = IIf(C<Ref(L,-6) AND vary<6 AND NOT
Ref(varx,-6),True,False);
> > > > varx = temp;
> > > >
> > > > To do what you are suggesting would require a loop.
> > > >
> > > > Regards,
> > > > GP
> > > >
> > > >
> > > > --- In amibroker@xxxxxxxxxxxxxxx, "sidhartha70" <sidhartha70@>
> wrote:
> > > >>
> > > >> Hi All,
> > > >>
> > > >> Is it possible to have recursive boolean expressions...? i.e. the
> > true
> > > >> or false of the current value of the array depends on whether a
> > > >> previous value of the array is true or false.
> > > >>
> > > >> So for example,
> > > >>
> > > >> varx = IIf(C<Ref(L,-6) AND vary<6 AND NOT
Ref(varx,-6),True,False);
> > > >>
> > > >> Would that work... or are recursive booleans like this not
> allowed??
> > > >>
> > > >> TIA
> > > >>
> > >
> >
>



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

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/