Cheers Tomasz. I appreciate the feedback and you taking your time. I'll go back and do some hard thinking with the information that you've shared.
Thank you and best wishes James ----- Original Message ----- From: Tomasz Janeczko To: [email protected] Sent: Friday, August 13, 2010 8:59 PM Subject: Re: [amibroker] Staticvarset generating error condition with zig function. Hello, I guess that you may be misguided by one assumption that you are making, that Cum(1) is the "absolute bar number". It is NOT. See docs: http://www.amibroker.com/guide/afl/afl_view.php?cum Adding/removing functions increases/decreases number of required QuickAFL bars http://www.amibroker.com/kb/2008/07/03/quickafl/ When you add new functions to your formula, it will most probably use more bars, so Cum(1) will return *different* numbers as well as BarCount will change. Never rely on "absolute number of bars" or "absolute bar index" because there is no such thing. What you see in AFL as "number of bars" or "index" change, as you zoom in / out, add new functions or new data arrive. If you actually ploted "x" variable you would quickly see that. x = Cum( 1 ); Causeserror = Zig( High, 0.1 ); // <= remove "//" and the functionality changes, Var1 = MA( L, 5 ); Var2 = MA( H, 15 ); Var3 = Cross( Var1, Var2 ); Plot ( Var3 *1000, "va3", colorRed ); for ( i = 0; i < BarCount; i++ ) { if ( Var3[i] == 1 ) { StaticVarSet( "svar", x[i] ); // Last "x" value when var3[i] == 1 } } Plot( x, "X - is CHANGING! - TRY ZOOMING OR ADDING NEW FUNCTIONS! ", colorRed ); Plot( StaticVarGet( "svar" ), "svar", colorBlue ); Best regards, Tomasz Janeczko amibroker.com On 2010-08-13 14:03, Tomasz Janeczko wrote: Hello, If I add x = Cum(1); and uncomment Causeserror = Zig(High, 0.1); there is NO error message generated. Besides, what you are trying to achieve with constructs like that: for (i=0; i<BarCount; i++) { if ( Var3[i] == 1 ) { StaticVarSet("svar", x[i]); // Last "x" value when var3[i] == 1 } } It calls StaticVarSet multiple times (unnecessarily), just to assign SINGLE SCALAR VALUE (the last one). Then you Plot single scalar value (i.e. flat line) with: Plot(StaticVarGet("svar"), "svar", colorBlue); All what this code does it to plot FLAT line at the level of last ValueWhen LastValue( ValueWhen( Var3, Cum(1) ) ); This statement will be orders of magnitude faster than your loop. > "running a high array count" What does that mean for you? It does not matter how many temporary AFL arrays you have because they are ALL released at the end of the formula. They do not take any memory between formula executions. The situation is exactly opposite with STATIC variables. Static variables use memory all the time. You should AVOID using them, unless you *share* information between formulas. Best regards, Tomasz Janeczko amibroker.com On 2010-08-13 13:18, James wrote: G'day Tomasz, "x" is defined below. I am sorry if i dont have the expert understanding of required to be proficient at coding with amibroker. But "x" is most definately defined. When the code is run - it runs as my original post states. It works well - as long as the line with "zig" is not called. Part of the reason that prompted me to use staticvarset / get is that i am running a high array count and would like to drop it significantly. Regards J. ----- Original Message ----- From: Tomasz Janeczko To: [email protected] Sent: Friday, August 13, 2010 7:07 PM Subject: Re: [amibroker] Staticvarset generating error condition with zig function. Hello, In your formula an error appears regardless of Zig(). Did you actually READ what error message says? It says "variable x used without being initialized". Error says it all. You are trying to use variable ('x') that was NEVER defined. Before any use, you need to assign VALUE to the 'x' variable, like this: x = something; Do not try to "reduce array manipulation" because you lack basic understanding of AFL. The code that you have presented does nothing except to ADD complexity. You will gain *nothing* this way. Best regards, Tomasz Janeczko amibroker.com On 2010-08-13 10:09, James wrote: Hello, I had anyone else experienced staticvarset generating error an error condition with the use of the zig function ? I have been trying to work around this issue - but am finding that in order to reduce array manipulation - i would like to set static variables - but this does not seem to work with call of the zig function anywhere in the code. I have attached the sample code and a description of the irregularity with amibroker. This has been prevalent in 5.20 and is still an issue with 5.30. Have i overlooked anything ? Thanks and regards James p/s: this was tested on the sample data (^DJI Daily) that comes with the default amibroker install. x = Cum(1); //----------------------------------------------------------------------------- // In this example "svar" holds the last value of x when var3[i] == 1. // Note: this changes with the displayed data. // When the "Causeserror" array is not commented out - amibroker no longer // references the last displayed value. //----------------------------------------------------------------------------- //Causeserror = Zig(High, 0.1); // <= remove "//" and the functionality changes, Var1 = MA(L, 5); Var2 = MA(H, 15); Var3 = Cross(Var1, Var2); Plot (Var3 *1000, "va3", colorRed); for (i=0; i<BarCount; i++) { if (Var3[i] == 1) { StaticVarSet("svar", x[i]); // Last "x" value when var3[i] == 1 }} Plot(StaticVarGet("svar"), "svar", colorBlue);
