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

[amibroker] Re: Global variables



PureBytes Links

Trading Reference Links

Don't know whether this is helpful in clarifying it, but I'll give it 
a try:

Say I have an AFL which looks like this:

bla bla bla . . . . .

examplevar=C/2; // This examplevar is now defined and thus already by 
definition a global variable !

bla bla bla . . . .

function Trial()
{
global examplevar; // Here I define examplevar again, but now as a 
global variable within the function; this will cause a problem as 
we'll see

. . . .
anotherexamplevar=H/2;

examplevar=C/3;

return anotherexamplevar;
}

. . . .

CallTrial = Trial();

CallExampleVar=examplevar;// This returns the value of the very first 
definition of examplevar, thus the one before = outside the function. 
It is therefore NOT equal to the "examplevar" defined as a global 
variable within the function. In fact, there is no way to catch this 
latter value, unless you change the code/names/etc.

This is my understanding and how I use it.

PS



--- In amibroker@xxxxxxxxxxxxxxx, "Ara Kaloustian" <ara1@xxxx> wrote:
>
> Exactly ... That's how I use it ...  but it is not working reliably
> 
> Ara
> ----- Original Message ----- 
> From: "Graham" <kavemanperth@xxxx>
> To: <amibroker@xxxxxxxxxxxxxxx>
> Sent: Wednesday, November 02, 2005 6:26 PM
> Subject: Re: [amibroker] Re: Global variables
> 
> 
> > If I want to use a variable that is defined within a function or
> > procedure I first define it as a globla variable within the 
function
> > or procedure. it is then available within the AFL after that 
function
> > or procedure has been called
> >
> > On 11/3/05, Chuck <cstangor232@xxxx> wrote:
> > > According to the help manual, this is how global and local 
variables
> relate
> > > to functions (depends on where they are first defined):
> > >
> > > If given identifier appears first INSIDE function definition - 
then it
> is
> > > treated as LOCAL variable.
> > > If given identifier appears first OUTSIDE function definition - 
then it
> is
> > > treated as GLOBAL variable.
> > >
> > >
> > > ----- Original Message -----
> > > From: "Ara Kaloustian" <ara1@xxxx>
> > > To: <amibroker@xxxxxxxxxxxxxxx>
> > > Sent: Wednesday, November 02, 2005 12:12 PM
> > > Subject: Re: [amibroker] Re: Global variables
> > >
> > >
> > > > Barry
> > > >
> > > > this is getting confusing ...
> > > >
> > > > Globals defined as such within a function seem available 
globally ...
> but
> > > > as
> > > > I indicated earlier... not reliably.
> > > >
> > > > According to the help files, there is no distinction between 
globals
> > > > defined
> > > > within functions and variables initialized outside of 
functions.
> > > >
> > > > Where did you see the distinction you mentioned?
> > > >
> > > > Hope this thread resolves the "mystery" of globals.
> > > >
> > > >
> > > > Ara
> > > >
> > > > ----- Original Message -----
> > > > From: "Barry Scarborough" <razzbarry@xxxx>
> > > > To: <amibroker@xxxxxxxxxxxxxxx>
> > > > Sent: Wednesday, November 02, 2005 8:54 AM
> > > > Subject: [amibroker] Re: Global variables
> > > >
> > > >
> > > >> Global variables defined withing a function are scoped to 
that
> > > >> function and all the sub functions within that function. But 
once
> > > >> you call outside that function the variable is not 
available. If you
> > > >> want the variable to be global it has to be in a global 
scope,
> > > >> outside of the functions that will use it. Declare it at the 
top of
> > > >> your code and it will have global scope as you mentioned. 
Otherwise
> > > >> pass it as a parameter. This is much safer. You have to be 
careful
> > > >> when using globals because anyone can change a global 
anytime and
> > > >> anywhere, darn hard to debug if that happens. If that is OK 
then
> > > >> make it global.
> > > >>
> > > >> I would have to look at your code to see what you are doing.
> > > >>
> > > >> Barry
> > > >>
> > > >>  --- In amibroker@xxxxxxxxxxxxxxx, "Ara Kaloustian" 
<ara1@xxxx>
> > > >> wrote:
> > > >> >
> > > >> > I have had some problems with defining globals within a 
function.
> > > >> >
> > > >> > Globals defined withing a function are not always 
available to
> > > >> code later on. In one situation, a global defined within a 
prior
> > > >> function and used in an indicator, was not available to some 
copies
> > > >> of the indicator and was available to some others where the
> > > >> indicator was used multiple times in same instance, but on 
different
> > > >> panes.
> > > >> >
> > > >> > If I initialize the variable at the beginning of the 
program, it
> > > >> is automatically a global and always works reliably.
> > > >> >
> > > >> > Anyone with similar issues?
> > > >> >
> > > >> > Ara
> > > >> >
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
> > > >> Please note that this group is for discussion between users 
only.
> > > >>
> > > >> To get support from AmiBroker please send an e-mail directly 
to
> > > >> SUPPORT {at} amibroker.com
> > > >>
> > > >> For other support material please check also:
> > > >> http://www.amibroker.com/support.html
> > > >>
> > > >>
> > > >> Yahoo! Groups Links
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
> > > >
> > > >
> > > >
> > > > Please note that this group is for discussion between users 
only.
> > > >
> > > > To get support from AmiBroker please send an e-mail directly 
to
> > > > SUPPORT {at} amibroker.com
> > > >
> > > > For other support material please check also:
> > > > http://www.amibroker.com/support.html
> > > >
> > > >
> > > > Yahoo! Groups Links
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> > >
> > >
> > > Please note that this group is for discussion between users 
only.
> > >
> > > To get support from AmiBroker please send an e-mail directly to
> > > SUPPORT {at} amibroker.com
> > >
> > > For other support material please check also:
> > > http://www.amibroker.com/support.html
> > >
> > >
> > > Yahoo! Groups Links
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> >
> >
> > --
> > Cheers
> > Graham
> > AB-Write >< Professional AFL Writing Service
> > Yes, I write AFL code to your requirements
> > http://e-wire.net.au/~eb_kavan/ab_write.htm
> >
> >
> >
> > Please note that this group is for discussion between users only.
> >
> > To get support from AmiBroker please send an e-mail directly to
> > SUPPORT {at} amibroker.com
> >
> > For other support material please check also:
> > http://www.amibroker.com/support.html
> >
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
>






------------------------ Yahoo! Groups Sponsor --------------------~--> 
Try Online Currency Trading with GFT. Free 50K Demo. Trade 
24 Hours. Commission-Free. 
http://us.click.yahoo.com/RvFikB/9M2KAA/U1CZAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For other support material please check also:
http://www.amibroker.com/support.html

 
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:
    http://docs.yahoo.com/info/terms/