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

Re: 'remebering' a value



PureBytes Links

Trading Reference Links

Hi Amiability,

You need to ensure that Sell is an array before entering VBScript 
(have a look at the second comment in TJ's sample program). Being a 
newbie myself, I wasnt sure how to do this, so I simply entered

Sell = Buy;

as a 'template' to force it into array form (Sell = Close; would also 
have worked). It makes no difference, because the Sell array is reset 
in the VBscript anyway.

Perhaps there is more elegant method to ensure Sell is an array, but 
this will work anyway.

Cheers

--- In amibroker@xxxx, "amiabilityy" <amiabilityy@xxxx> wrote:
> hi tomasz,
> 
> i am interested in the same type of prob as what the previous 
poster 
> posted.
> 
> Why does your code give me error messages.
> 
> 
> Source: Microsoft VBScript runtime error
> Line: 18 Char: 1
> Error: 0 - Type mismatch: 'Sell'
> 
> it happens at this line in the code of youre formula below.
> for i = 0 to UBound( Close )
> Sell( i ) = 0
> 
> thanks pete.
> 
> 
> 
> 
> 
> 
> --- In amibroker@xxxx, "Tomasz Janeczko" <amibroker@xxxx> wrote:
> > Hello,
> > 
> > A very similar example is included in the User's Guide: AmiBroker 
> Formula Language "AFL Scripting Host":
> > [code]
> > 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;
> > 
> > [/code]
> > 
> > Best regards,
> > Tomasz Janeczko
> > amibroker.com
> > ----- Original Message ----- 
> > From: "sidleysh" <steves@xxxx>
> > To: <amibroker@xxxx>
> > Sent: Thursday, July 11, 2002 10:29 AM
> > Subject: [amibroker] 'remebering' a value
> > 
> > 
> > > I have a simple AFL problem (as a newbie), which is 
> straightforward 
> > > in traditional languages, but I cant seem to find a solution in 
> AFL 
> > > 
> > > 1) I want to generate a buy when condition is true. 
> > > 2) After that I want to buy every time the closing price is x% 
> higher 
> > > than the price of my previous buy. 
> > > 
> > > Because I cant 'store' the price of the previous buy, I do not 
> how to 
> > > do this. 
> > > 
> > > Any ideas? 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > Your use of Yahoo! Groups is subject to 
> http://docs.yahoo.com/info/terms/ 
> > > 
> > > 
> > >