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

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



PureBytes Links

Trading Reference Links



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 -----
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
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@xxx> 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 _vbscript_s.
> > >
> > >
> > >
> > > --- 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 = "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/





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

__,_._,___