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

Re: [amibroker] What are static variables used for?


  • Date: Sat, 30 Jan 2010 16:50:20 +0100
  • From: "Markus Witzler" <funnybiz@xxxxxx>
  • Subject: Re: [amibroker] What are static variables used for?

PureBytes Links

Trading Reference Links



Hello Steve,
 
let add what Mike answered to my question on static variables a short while ago (see below).
 
Cheers
 
Markus
 
- - - - - - - - - -
 
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
>
----- Original Message -----
Sent: Saturday, January 30, 2010 4:00 PM
Subject: Re: [amibroker] What are static variables used for?

 

Hi -I think the big thing with static vars is that they can be shared, i.e.
you can create a var in one chart and save it with StaticVarSet(), then you
can access it from other charts or from AA with a call to StaticVarGet().

Steve

----- Original Message -----
From: "Pmxgs" <pmxgs@xxxxxxxxpt>
To: <amibroker@xxxxxxxxxps.com>
Sent: Saturday, January 30, 2010 9:45 AM
Subject: [amibroker] What are static variables used for?

> Hello,
>
> can someone please explain me what ate static variables used for?
>
> In the help section it says that a static varable keeps its value in
> memory until the end of the program.
> What's the difference between this and assigning a value to a normal
> variable (which also doesn't change unless we assign another value to it).
> For example: var=3; keeps this variable equal to 3 until we assign another
> value to it.
>
> I know I'm missing something obvious, but I'm learning how to program and
> I can't understand this concept.
>
> thanks
>
>
>
>
>
> ------------------------------------
>
> **** 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/
>
> Yahoo! Groups Links
>
>
>
>



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

The message was checked by ESET Smart Security.

http://www.eset.com


__________ 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

__,_._,___