PureBytes Links
Trading Reference Links
|
Hello,
The problem is that you have the same name for
FUNCTION and variable inside function.
If your function has the name of eVWMA you must
not use the variable of the same name. This is
not visual basic. Identifiers for functions and variables
defined inside functions must be different.
To fix your code it is enough to change the function name
from eVWMA to say feVWMA to avoid identifier clash.
EnableScript("jscript");
<%
function feVWMA( x, y, f0)
{
x = VBArray( x ).toArray();
y = VBArray( y ).toArray();
eVWMA = new Array();
j = 0;
for( i = 1; i < y.length; i++ )
{
if (y[ i ] > j)
j = y[ i ];
}
// initialize the first element of result array
eVWMA[ 0 ] = x[ 0 ];
for( i = 1; i < x.length; i++ )
{
eVWMA[ i ] = (f0 * j - y[ i ]) * eVWMA[ i - 1 ] + y[ i ] * x[ i ];
eVWMA[ i ] = eVWMA[ i ] / ( f0 * j);
}
return eVWMA;
}
%>
script = GetScriptObject();
sharesFloat = Param("Shares Floating", 2, 0, 10, 0.5 );
Graph0 = Close;
Graph0Color = colorBlack;
Graph0Style = 128;
Graph1 = script.feVWMA( Close, Volume, sharesFloat);
evwma = script.feVWMA( Close, Volume, sharesFloat);
Graph2 = EMA(evwma, 8);
Graph2Color = colorYellow;
Graph2Style = styleLine;
BUT... there is a much better, easier, shorter and faster alternative:
use NATIVE AFL looping and functions (AB version 4.40 required):
function feVWMA( x, y, f0 )
{
j = 0;
for( i = 1; i < BarCount; i++ )
{
if (y[ i ] > j)
j = y[ i ];
}
// initialize the first element of result array
eVWMA[ 0 ] = x[ 0 ];
for( i = 1; i < BarCount; i++ )
{
eVWMA[ i ] = (f0 * j - y[ i ]) * eVWMA[ i - 1 ] + y[ i ] * x[ i ];
eVWMA[ i ] = eVWMA[ i ] / ( f0 * j);
}
return eVWMA;
}
sharesFloat = Param("Shares Floating", 2, 0, 10, 0.5 );
Graph0 = Close;
Graph0Color = colorBlack;
Graph0Style = 128;
Graph1 = feVWMA( Close, Volume, sharesFloat);
Graph2 = EMA(feVWMA( Close, Volume, sharesFloat), 8);
Graph2Color = colorYellow;
Graph2Style = styleLine;
Best regards,
Tomasz Janeczko
amibroker.com
----- Original Message -----
From: "rsmith_den" <rls_jls@xxxxxxxxxxxxxxxx>
To: <amibroker@xxxxxxxxxxxxxxx>
Sent: Friday, August 22, 2003 6:47 PM
Subject: [amibroker] Can't get EMA from jscript array .
> Hello,
>
> Today, I am writing an AFL that contains some jscript. The AFL works
> fine up to the point I want to get the EMA of the evwma. The evwma is
> the returned output array of the jscript. Below is the code and the
> error:
>
> EnableScript("jscript");
>
> <%
> function eVWMA( x, y, f0)
> {
>
> x = VBArray( x ).toArray();
>
> y = VBArray( y ).toArray();
>
> eVWMA = new Array();
>
> j = 0;
> for( i = 1; i < y.length; i++ )
> {
> if (y[ i ] > j)
> j = y[ i ];
> }
>
> // initialize the first element of result array
> eVWMA[ 0 ] = x[ 0 ];
>
> for( i = 1; i < x.length; i++ )
> {
> eVWMA[ i ] = (f0 * j - y[ i ]) * eVWMA[ i - 1 ] + y[ i ] * x[ i ];
>
> eVWMA[ i ] = eVWMA[ i ] / ( f0 * j);
> }
>
> return eVWMA;
>
> }
>
> %>
>
> script = GetScriptObject();
>
> sharesFloat = Param("Shares Floating", 2, 0, 10, 0.5 );
>
> Graph0 = Close;
> Graph0Color = colorBlack;
> Graph0Style = 128;
> Graph1 = script.eVWMA( Close, Volume, sharesFloat);
>
> // evwma = script.eVWMA( Close, Volume, sharesFloat);
>
> // Graph2 = EMA(evwma, 8);
> // Graph2Color = colorYellow;
> // Graph2Style = styleLine;
>
> The erroneous code has been commented out. How can I get EMA( evwma,
> 8 ) ?
>
> TIA RS
>
>
>
>
> 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
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for Your HP, Epson, Canon or Lexmark
Printer at Myinks.com. Free s/h on orders $50 or more to the US & Canada. http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/l.m7sD/LIdGAA/qnsNAA/GHeqlB/TM
---------------------------------------------------------------------~->
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
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
|