PureBytes Links
Trading Reference Links
|
<FONT face=Arial color=#0000ff
size=2>Ara,
<FONT face=Arial color=#0000ff
size=2>
You
have to be careful scoping the Static Variables,
<FONT face=Arial color=#0000ff
size=2>
1) If
you use same name static variables in different indicators then their values can
change from various sources. This is the case if you assign program derived
values, for example counters ,not in the case of param() see
next...
<FONT face=Arial color=#0000ff
size=2>
2) If
the Static variables are initialized inside the code with a Param() in EACH of
the Indicators then in essence you have disabled the Global nature of the
Static Variable: this is so because the Static variable is reinitialized in
each Indicator separately each time the code is executed (on Refresh). This
makes it immune to whatever other code does.
<FONT face=Arial color=#0000ff
size=2>
3)
Static variables are truly Global, in contrast to afl variables declared Global
in afl, these are Global 'per' indicator. Static variables are Global per
AmiBroker Instance.
<FONT face=Arial color=#0000ff
size=2>
4) If
you want to restrict the scope of Static variables to the current Indicator, to
prevnt conflicing conditions, then you have to add a unique identifier to
each code, I use something like this:
ChartID = <FONT color=#0000ff
size=2>NumToStr(<FONT color=#0000ff
size=2>GetChartID(),<FONT color=#ff00ff
size=2>1.0,False); Reset = <FONT
color=#0000ff size=2>Param(<FONT color=#ff00ff
size=2>"Reset Static variables",<FONT color=#ff00ff
size=2>0,0<FONT
size=2>,1,<FONT
color=#ff00ff size=2>1<FONT
size=2>);StaticScope = Param(<FONT
color=#ff00ff>"Scope (0:Local,1:Global) for Chart#"+ChartID,<FONT
color=#ff00ff>1,0,<FONT
color=#ff00ff>1,1);<FONT
color=#800000>if( StaticScope ) Scope = <FONT
color=#ff00ff>""; else<FONT
size=2> Scope = ChartID;<FONT
face=Arial>.<SPAN
class=343574700-09082004>..<FONT
color=#800000>if<FONT color=#000000
size=2>( IsEmpty<FONT color=#000000
size=2>( StaticVarGet<FONT
color=#000000 size=2>(<FONT color=#ff00ff
size=2>"TickCounter"<FONT
color=#000000>+Scope)) OR Reset)<FONT color=#0000ff
size=2>StaticVarSet(<FONT color=#ff00ff
size=2>"TickCounter"+Scope,<FONT color=#ff00ff
size=2>0);TickCount = <FONT
color=#0000ff size=2>StaticVarGet(<FONT color=#ff00ff
size=2>"TickCounter"<FONT
size=2>+Scope);<FONT
color=#800000>
<SPAN
class=343574700-09082004><SPAN
class=343574700-09082004>here a tickcounter is
made Local to the indicator containing the code to prevent interference with
duplicate code in other indicators. This means i can count ticks from fifferent
stocks while using the SAME indicator.
Hope
this helps,
<SPAN
class=343574700-09082004>herman.
<FONT face=Arial
color=#0000ff>
<FONT
face=Tahoma size=2>-----Original Message-----From: Ara Kaloustian
[mailto:ara1@xxxxxxxxxx]Sent: Sunday, August 08, 2004 8:46
PMTo: AB-MainSubject: [amibroker] Static
Variables
I am having a hard time using static
variables....
Sometimes they work as expected ... sometimes
they don't ... so my expectation must obviously be questionable.
I am assuming Static variables can be used
anywhere that normal Number and String variables can be used!
- in assignments:
StaticVarSet("Var",Value);
- in If Statements: if (StaticVarGet("Var") ==
Value) ....
- in iif Statement: Test =
iif(StaticVarGet("Var") ==Value,True,False);
Is my assumption correct?
Thanks
AraCheck AmiBroker web
page at:<A
href="">http://www.amibroker.com/Check
group FAQ at: <A
href="">http://groups.yahoo.com/group/amibroker/files/groupfaq.html
Check AmiBroker web page at:
http://www.amibroker.com/
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html
Yahoo! Groups Sponsor
ADVERTISEMENT
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 the Yahoo! Terms of Service.
|