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

Re: [amibroker] Re: VB script i give up what is wrong with this code



PureBytes Links

Trading Reference Links


Hello,
 
The formula does not plot anything exceptflat 
line because your formula
calculates SINGLE value not an array.
Please take a look at the sample indicator I 
presented in scripting documentation:
It generates an ARRAY of results. This isthe main 
difference between writing indicators
in pure AFL that processes arrays 
internally that makes writing indicators A LOT easier.
On the other hand scripting in AFL gives 
you more flexibility but you must iterate
thru and generate result arrays 
by yourself.  
EnableScript("jscript");
<%
close = VBArray( AFL( "close" ) ).toArray();output = new Array();// initialize first element
output[ 0 ] = close[ 0 ];// perform the loop thatcalculates exponential moving average
factor = 0.05;

for( i = 1; i < close.length; i++ )
{
output[ i ] = factor * close[ i ] + (1 - factor) * output[ i - 1 ];
}
AFL.Var("graph0") = close;
AFL.Var("graph1") = output;%>
WriteVal( graph1 ); 
Best regards,Tomasz Janeczko===============AmiBroker - the 
comprehensive share manager.<A 
href="">http://www.amibroker.com
<BLOCKQUOTE 
>
----- Original Message ----- 
<DIV 
>From: 
<A title=nickhere@xxxx 
href="">nickhere@xxxx 
To: <A title=amibroker@xxxxxxxxxxxxx 
href="">amibroker@xxxxxxxxxxxxxxx 
Sent: Friday, June 15, 2001 11:23 
PM
Subject: [amibroker] Re: VB script i 
give up what is wrong with this code
I did find out the values is return ok ir just not 
plotting--- In <A 
href="">amibroker@xxxx..., <A 
href="">nickhere@xxxx... wrote:> I know it built 
in  but this is special.> it not going to be a  normal 
bollenger.> > > > > --- In <A 
href="">amibroker@xxxx..., "Tomasz Janeczko" <<A 
href="">tj@xxxx...> wrote:> > Hi,> > 
> > There is no need to write bollinger bands using 
scripting> > - they are BUILT-IN into AFL.> > a.. > 
>   1.. BBANDBOT > 
>         1.. SYNTAX > 
>      bbandbot( ARRAY, periods = 15, width= 2 ) 
> >       RETURNS ARRAY > 
>       FUNCTION  Calculates the bottom 
Bollinger Band of ARRAY > shifted down width standard deviations (using 
periods averaging > range ). > 
>       EXAMPLE bbandbot( close, 10, 2 ) 
> >       SEE ALSO   
> > > > a.. > >   1.. BBANDTOP 
> >         1.. SYNTAX 
> >      bbandtop( ARRAY, periods = 15, 
width = 2 ) > >       RETURNS ARRAY 
> >       FUNCTION  Calculates 
the bottom Bollinger Band of ARRAY > shifted upwidth standard 
deviations (using periods averaging range ). > 
>       EXAMPLE bbandtop( close, 10, 2 ) 
> >       SEE ALSO   
> > > > Best regards,> > Tomasz Janeczko> 
> ===============> > AmiBroker- the comprehensive share 
manager.> > <A 
href="">http://www.amibroker.com> > 
> >   ----- Original Message ----- > 
>   From: nickhere@xxxx > >   To: 
amibroker@xxxx > >   Sent: Friday, June 15, 2001 9:09 
PM> >   Subject: [amibroker] VB script i give up whatis 
wrong with this > code> > > > > 
>   This code return nothing> > > > > 
>   EnableScript("vbscript");> >   
<%> >   price = AFL ( "high" )> >   
bb=bbband(price,9,2)> > > >   Function 
bbband(price, length, StandardDev)> >   bbband = 
Average(price, length) + (StandardDev * Stddev(price, > 
>   length))> >   End Function> > 
> >   Function Average(price, length)> 
>   Sum = 0> >   Counter = 0> 
>       For Counter = 0 To length - 1> 
>       Sum = Sum + price(Counter)> 
>       Next> >   If 
length > 0 Then> >   Average = Sum / length> 
>   Else> >   Average = 0> 
>   End If> >   End Function> > 
> >   Function Stddev(price, length)> 
>   SumSqr = 0> >   Avg = 0> 
>   Counter = 0> >   If length <> 0 
Then> >      Avg = Average(price, 
length)> >      SumSqr = 0> 
>      For Counter = 0 To length - 1> 
>        SumSqr = SumSqr + 
(price(Counter) - Avg) * (price(Counter) - > Avg)> 
>        Next> 
>      Stddev = Sqr(SumSqr / length)> 
>   Else> >      Stddev = 
0> >      End If> >   
End Function> > > >   AFL.Var("graph1") = 
bb> >   %>> >   WriteVal( graph1 
);> > > > > > > > > 
>         Yahoo! Groups Sponsor 
> > > >         
Click for Details > >        
> > > >   Your use of Yahoo! Groups is subject 
to the Yahoo! Terms of > Service.Your 
use of Yahoo! Groups is subject to the <A 
href="">Yahoo! Terms of Service.