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

Re: [amibroker] using global variables in multi-time frame



PureBytes Links

Trading Reference Links

2 ways you would need to do this as procedures do not provide any real
output, only an action

METHOD 1

X =Y = 0; //initialise global variables on first pass through code

procedure Test(TimeFrame)
{
   TimeFrameSet( Timeframe );
       ...now process some stuff and allocate values to the global
variables ...
   X = xx;
   Y = yy;
   TimeFrameRestore();
Plot(TimeFrameExpand(X,Timeframe ,expandLast), "", colorblue);
Plot(TimeFrameExpand(Y,Timeframe expandLast), "", colorblue);

}

Test(indaily);
Test(inweekly);




METHOD 2


X =Y = 0; //initialise global variables on first pass through code

procedure Test(TimeFrame)
{
Global x;
global y;
   TimeFrameSet( Timeframe );
       ...now process some stuff and allocate values to the global
variables ...
   X = xx;
   Y = yy;
   TimeFrameRestore();
}

//now call on the procedure in daily time frame and plot
Test(inDaily);
Plot(TimeFrameExpand(X,inDaily,expandLast), "", colorblue);
Plot(TimeFrameExpand(Y,inDaily,expandLast), "", colorblue);

//now call on the procedure in weekly time frame and plot
Test(inWeekly);
Plot(TimeFrameExpand(X,inWeekly,expandLast),"",, "", colorred);
Plot(TimeFrameExpand(Y,inWeekly,expandLast),"",, "", colorred);



-- 
Cheers
Graham
AB-Write >< Professional AFL Writing Service
Yes, I write AFL code to your requirements
http://www.aflwriting.com


On 05/12/06, andy_davidson_uk1 <AndyDavidson@xxxxxxxxxxxxx> wrote:
>
> I'm using a procedure to output several global variables. This works
> fine normally (i.e. all variables are returned OK), but when when I try
> to use it in conjunction with multi-time frame analysis I run across
> problems.
>
> A simplified version of the code is shown below. I would copy it all but
> there's a lot of lines and I'm sure the "process some stuff" bit is all
> working fine anyhow. The problem is that (on an EOD chart) the daily
> plots are fine, but the expanded weekly TF plots are not. Variables X
> and Y are unchanged by the second procedure call...i.e. they are the
> same *values* as discovered in the daily time frame - only expanded to a
> weekly plot. If I switch the chart to a weekly plot I get
> differing values for the X and Y variables, so there is no doubt that
> this is plotting incorrectly.
>
> In the full code there are a lot more than just two variables returned
> by the procedure, so I need to get this sorted to avoid getting
> unecessarily messy.
>
> The basic logic looks fine to me. Grateful if someone could point out
> what I'm missing,
> TIA
> Andy
>
> //-----------------------------
> X =Y = 0; //initialise global variables on first pass through code
>
> procedure Test(TimeFrame)
> {
>     TimeFrameSet( Timeframe );
>         ...now process some stuff and allocate values to the global
> variables ...
>     X = xx;
>     Y = yy;
>     TimeFrameRestore();
> }
>
> //now call on the procedure in daily time frame and plot
> Test(inDaily);
> Plot(TimeFrameExpand(X,inDaily,expandLast), "", colorblue);
> Plot(TimeFrameExpand(Y,inDaily,expandLast), "", colorblue);
>
> //now call on the procedure in weekly time frame and plot
> Test(inWeekly);
> Plot(TimeFrameExpand(X,inWeekly,expandLast),"",, "", colorred);
> Plot(TimeFrameExpand(Y,inWeekly,expandLast),"",, "", colorred);
>
> //------------------------------------
>
>
>
>
>
> 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 NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
> http://www.amibroker.com/devlog/
>
> For other support material please check also:
> http://www.amibroker.com/support.html
>
> Yahoo! Groups Links
>
>
>
>

Content-Description: "AVG certification"
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.15.9/573 - Release Date: 12/5/2006 4:07 PM