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

RE: [amibroker] OT: monitor query



PureBytes Links

Trading Reference Links

treliff,
If you want the analytic StDev() function, keep it simple
n=10; f=2;
Qn=Sum(C^2,n);
Sn=Sum(C,n);
Kn=(1/n)*sqrt(n*Qn-Sn^2);
Plot(Kn,"Analytic StDev",colorBlack,1);
Plot(StDev(C,n),"Built-in StDev",colorRed,8);
The reason to use the above analytic formula is that built-in StDev() 
does not accept variable n. But, the built-in Sum() *does* !!
So, the above analytic form will accept variable n.
Example

n=10+Cum(1)%5;//n varies from 10 to 14 
Qn=Sum(C^2,n);
Sn=Sum(C,n);
Kn=(1/n)*sqrt(n*Qn-Sn^2);
Plot(Kn,"Analytic StDev",colorBlack,1);

I hope it is clear.
Dimitris Tsokakis
--- In amibroker@xxxxxxxxxxxxxxx, "treliff" <treliff@xxxx> wrote:
> 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 */



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/