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

Re: [amibroker] Re: Static variables


  • Date: Tue, 12 Jan 2010 11:58:09 +0100
  • From: "Markus Witzler" <funnybiz@xxxxxx>
  • Subject: Re: [amibroker] Re: Static variables

PureBytes Links

Trading Reference Links



Thanks, Mike for this thorough explanation.
 
Now, I got the difference.
 
Markus
----- Original Message -----
From: Mike
Sent: Friday, January 08, 2010 1:46 AM
Subject: [amibroker] Re: Static variables

 

The difference is the lifespan of the value. Formalizing your sample, we have the following code:

...
b = 5;
...
b = 6;

When running over a watchlist, the script is restarted for each symbol. Using your example, once the script begins over again for the next symbol, the value of b just before the line b = 5 will be the same as it was for the first symbol. Specifically, b will be undefined, not 6 as was the case at the end of the previous symbol's execution.

In other words, variables do not retain their value between executions of the script.

The behavior of VarSet is identical to simply saying b = 5. The only difference is that you can dynamically construct the name of the variable as opposed to hard coding it. This is useful when setting variables in a loop (e.g. b1 = ..., b2 = ..., b3 = ...).

Static variables are primarily used for two reasons:

1. To preserve values from execution to execution.
For example, changing your original code to use statics (StaticVarSet) would mean that for all subsequent symbols, the value of b would be 6 just before the line StaticVarSet(b, 5) instead of undefined. For the first symbol, b would still initially have been undefined until set to 5.

For a more practical example; automation traders will re-run the same scan/exploration over and over throughout the day as new bars come in. Using static variables they are able to preserve state information between executions (e.g. whether or not a position has been taken), even if running on just a single symbol rather than a watchlist.

2. To access information across panes.
StaticVarGet can be used from other panes to access a static value set from a different pane. Rather than having everything displayed in a single pane in a single script, it is sometimes more practical to do the calculations once in a "master" pane, and have one or more additional "detail" panes/scripts that chart a variety of related information.

Additional usage might include access within the latter pass of the backtester to values set during the initial signal generating pass.

Mike

--- In amibroker@xxxxxxxxxps.com, "Markus Witzler" <funnybiz@xx.> wrote:
>
> Hello,
>
> could someone enlighten me as to when I "should" use static variables (Varset)?
>
> I understand that they serve as "temporary storage space".
>
> But couldn´t I just use any letter, such as b=5 and later assign b = 6 etc. and retrieve/change its value whenever needed
>
> Where is the difference to a static variable?
>
> Sorry - again - for my ignorance!
>
> Thanks
>
> Markus
>



__________ Information from ESET Smart Security, version of virus signature database 4668 (20091207) __________

The message was checked by ESET Smart Security.

http://www.eset.com


__._,_.___


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

TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/





Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___