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

[amibroker] Re: Probably silly coding error;



PureBytes Links

Trading Reference Links

The reason that you can't do trend1=ADX()[0]>ADX()[1]; is that it is 
not legal to index a function call. You have to get the results from 
the call placed in an array and then look at the elements. 

As Mike said you DO NOT want to use array subscripts if you can avoid 
it. There are a couple of reasons, one being speed. The other being 
that indexing isn't what it seems on the surface. Read my post on the 
AB At forum about barindex and barcount. AB is not looking at the 
entire ticker array, only enough to plot the values. So it seems AB 
is using a subset array of your entire ticker array. Say you get the 
barindex and try to access an element near the end, you will get an 
our of range error because the array AB is using is no where the 
number of bars the ticker has. Using Ref(x, -n) will be much safer 
and much easier to debug. 

a = myADX[LastValue(BarIndex()) - 4] 
Error 10.
Subscript out of range.
You must not access array elements outside 0..(BarCount-1) range.

If you are new to AB and AFL and you are a programmer accustomed to C 
or some other language, AFL is a real paradigm shift. I am a C++ 
programmer, among other languages, and it took me a year to get my 
head around ABs arrays. I have been at it about 5 years and sometimes 
they still baffle me.

Cheers,
Barry 

IF you want to see something that will blow your mind put this in a 
formula and look at the interpretation window as you change the 
number of bars displayed and click on various bars. If you can watch 
this with live data comming in it will be much more confusing. 

// start of formula
// for AT purposes, you can define:
// When ALL elements are loaded, Barcount = LastValue(bi) -1. This is 
because
// BarCount is the actual number of cells AND since AFL uses zero 
based arrays,
// the first element index is 0 (zero).

// If you want to work with loops of limited length, use
// for (i = BarCount - 1 - x; i < BarCount; i++)
// where x is the number of elements you want to look at.

// For backtesting you have to give up efficiency if you want to test
// the entire array, else select the Date range you want.

bi = BarIndex();
lastBi = LastValue(bi);
ai = bi - bi[0];
printf("Barcount " + NumToStr(BarCount, 1.0, False) + "\nBarIndex " + 
NumToStr(bi, 1.0, False) + "\nlastBi " + NumToStr(lastBi , 1.0, 
False)  + "\nai " + NumToStr(ai, 1.0, False));
printf("\nC " + NumToStr(C, 1.2) + "\nSelected C " + NumToStr
(SelectedValue(C), 1.2) + "\nLastC " + NumToStr(LastValue(C), 1.2) ); 
printf("\nC[BarCount - 1] " + NumToStr(C[BarCount - 1], 1.2));

reset = ParamTrigger("Reset" , "Reset");
if(reset) StaticVarSet("bi", 0);
staticBI = StaticVarGet("bi");
if(staticBI == 0 OR staticBI < lastBi )
	printf("\n\nbi " + NumToStr(lastBi , 1.0, False) + "\nstatic 
bi " + NumToStr(staticBI , 1.0, False));
else
	printf("\n\nSame bar. LastValue(bi) " + NumToStr(Lastbi , 
1.0, False));

printf("\n\nInterval " + NumToStr(Interval(), 1.0));
// end of formula

watch out for the line wraps. They will cause errors.

--- In amibroker@xxxxxxxxxxxxxxx, "Mike" <sfclimbers@xxx> wrote:
>
> Hi,
> 
> I doubt that you want to use hard coded element references like 
that. 
> You are effectively stating that you want to know if the ADX of 
> exactly the second bar is greater than that of exactly the first 
bar, 
> regardless of what bar you happen to be on at the time of 
evaluation 
> (e.g. even if you are on bar 1200, you will still be basing your 
> trend calculation on the values of bar 0 and bar 1 which is not 
very 
> useful).
> 
> More likey, you would want to do something along the lines of:
> 
> MyADX = ADX();
> trend1 = MyADX > Ref(MyADX, -1);
> 
> This way, the value of trend1 is updated for each bar using the 
> current bar and the one immediately preceding it.
> 
> Mike
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "Tony Grimes" <Tonez.Email@> 
> wrote:
> >
> > Try This:
> > 
> > myADX = ADX();
> > trend1 = MyADX[0] > myADX[1];
> > 
> > 
> > On Sat, Oct 11, 2008 at 8:27 AM, noemeenswat <noemeenswat@> 
> wrote:
> > 
> > >   I want to determine or ADX is uptrending or downtrending. 
> Therfore I
> > > coded:
> > >
> > > trend1=ADX()[0]>ADX()[1];
> > >
> > > This should result in a true or false for trend1 depending on
> > > trenddirection of ADX. It gives however a consistent error 30 
> syntax
> > > error.
> > >
> > > If I replace ADX() by H, C etc it works fine. Can someone 
explain 
> what
> > > I'm doing wrong?
> > >
> > > Thanks
> > > Wilco
> > >
> > >  
> > >
> >
>



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

**** IMPORTANT ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

*********************
TO GET TECHNICAL 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/