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

RE: [amibroker] programming 101



PureBytes Links

Trading Reference Links


 (1)  The Iif() cannot be used to assign "a" to "a" unless "a" has already been assigned.  For example, assume each of following snipets occur as the first lines of an AFL: Ex. 1 - Will Worka = 1+1;b = 1+2;c = 3+2;a = Iif(c>b,b,a); Ex. 2 - Will NOT Work
b = 1+2;c = 3+2;a = Iif(c>b,b,a); //This is because prior to this step "a" does not exist and therefor cannot be assigned to any variable, inc. "a."  To solve this you could add a line in the beginning setting "a=0" or place "Null" in the Else portion of the statement.(2) Iif cond1 Then a=c....  where "a" must persist until, I assume, some other condition is true.  If my assumption is correct and we call this other condition "cond2," then the following code would work:a = Iif(cond1,c,0);Flip(a,cond2);(3) I'll give you my method, however, I believe there exist more elegant and efficient ways of producing this result.  The first exemplifies a condition where you want the historical occurrences and the second exemplifies a condition where you only want the number of occurrences while some other condition has been true.  There are, of course, many variations. Ex. 1 - Historical OccurrencesAboveMA = Iif(C>MA(C,20),1,0);CountHow
 ManyAboveMA = Cum(AboveMA); Ex. 2 - Occurences Since Cond2 (A rising 20 period MA) Has Been TrueAboveMA = Iif(C>MA(C,20),1,0);RisingMA = Iif(MA(C,20)>Ref(MA(C,20)),1,0);CountAboveMAWhileMARising = Iif(RisingMA==1,Sum(AboveMA,BarsSince(RisingMA=0)),0); To save values you can again use the Flip() function (For persistance until another condition is met) or the Hold() function (For persistance over a set number of bars). -Rich--- On Fri 05/16, Sidney Kaiser < s9kaiser@xxxxxxxxxxx > wrote:From: Sidney Kaiser [mailto: s9kaiser@xxxxxxxxxxx]To: AmiBroker@xxxxxxxxxxxxxxxDate: Fri, 16 May 2003 11:07:48 -0700Subject: [amibroker] programming 101Still struggling with trying to convert that Tradestation script....  ;(A few basic elements seem to crop up over and over again.  The p
 roblem is I am a trader not a programmer, and I spend huge amounts of time spinning my wheels trying to generate or adapt code to do fairly simple tasks.  Here are a couple samples.(1)  IF condition then a=b            // trying to use IIF , would that be: a = IIF(condition, b, a);  ie: the true condition has a new value but ?? on the value to be used for the false condition.(2)  IF condition then a=c        // Where the value for "a" needs to persist until it is changed by the program.  Does that involve the use of ValueWhen(condition, c);   and I would think that the condition needs to change to a cross  function to pick up the first value where condition is true.  Multi part question I guess, but the details are important to poor programmers like myself.(3)  How do I set up a counter in AFL to keep track of the number of occurrences of some condition.      IF condition then increment count
 er            // Again the value of the counter needs to persist until it is used perhaps many bars later and then is probably reset.TIASidSend BUG REPORTS to bugs@xxxxxxxxxxxxxSend SUGGESTIONS to suggest@xxxxxxxxxxxxx-----------------------------------------Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx (Web page: http://groups.yahoo.com/group/amiquote/messages/)--------------------------------------------Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. 
---Outgoing mail is certified Virus Free.Checked by AVG anti-virus system (http://www.grisoft.com).Version: 6.0.481 / Virus Database: 277 - Release Date: 5/13/2003Join Excite! - http://www.excite.comThe most personalized portal on the Web!







Yahoo! Groups Sponsor












Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html



Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.