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

Re: [amibroker] VBscript questions



PureBytes Links

Trading Reference Links

Hello,

buy/seel/short/cover ARE arrays.

You should create temporary array variables inside
scripting part and assign at the end of the script 

<%
' make a copy of close array
' (it is faster than Dim / Redim())
Buy = Close

For bar = 0 To UpperBound( Close ) 
If condition1 and Direction <> 1 then
Buy( bar ) = ... ' assign array element
End If
Next

' assign at the end of the script part
AFL("buy") = Buy

%>

Example is included in the User's Guide:


EnableScript("VBScript");
hh = HHV( close, 250 );
// buy when prices reaches a new high
buy = Close == HHV( close, 250 ); 

// ensure that sell is an array, 
// sell = 0 would set the type to numbersell = buy; 

<%
close = AFL("close")
buy = AFL( "buy" )
sell = AFL("sell")
' this variable holds last buying price
' if it is zero it means that no trade is open
lastbuyprice = 0
' iterate along the array
for i = 0 to UBound( close )
sell( i ) = 0
' Remove Buy signals if trade was already initiated
if( lastbuyprice > 0 ) then
buy( i ) = 0
end if
' if there is no open trade and buy signal occurs 
' get the buying price
if ( lastbuyprice = 0 ) AND (buy( i ) = 1) then
lastbuyprice = close( i )
end if
' if trade is open and sell condition is valid 
' generate sell signal
' and close the trade
if (lastbuyprice >0 ) AND ( close( i ) > ( 1.1 * lastbuyprice ) ) then
sell( i ) = 1
lastbuyprice = 0
end if
next
AFL("buy") = buy
AFL("sell") = sell
%>
buy = buy;

Best regards,
Tomasz Janeczko
amibroker.com
----- Original Message ----- 
From: "o_2_b_sean" <seanrmartinez@xxxx>
To: <amibroker@xxxxxxxxxxxxxxx>
Sent: Friday, October 04, 2002 8:19 PM
Subject: [amibroker] VBscript questions


> 
> Since I am coming to AB after using EasyLanguage and I find myself 
> wanting to write most of my code in VBscript so that I can use the 
> familiar IF...THEN FOR...NEXT type of coding structures. However, I 
> am having a bit of a hard time understanding how to activate the 
> buy/sell/short/cover variables from within the script. Can anyone 
> help? The buy/sell/short/cover vars are not arrays like the 
> close/high/open/low are right? So I don't need parentheses as in AFL
> ("Close()"), right?
> 
> Why doesn't the following work? I find the ExRem function a bit hard 
> to use right, so this is my VBscript approach:
> 
> If condition1 AND Direction <> 1 then
> AFL("Buy") = False
> AFL("Cover") = False
> AFL("Sell") = True
> AFL("Short") = True
> Direction = 1
> end if
> 
> - Sean
> 
> 
> 
> 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 
> 
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 
> 
> 
>