PureBytes Links
Trading Reference Links
|
Graham, Dimitris, Paul, Ed and others, thanks to you experts I got
the looping stuff under control, at least sufficiently
for the code below of a standard deviation measurement with variable
periods. (Had been some previous discussion about in the forum but I
did not find a code.)
This code works (AFL StDev is added as a visual check) but this is
sooo-slooow, on my pc more than a few hundred bars loaded results in
an AB freeze. Certainly in view of my plan to combine this one with
other loops in a more complex code, I wonder if these kind of
executions are in fact feasible or perhaps I made a giant detour
somewhere in this code.
If you'd find the time to take a look and give some comments
I'd appreciate it. Thanks in advance.
-treliff
/* code start */
/*
MEAN is mean of data from bar n-1 till current bar.
VAR is variance of data from bar n-1 till current bar.
VR is variance of data of last n bars.
SD = sqrt(VR) is standard deviation of last n bars.
*/
// set array and periods
array = C ;
per = 12 ;
function MEAN(input,n)
{
result[n-1] = input[n-1] ;
for (i=n;i<BarCount;i++)
{
result[i] = ((i-n+1)/(i-n+2))*result[i-1] + (1/(i-n+2))*input[i] ;
}
return result;
}
function VAR(input,n)
{
result[n-1] = 0 ;
for (i=n;i<BarCount;i++)
{
myvar = MEAN(input,n);
result[i] = ((i-n+1)/(i-n+2))*result[i-1] + (1/(i-n+1))*(input[i]-
myvar[i])^2 ;
}
return result;
}
function VR(input,n)
{
for (i=n-1;i<BarCount;i++)
{
myvar = VAR(input,i-n+2);
result[i] = myvar[i] ;
}
return result;
}
function SD(input,n)
{
return sqrt(VR(input,n));
}
GraphXSpace = 3;
Plot(SD(array,per),"SD",colorBlack);
Plot(StDev(array,per),"StDev",colorBlue);
/* code end */
------------------------ 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/mOAaAA/3exGAA/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
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/
|