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

[amibroker] Re: How to pass variables from AFL to embedded JScript?



PureBytes Links

Trading Reference Links

e.g.

AB = CreateObject("Broker.Application");
doc = AB.ActiveDocument;
doc.Name = "xyqst";       // instead of "EURUSD"


--- In amibroker@xxxxxxxxxxxxxxx, "ozzyapeman" <zoopfree@xxx> wrote:
>
> and since Dingo resurrected the topic, I also have a follow-up question...
> 
> If I change doc.name to junk that does not exist, like "xyqst", I do not get an error message. Shouldn't something like this generate an error? Otherwise if I make a typo, I'll never know if the actual doc was used for the operation.
> 
> 
> --- In amibroker@xxxxxxxxxxxxxxx, dingo <waledingo@> wrote:
> >
> > BUT, why didn't his use of AB.ActiveDocument.Name work?  Isn't it supposed
> > to according to how OLE object names are constructed?
> > 
> > 
> > d
> > 
> > 
> > On Wed, May 13, 2009 at 7:19 PM, Tomasz Janeczko <groups@>wrote:
> > 
> > >
> > >
> > > AB = CreateObject("Broker.Application");
> > > doc = AB.ActiveDocument;
> > > doc.Name = "EURUSD";
> > >
> > > Best regards,
> > > Tomasz Janeczko
> > > amibroker.com
> > >
> > >  ----- Original Message -----
> > > *From:* ozzyapeman <zoopfree@>
> > > *To:* amibroker@xxxxxxxxxxxxxxx
> > >   *Sent:* Thursday, May 14, 2009 12:36 AM
> > > *Subject:* [amibroker] Re: How to pass variables from AFL to embedded
> > > JScript?
> > >
> > > Bumping thread.
> > >
> > > Can anyone point out why the ActiveDocument switch  in the simple two lines
> > > below, generates a syntax error? I've used it many times before in JScript.
> > > But now that I am staying within AFL for OLE, that switch no longer works.
> > >
> > > I can't find anything in the manual that says the below should be any
> > > different.
> > >
> > >
> > > AB = CreateObject("Broker.Application");
> > >
> > > AB.ActiveDocument.Name <http://ab.activedocument.name/> = "EURUSD";
> > >
> > >
> > >
> > >
> > >
> > >
> > > --- In amibroker@xxxxxxxxxxxxxxx, "ozzyapeman" <zoopfree@> wrote:
> > > >
> > > > I've eliminated JScript and am instead calling objects from within AFL.
> > > > But now I am running into a syntax error on what used to be a routine
> > > > call in JScript: ActiveDocument.Name
> > > >
> > > > I get a non specific syntax error when trying to set
> > > > ActiveDocument.Name, as below. Anyone know why? Is that object treated
> > > > differently in AFL compared to JScript? I can set it fine in JScript
> > > > with the same code below, just switching the AB object to an ActiveX.
> > > >
> > > >
> > > > Database = "F:\\AB Databases\\MyDB";
> > > >
> > > > AB = CreateObject("Broker.Application");
> > > >
> > > > AA = AB.Analysis;
> > > >
> > > > AB.LoadDatabase( Database );
> > > >
> > > > AB.ActiveDocument.Name <http://ab.activedocument.name/> = "EURUSD";
> > > >
> > > >
> > > >
> > > >
> > > > --- In amibroker@xxxxxxxxxxxxxxx, "ozzyapeman" zoopfree@ wrote:
> > > > >
> > > > > Thanks for the detailed explanations Tomasz. I will rethink my
> > > > approach on this.
> > > > >
> > > > > Herman - Bruce beat me to it. I indeed use his code to check status of
> > > > the WF engine. It has proven very useful.
> > > > >
> > > > >
> > > > > --- In amibroker@xxxxxxxxxxxxxxx, "Tomasz Janeczko" groups@ wrote:
> > > > > >
> > > > > > Yes I agree, of course there are always few things that make scripts
> > > > handy, and
> > > > > > my approach is to leave doors open in the application, however, I
> > > > always
> > > > > > verbally discourage certain techniques, unless someone is very well
> > > > aware of consequences
> > > > > > and issues behind them.
> > > > > >
> > > > > > Best regards,
> > > > > > Tomasz Janeczko
> > > > > > amibroker.com
> > > > > > ----- Original Message -----
> > > > > > From: bruce1r
> > > > > > To: amibroker@xxxxxxxxxxxxxxx
> > > > > > Sent: Tuesday, May 12, 2009 3:10 PM
> > > > > > Subject: [amibroker] Re: How to pass variables from AFL to
> > > > embedded JScript?
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Tomasz -
> > > > > >
> > > > > > Just to make note of the some exceptions to your note about lack
> > > > of reasons to run JScript/VBScript, there are still a few non-mainstream
> > > > things that it makes possible. Just to list a few -
> > > > > >
> > > > > > 1.. Manipulation of COM arrays that allows a very fast way to
> > > > get AFL arrays into and out of Excel.
> > > > > >
> > > > > > 2.. Detecting the closing of a COM server via the On Error logic
> > > > in VBScript. Users have a bad habit of closing them and it can't be
> > > > detected and handled in AFL.
> > > > > > 3.. Getting lists of files and directories.
> > > > > > 4.. Sorting CSV lists in JScript.
> > > > > > etc....
> > > > > >
> > > > > > I don't like script much either, but I'm glad that you originally
> > > > did it. There are other ways of doing these and other tasks that I
> > > > usually prefer (DLL, COM DLL, etc.). But it is kind of like having a
> > > > carpenter having a hand plane in his toolbox. Power tools are better,
> > > > but on the rare occasion when a hand plane can be used, you are glad
> > > > that it is handy and that you have it.
> > > > > >
> > > > > > -- BruceR
> > > > > >
> > > > > >
> > > > > > --- In amibroker@xxxxxxxxxxxxxxx, "Tomasz Janeczko" <groups@>
> > > > wrote:
> > > > > > >
> > > > > > > I should add that embedding JScript/VBScript in formula is old
> > > > technology and was intended
> > > > > > > as a way to support looping in very old and dark ages when there
> > > > was no native looping in
> > > > > > > AFL. Now AFL allows everything that JScript/VBScript and more
> > > > plus it is 10x faster
> > > > > > > and there is absolutely NO reason to use JScript/VBScript
> > > > anymore. It is left here ONLY
> > > > > > > to allow run legacy formulas.
> > > > > > > No new code should use JScript/VBScript.
> > > > > > >
> > > > > > > Second thing is that OLE AUTOMATION is intended to be used only
> > > > FROM OUTSIDE
> > > > > > > of AmiBroker. Using it within formulas from inside AB, may
> > > > inevitably lead to "chicken and egg" (circular reference) problem
> > > > > > > and is not supported.
> > > > > > > It is important that OLE automation was always thought by
> > > > Microsoft as a method of controlling ONE application
> > > > > > > from ANOTHER application.
> > > > > > >
> > > > > > > Best regards,
> > > > > > > Tomasz Janeczko
> > > > > > > amibroker.com
> > > > > > > ----- Original Message -----
> > > > > > > From: Tomasz Janeczko
> > > > > > > To: amibroker@xxxxxxxxxxxxxxx
> > > > > > > Sent: Tuesday, May 12, 2009 9:41 AM
> > > > > > > Subject: Re: [amibroker] Re: How to pass variables from AFL to
> > > > embedded JScript?
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Hello,
> > > > > > >
> > > > > > > No you are not allowed to run scripting host code within
> > > > conditional expression.
> > > > > > >
> > > > > > > The Microsoft SCRIPTING host is INDEPENDENT, i.e. it executes on
> > > > its own,
> > > > > > > in parallel and its "global" parts are simply extracted from the
> > > > formula and run unconditionally
> > > > > > > before actual AFL execution.
> > > > > > >
> > > > > > > If you need to call something in script conditionally you have
> > > > two choices:
> > > > > > > a) either write condition in JScript/VBScript
> > > > > > > OR
> > > > > > > b) write a FUNCTION in JScript/VBScript and call that function
> > > > conditionally from AFL level
> > > > > > > as shown below:
> > > > > > >
> > > > > > >
> > > > > > > EnableScript( "jscript" );
> > > > > > > <%
> > > > > > > // NO global code, only function definition
> > > > > > >
> > > > > > > function DoTheJob()
> > > > > > > {
> > > > > > > AB = new ActiveXObject( "Broker.Application" );
> > > > > > > AA = AB.Analysis;
> > > > > > > }
> > > > > > >
> > > > > > > %>
> > > > > > >
> > > > > > > Test = 4;
> > > > > > > if( Test == 4 )
> > > > > > > {
> > > > > > > scr = GetScriptObject();
> > > > > > > scr.DoTheJob();
> > > > > > > }
> > > > > > >
> > > > > > > Best regards,
> > > > > > > Tomasz Janeczko
> > > > > > > amibroker.com
> > > > > > > ----- Original Message -----
> > > > > > > From: ozzyapeman
> > > > > > > To: amibroker@xxxxxxxxxxxxxxx
> > > > > > > Sent: Tuesday, May 12, 2009 7:36 AM
> > > > > > > Subject: [amibroker] Re: How to pass variables from AFL to
> > > > embedded JScript?
> > > > > > >
> > > > > > >
> > > > > > > Okay, this is bizarre. I am testing out some embedded JScript
> > > > for a related application to what I posted earlier. This one is not
> > > > happening within the AA, but is nonetheless still inside an AFL.
> > > > > > >
> > > > > > > The following simple code is fine, and does not generate a
> > > > syntax error:
> > > > > > >
> > > > > > > //Test = 4;
> > > > > > >
> > > > > > > //if ( Test == 4 )
> > > > > > > //{
> > > > > > >
> > > > > > > EnableScript( "jscript" );
> > > > > > > <%
> > > > > > >
> > > > > > > AB = new ActiveXObject( "Broker.Application" );
> > > > > > > AA = AB.Analysis;
> > > > > > >
> > > > > > > %>
> > > > > > >
> > > > > > > //}
> > > > > > >
> > > > > > >
> > > > > > > However, if I uncomment all the "//" I get a syntax error.
> > > > > > >
> > > > > > > Are we not allowed to call a JScript inside an IF block? If not,
> > > > why the heck not? And if we are allowed, why would it be generating a
> > > > syntax error in this simple case?
> > > > > > >
> > > > > > > The error I get is on the "<%" --> probably missing semi colon
> > > > on previous line.
> > > > > > >
> > > > > > > But the semi colon is clearly there.
> > > > > > >
> > > > > > > Anyone's two cents appreciated.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > --- In amibroker@xxxxxxxxxxxxxxx, "ozzyapeman" zoopfree@ wrote:
> > > > > > > >
> > > > > > > > Thanks for that tip.
> > > > > > > >
> > > > > > > > Guess I will have to write a WF type routine in JScript and
> > > > call each optimize individually, from outside AA.
> > > > > > > >
> > > > > > > >
> > > > > > > > --- In amibroker@xxxxxxxxxxxxxxx, "Tomasz Janeczko" groups@
> > > > wrote:
> > > > > > > > >
> > > > > > > > > During any AA operation in progress, you must not
> > > > > > > > > use Analysis object to start another AA operation
> > > > > > > > > (because it is infinite nesting)
> > > > > > > > >
> > > > > > > > > Analysis object may only be used from OUTSIDE
> > > > > > > > > of AA.
> > > > > > > > >
> > > > > > > > > To run "suboptimization" use THE ONLY supported
> > > > > > > > > way, i.e. Optimizer API (see optimizer.html file in the ADK
> > > > subfolder).
> > > > > > > > >
> > > > > > > > > Best regards,
> > > > > > > > > Tomasz Janeczko
> > > > > > > > > amibroker.com
> > > > > > > > > ----- Original Message -----
> > > > > > > > > From: "ozzyapeman" zoopfree@
> > > > > > > > > To: amibroker@xxxxxxxxxxxxxxx
> > > > > > > > > Sent: Tuesday, May 12, 2009 3:11 AM
> > > > > > > > > Subject: [amibroker] Re: How to pass variables from AFL to
> > > > embedded JScript?
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > > And if there is no way to pass variables directly from AFL
> > > > to JScript,
> > > > > > > > > > can I first fput the AFL vars to some kind of log file,
> > > > and then is
> > > > > > > > > > there a command in JScript that can pull those vars to use
> > > > for the
> > > > > > > > > > Dates?
> > > > > > > > > >
> > > > > > > > > > I can also use VBscript, if that makes any difference. I'm
> > > > just not all
> > > > > > > > > > that knowledgeable about either J or VB scripts.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > --- In amibroker@xxxxxxxxxxxxxxx, "ozzyapeman" <zoopfree@>
> > > > wrote:
> > > > > > > > > >>
> > > > > > > > > >> Hello, hoping someone can help out here. During a
> > > > Walk-Forward test, I
> > > > > > > > > >> am trying to pass From and To dates from the WF engine
> > > > into an
> > > > > > > > > > embedded
> > > > > > > > > >> JScript. I essentially want to do a "sub-optimization" as
> > > > part of the
> > > > > > > > > >> backtest portion of the WF test. However, it seems that I
> > > > cannot pass
> > > > > > > > > >> variables from the AFL to the JScript.
> > > > > > > > > >>
> > > > > > > > > >> Is there any way to pass the From and To dates into the
> > > > JScript? Below
> > > > > > > > > >> is what I have. It generates an 'undefined source' error
> > > > for these
> > > > > > > > > >> lines:
> > > > > > > > > >>
> > > > > > > > > >>
> > > > > > > > > >> AA.RangeFromDate = FromDateStr;
> > > > > > > > > >> AA.RangeToDate = ToDateStr;
> > > > > > > > > >>
> > > > > > > > > >>
> > > > > > > > > >> Here is the AFL with embedded JScript:
> > > > > > > > > >>
> > > > > > > > > >> FromDateNum = Status( "rangefromdate" );
> > > > > > > > > >> ToDateNum = Status( "rangetodate" );
> > > > > > > > > >>
> > > > > > > > > >> FromDate = DateTimeConvert( 2, FromDateNum );
> > > > > > > > > >> ToDate = DateTimeConvert( 2, ToDateNum );
> > > > > > > > > >>
> > > > > > > > > >> FromDateStr = DateTimeToStr( FromDate );
> > > > > > > > > >> ToDateStr = DateTimeToStr( ToDate );
> > > > > > > > > >>
> > > > > > > > > >>
> > > > > > > > > >> EnableScript( "jscript" );
> > > > > > > > > >> <%
> > > > > > > > > >>
> > > > > > > > > >> Formula = "F:\\SomeFormula.afl";
> > > > > > > > > >> Database = "F:\\AB Databases\\MyIB";
> > > > > > > > > >> Settings = "F:\\Some Settings.ABS";
> > > > > > > > > >>
> > > > > > > > > >> AB = new ActiveXObject( "Broker.Application" );
> > > > > > > > > >> AA = AB.Analysis;
> > > > > > > > > >>
> > > > > > > > > >> AB.LoadDatabase( Database );
> > > > > > > > > >> AB.ActiveDocument.Name <http://ab.activedocument.name/> =
> > > "EURUSD";
> > > > > > > > > >> AA.LoadFormula( Formula );
> > > > > > > > > >> AA.LoadSettings( Settings);
> > > > > > > > > >> AA.ApplyTo = 1;
> > > > > > > > > >> AA.RangeMode = 3;
> > > > > > > > > >> AA.RangeFromDate = FromDateStr; // * ERROR *
> > > > > > > > > >> AA.RangeToDate = ToDateStr;
> > > > > > > > > >> AA.Optimize( 0 );
> > > > > > > > > >>
> > > > > > > > > >> AA.Export ( "F:\\TestReport1.html" );
> > > > > > > > > >>
> > > > > > > > > >> %>
> > > > > > > > > >>
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > ------------------------------------
> > > > > > > > > >
> > > > > > > > > > **** IMPORTANT PLEASE READ ****
> > > > > > > > > > This group is for the discussion between users only.
> > > > > > > > > > This is *NOT* technical support channel.
> > > > > > > > > >
> > > > > > > > > > TO GET TECHNICAL SUPPORT send an e-mail directly to
> > > > > > > > > > SUPPORT {at} amibroker.com
> > > > > > > > > >
> > > > > > > > > > TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
> > > > > > > > > > http://www.amibroker.com/feedback/
> > > > > > > > > > (submissions sent via other channels won't be considered)
> > > > > > > > > >
> > > > > > > > > > For NEW RELEASE ANNOUNCEMENTS and other news always check
> > > > DEVLOG:
> > > > > > > > > > http://www.amibroker.com/devlog/
> > > > > > > > > >
> > > > > > > > > > Yahoo! Groups Links
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> > >
> > >
> > > 
> > >
> >
>




------------------------------------

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

TO GET TECHNICAL SUPPORT send an e-mail directly to 
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

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/