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

[amibroker] Re: Pass value of variable from AFL to AFL



PureBytes Links

Trading Reference Links

Thanks Mike

So simple.  I have a history of looking for the complex solutions and 
missing the simple ones.

Thanks again

Graham


--- In amibroker@xxxxxxxxxxxxxxx, "Mike" <sfclimbers@xxx> wrote:
>
> Note that you could also just choose to pass the values as 
parameters 
> rather than using the global keyword.
> 
> e.g. DoBacktest(MaxPositions);
> 
> Mike
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "Mike" <sfclimbers@> wrote:
> >
> > Hi,
> > 
> > There may be a better way, but the following will achieve what 
> you're 
> > trying to do. 
> > 
> > In your main.afl, #include an external file which contains your 
> > custom backtest logic. Initialize all the variables that you need 
> to 
> > use before starting the backtest. You'll still start the backtest 
> > from main.afl, but simply defer all processing to the external 
file 
> > via a procedure call. e.g.
> > 
> > main.afl
> > --------
> > 
> > #include<backtest.afl>
> > 
> > MaxPositions = 20;
> > 
> > SetCustomBacktestProc("");
> > if (Status("action") == actionPortfolio) {
> >   DoBacktest();
> > }
> > 
> > Buy = Cover = IIF(DayOfWeek() == 1, 1, 0);
> > Sell = Short = IIF(DayOfWeek() == 4, 1, 0);
> > 
> > 
> > backtest.afl
> > ------------
> > 
> > procedure DoBacktest() {
> >   global MaxPositions;
> > 
> >   bo = GetBacktesterObject();
> >   bo.backtest();
> >   bo.addCustomMetric("Max Positions", MaxPositions);
> > }
> > 
> > 
> > Mike
> > 
> > --- In amibroker@xxxxxxxxxxxxxxx, "Graham Johnson" <grahamj@> 
> > wrote:
> > >
> > > For the sake of code re-use, I wish to have CBT code in its own 
> AFL 
> > and 
> > > access it using SetCustomBacktestProc("<filename>");
> > > 
> > > That works fine except that in the Main.afl there is a variable 
> set 
> > for 
> > > Max Open Positions and I want to pass that value to CBT.afl for 
> > > inclusion in the backtest report using AddCustomMetric.
> > > 
> > > Tried using Global but that didn't get a result - CBT.afl 
didn't 
> > > recognise the variable name.
> > > 
> > > I presume that from Main.afl I could write the value to a file 
> and 
> > then 
> > > retrieve the file in CBT.afl.  Gets a bit messy when wanting to 
> > pass 
> > > the values of several variables.
> > > 
> > > Is there a better way, please?
> > > 
> > > Graham
> > >
> >
>



------------------------------------

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

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> 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/