you can NOT run optimizations nor backtests from inside an AFL. You MUST run them from external scripts.
You'd do a whole lot better searching for examples of jscripts in the email archives here as that is where all of the OLE examples relating to Amibroker are. d On Thu, Dec 18, 2008 at 9:57 PM, ozzyapeman <[email protected]> wrote: > Thanks, Mike. That's a great help. > > Yes, there was some junk in my original code. I cobbled it together > from other examples found on this group, and I didn't quite know what > I was doing. > > Thanks also for letting me know of the ability to run from the command > line window. I had not even thought of that, or was aware it could > work that way. Do you have any online Jscript tutorials that you could > recommend, specifically geared towards automation? I found some > general purpose tutorials, but want to focus just on automating stuff > like this. > > I am still a bit confused why your code runs fine (all 100 opt steps) > when run from the command line, but only does a single opt step when > run as an AFL that simply calls the identical jscript routine. > > > --- In [email protected], "Mike" <sfclimb...@...> wrote: > > > > Are you particularly looking to run the first script from AmiBroker? > > Since the whole thing is intended to just be a batch starter, you can > > just write it as a vanilla JScript file and run it directly from the > > command line. > > > > Just rename it to have a .js file extension (e.g. runami.js) then run > > it from the command line using: > > > > wscript runami.js > > > > That being said. There are a few issues with your original post. > > 1. It's not clear what you are trying to do with the Stocks object and > > your usage of Document. I'm assuming that you are just trying to set > > the active document as shown in my sample below. > > > > 2. Generally you either want to Optimize, or to Backtest. Not clear > > why you are trying to do both. > > > > The following .ps file works, runs all 100 optimizations. Your sample > > probably does to, but then immediately clobbers the result with a > > single backtest! > > > > Mike > > > > > > database = "C:\\Program Files\\Amibroker\\Data"; > > formula_1 = "C:\\Simple MA Cross.afl"; > > > > AB = new ActiveXObject( "Broker.Application" ); > > AA = AB.Analysis; > > > > AB.LoadDatabase( database ); > > AB.ActiveDocument.Name <http://ab.activedocument.name/> = "^DJI"; > // Set ^DJI as active > > document > > > > 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 > > > > > > --- In [email protected], "ozzyapeman" <zoopfree@> wrote: > > > > > > To add to my confusion, sometimes the below code does produce syntax > > > errors when applied. Other times it runs smoothly (albeit with a > > > single optimization step). I'm not doing anything different, so I > > have > > > no idea why it fluctuates. > > > > > > > > > --- In [email protected], "ozzyapeman" <zoopfree@> wrote: > > > > > > > > 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" <zoopfree@> 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 ); > > > > > > > > > > > > > > > > > > ------------------------------------ > > **** 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 > > ********************************* > Yahoo! Groups Links > > > >
