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

Re: [amibroker] Still Problem using IIf() and arrays to trackpeaks and valleys



PureBytes Links

Trading Reference Links

Just going to the 2nd line of code. You can't assign to an array by
referencing prior values of that same array inside and IIF statement.

In your case, your third test will always be false since the value of
isfalling "at the time of evaluating your 2nd line of code" will be 0 based
on your first line of code.

The only way to check previous values as you are trying to do is to use a
loop that evaluates each bar of the array one at a time, thus the prior
value IS then available to test against.

This is why you had to "initialize" the array first to get rid of the error
"..array not initialized". It just makes it all zeros and that is what is
referred to while line 2 is executing.

PS: Here's a simplified portion of the first part of line 2...
isfalling = IIf(C <= Ref(C,-1)...
 instead of
isfalling = IIf(C<Ref(C,-1) OR C==Ref(C,-1)...

Terry
--

> I am still having a problem using IIf() and arrays to track peaks and
> valleys.  I just tried to simplify and comment the code so people
> could more easily see my problem.  TIA for your help. -- Keith
> 
> ======= code starts here ================
> // is price falling
> isfalling = 0;  // initialize array
> isfalling = IIf(C<Ref(C,-1) OR C==Ref(C,-1) AND Ref(isfalling, -1),
> 1, 0);
> //extra code for troubleshooting
> Plot(IIf(isfalling,500,400), "isfalling", colorRed, styleLine); //
> below recent RUT2K
> 
> 
> recentpeak = 650;  // initialize to value higher than recent RUT2K
> price
> // if price just changed to falling then last value was a peak
> // set value of recentpeak to the peak and follow it until next peak
> recentpeak = IIf(isfalling AND NOT Ref(isfalling,-1), Ref(C,-1), Ref
> (recentpeak,-1));
> //PROBLEM: recentpeak is set to proper value but then goes to 650 on
> the next bar!!!!
> //  This means that if conditional statement is false then recentpeak
> is NOT set
> //    to Ref(recentpeak,-1) as it should be but just stays at inital
> value of 650.
> 
> GraphXSpace=5;
> Plot(C, "Close", colorBlack, styleLine);  // testing with RUT which
> is near 500
> Plot(recentpeak, "Recent Peak", colorGreen, styleLine);
> 
> 



------------------------ Yahoo! Groups Sponsor --------------------~--> 
$9.95 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/J8kdrA/y20IAA/yQLSAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

Check AmiBroker web page at:
http://www.amibroker.com/

Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.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/