You can only automate AA from OUTSIDE of AA. I.e. the script should be EXTERNAL JScript, not an AFL run from AA befcause it will be immediatelly overwritten in first iteration.
Best regards, Tomasz Janeczko amibroker.com ----- Original Message ----- From: ozzyapeman To: [email protected] Sent: Friday, December 19, 2008 3:12 AM Subject: [amibroker] Re: Automation to load an AFL and run Portfolio Optimization The simplified code below runs without any syntax error. However, instead of optimizing through all 100 steps, it only does a single step. Any idea why doesn't it do all 100 steps, as coded in the Simple MA Cross afl?: //---------------------------------------------------------------------------- // 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; 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------------------------------------------------- --- In [email protected], "ozzyapeman" <zoopf...@...> wrote: > > 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 ); >
