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

Re: [amibroker] Re: problem with "buyprice" and "shortprice" during backtesting



PureBytes Links

Trading Reference Links

It's a little cumbersome, but I needed to do this in one 
application.  You can pass in the variable names to a function and 
have it set those multiple variables' values by using script.  This 
is a little more flexible than dedicated gloabls.

Demo code of the technique is below for a SerVar() routine.

-- Bruce

//  Define the routine to set AFL variables
EnableScript("vbscript");
<%
sub setvar(varname, value)
	AFL.Var(varname) = Value
End sub
%>

Buy = Sell = 0;
a = 1;
b = 0;

//  Show setting an initialize and uninitialized variable
ab = GetScriptObject();
ab.setvar("b", 2);
ab.setvar("x", 3);

Filter = Status("lastbarinrange");
AddColumn(a, " A", 5.0);
AddColumn(b, " B", 5.0);
AddColumn(x, " X", 5.0);


--- In amibroker@xxxxxxxxxxxxxxx, "Dave Merrill" <dmerrill@xxxx> 
wrote:
> Say I have a function that I'd like to have return two arrays. As 
far as I
> know, there's no direct way to do that, but I'd like to confirm 
this for
> certain, since it would be very handy, and allow better coding 
practices.
> 
> The closest we can come I think is to set some variables outside the
> function, before calling it, so they're global, and have the 
function set
> them. What I don't like about this is that in contrast to some other
> languages, the names of those variables have to be hard coded 
inside the
> function. I'd much rather pass the names of the result arrays to 
use (or
> pointers to them) into the function.
> 
> For example:
> 
> ResultArrayOne = ResultArrayTwo = Null;
> function SetTwoArrays() {
> 	ResultArrayOne = C;
> 	ResultArrayTwo = ROC(C, 1);
> }
> 
> You have to use the variables named ResultArrayOne and 
ResultArrayTwo for
> this function to work correctly; those variables are what it sets, 
no matter
> what.
> 
> Do I have it right that this is the only way to get more than one 
array back
> from a function?
> 
> Dave Merrill


Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 

Yahoo! Groups Links

To visit your group on the web, go to:
 http://groups.yahoo.com/group/amibroker/

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/