Tony - 2nd arg of For Loop means to continue looping *while* the condition is true, not *until* it is true. You have initialized Stop to zero but then told the Loop to keep looping as long as Stop >0. You should change the ">" to "==" ( 2 equal signs ), *but*...
Now that I have looked closer at your code, it is also wrong that you are using array-based IIF inside the loop - to walk the arrays, you should be using IF ( non-array ) and [] subscripts to check each element one at a time. It is usually easier to just use array-based AFL - does the code I gave you yesterday work? Steve ----- Original Message ----- From: "Tony" <[EMAIL PROTECTED]> To: <[email protected]> Sent: Sunday, September 23, 2007 1:34 AM Subject: [amibroker] Re: Could someone point in the right direction... > Steve, > Thank you for your response. > I tried changing the 2nd argument to a test (but it still does not > work (see below). I still get the same results. Any suggestions? > > I will explore your second option. > Thank you. > > Tony > > > > CheckAlligator = 0; > stop =0; > NumberOfDays =0; > for ( i=-1; stop > 0 ; i--) > { > > CheckAlligator =IIf( Ref(AlligatorGreen,i) > Ref(AlligatorRed,i) AND > Ref(AlligatorGreen,i) > Ref(AlligatorBlue, i) AND > Ref(AlligatorRed,i) > Ref(AlligatorBlue, i) ,1, 0); > > // if in uptrend increment the NumberOfDays variable > if (CheckAlligator == 1 ) > NumberOfDays = 1 + NumberOfDays; > else > stop = 1; > > }// end for loop > > > > > --- In [email protected], "Steve Dugas" <[EMAIL PROTECTED]> wrote: >> >> >> Hi - In 2nd arg of for loop header, you are assigning a value of > zero >> instead of testing for it, so I am guessing the expression returns > zero and >> so is never true. Might be easier to do this without a loop, > something >> like... >> >> InTrend = AlligatorGreen > AlligatorRed AND AlligatorRed > > AlligatorBlue; >> NotInTrend = NOT InTrend; >> TrendBars = BarsSince( NotInTrend ); >> >> >> Steve >> >> ----- Original Message ----- >> From: "Tony" <[EMAIL PROTECTED]> >> To: <[email protected]> >> Sent: Saturday, September 22, 2007 10:26 PM >> Subject: [amibroker] Could someone point in the right direction... >> >> >> > Hi, >> > >> > I am trying to write an exploration to loop back thru 3 arrays to >> > confirm how many days ago there was a crossover of the 3 moving >> > averages defined below. This is related the the Bill Williams > Chaos >> > Theory ( the alligator). Once the exploration is executed I would > be >> > able to see which stocks are still in an uptrend and have been in > an >> > uptrend for the longest time. >> > >> > However in my current formula, the for loop drops out on the very >> > first pass. I cannot figure out why. It never adds anything to the >> > NumberOfDays variable. >> > >> > I am certain the checkAlligator formula is correct as i tested it >> > manually. I just added the ref() and the index counter for my >> > formula, so it could loop back through the data. >> > >> > I would be gratefully if someone could explain to me what i a > doing >> > incorrectly? or point me in the correct direction. >> > >> > Thank you kindly in advance... >> > >> > Regards, >> > >> > Tony >> > >> > >> > A=((H+L)/2); >> > >> > AlligatorBlue=Ref(Wilders(A,13),-8); >> > AlligatorRed=Ref(Wilders(A,8),-5); >> > AlligatorGreen=Ref(Wilders(A,5),-3); >> > CheckAlligator = 0; >> > NumberOfDays =0; >> > for ( i=-1; stop = 0 ; i--) >> > { >> > >> > CheckAlligator =IIf( Ref(AlligatorGreen,i) > Ref(AlligatorRed,i) > AND >> > Ref(AlligatorGreen,i) > Ref(AlligatorBlue, i) > AND >> > Ref(AlligatorRed,i) > Ref(AlligatorBlue, i) ,1, > 0); >> > >> > // if in uptrend increment the NumberOfDays variable >> > if (CheckAlligator == 1 ) >> > NumberOfDays = 1 + NumberOfDays; >> > else >> > stop = 1; >> > >> > }// end for loop >> > >> > Filter = C > 1; >> > AddColumn(i , "index "); >> > AddColumn(Checkalligator , "Checkalligator"); >> > AddColumn(NumberOfDays , "NumberOfDays "); >> > AddColumn(Close , "Close"); >> > AddColumn(AlligatorGreen, "AlligatorGreen"); >> > AddColumn(AlligatorRed, "AlligatorRed"); >> > AddColumn(AlligatorBlue, "AlligatorBlue"); >> > >> > >> > >> > 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 >> > >> > >> > >> > >> > > > > > 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 > > > >
