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

[amibroker] Automation to load an AFL and run Portfolio Optimization



PureBytes Links

Trading Reference Links

Hoping someone can chime in here to let me know what I might be doing wrong. I'm currently testing out some simple automation code. The objective is to load an AFL and then run a portfolio optimization for a specified date range.

I am using a simple MA crossover trading system for testing purposes. I can of course optimize it manually in AA without any problem. But when I try to run and control that optimization from a piece of automation code, I get a whole range of syntax errors.

Below are the two *separate* AFL codes. I imagine the first AFL has some errors in it that is preventing the actions from being carried out properly. What am I missing or doing wrong? Any input much appreciated:

//----------------------------------------------------------------------------
// AUTOMATION CODE: Load an AFL and Run a Portfolio Optimization
//----------------------------------------------------------------------------

EnableScript("jscript");
<%

database =
"C:\\Program Files\\Amibroker\\Data";
formula_1 =
"C:\\Simple MA Cross.afl";

AB  = new ActiveXObject(
"Broker.Application" );  
AB.LoadDatabase( database );
AA  = AB.Analysis;
Stk = AB.Stocks
Doc = AB.Documents.Open( Stk.Ticker );            

AA.LoadFormula( formula_1 );              
// load formula from external file

AA.ApplyTo       =
1;                     // use current symbol
AA.RangeMode     =
3;                     // use 'From' and 'To' dates
AA.RangeFromDate =
"11/01/2005";
AA.RangeToDate   =
"12/31/2005";
AA.Optimize(
0 );                         // run Optimize for the portfolio, which is just one symbol
AA.Backtest();

%>
//---------END AUTOMATION AFL-------------------------------------------------





//----------------------------------------------------------------------------
// Simple MA Cross: THIS IS A SEPARATE AFL SAVED AT: "C:\\Simple MA Cross.afl"
//----------------------------------------------------------------------------


FastMALength =
Optimize("FastMALength",      1,     1,    100,     1);
SlowMALength =
20;

//----------------------------------------------------------------------------
// BACKTESTER SETTINGS
//----------------------------------------------------------------------------

SetBarsRequired(10000, 0);                    
SetOption("AllowPositionShrinking", False);      
SetOption("AllowSameBarExit", True);              
SetOption("CommissionAmount", 3.00);              
SetOption("CommissionMode", 3);                  
SetOption("FuturesMode", 1);                    
SetOption("InitialEquity", 100000);              
SetOption("InterestRate",0);                      
SetOption("MaxOpenPositions", 1);
SetOption("MinPosValue", 0);                      
SetOption("MinShares", 1);                        
SetOption("PriceBoundChecking", False );          
SetOption("ReverseSignalForcesExit", False);
SetOption("UsePrevBarEquityForPosSizing", True );
SetTradeDelays(0, 0, 0, 0);
SetPositionSize(1, spsShares);
TickSize      = 0.0001;    // The minimum price move of symbol for Forex
PointValue    = 100000;
RoundLotSize  = 1;
MarginDeposit = 2500;
BuyPrice      = SellPrice = ShortPrice = CoverPrice = Close;

//------------------------------------------------------------------------
// TRADING SYSTEM
//------------------------------------------------------------------------

FastMA       =    
MA( C, FastMALength );
SlowMA       =    
MA( C, SlowMALength );
Buy          = Cross( FastMA, SlowMA  );
Sell         = Cross( SlowMA, FastMA  );

__._,_.___

**** IMPORTANT ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

*********************
TO GET TECHNICAL 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

*********************************




Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___