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 [email protected], "Graham Johnson" <[EMAIL PROTECTED]> 
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
>


Reply via email to