> 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 = "^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
amibroker@xxxxxxxxxxxxxxx, "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
amibroker@xxxxxxxxxxxxxxx, "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
amibroker@xxxxxxxxxxxxxxx, "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
<*> 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/