Standard Error Bands.afl
上传用户:shiqiang
上传日期:2009-06-12
资源大小:1289k
文件大小:2k
源码类别:

金融证券系统

开发平台:

Others

  1. //------------------------------------------------------------------------------
  2. //
  3. //  Formula Name:    Standard Error Bands
  4. //  Author/Uploader: jparent 
  5. //  E-mail:          
  6. //  Date/Time Added: 2002-02-24 22:14:38
  7. //  Origin:          
  8. //  Keywords:        
  9. //  Level:           medium
  10. //  Flags:           indicator
  11. //  Formula URL:     http://www.amibroker.com/library/formula.php?id=164
  12. //  Details URL:     http://www.amibroker.com/library/detail.php?id=164
  13. //
  14. //------------------------------------------------------------------------------
  15. //
  16. //  vbscript functions to calculate band top and bottom of your array
  17. //
  18. //------------------------------------------------------------------------------
  19. EnableScript("vbscript");
  20. <%
  21. function STEBandTop(V,n,d)
  22. dim result()
  23. redim result(UBound(V))
  24. q=EP(V,n)
  25. r=DV(V,n,d)
  26. for i=0 to UBound(V)
  27. result(i)=q(i)+r(i)
  28. next
  29. STEBandTop=result
  30. end function
  31. function STEBandBot(V,n,d)
  32. dim result()
  33. redim result(UBound(V))
  34. q=EP(V,n)
  35. r=DV(V,n,d)
  36. for i=0 to UBound(V)
  37. result(i)=q(i)-r(i)
  38. next
  39. STEBandBot=result
  40. end function
  41. function EP(V,n)
  42. Dim endpoint()
  43. redim endpoint(UBound(V))
  44. for i=0 to n-1
  45. x=x+(i+1)
  46. y=y+V(i)
  47. x2=x2+(i+1)^2
  48. xy=xy+(i+1)*V(i)
  49. endpoint(i)=V(i)
  50. next
  51. ya=y/n
  52. xa=x/n
  53. for i=n to UBound(V)
  54. x=x+n
  55. y=y+V(i)-V(i-n)
  56. x2=x2+(i+1)^2-(i-n+1)^2
  57. xy=xy+(i+1)*V(i)-(i-n+1)*V(i-n)
  58. ya=(ya*n+V(i)-V(i-n))/n
  59. xa=x/n
  60. t=(n*xy-x*y)/(n*x2-x^2)
  61. endpoint(i)=ya+t*(i-xa)
  62. next
  63. EP=endpoint
  64. end function
  65. function DV(V,n,d)
  66. Dim dev()
  67. redim dev(UBound(V))
  68. for i=0 to n-1
  69. x=x+(i+1)
  70. y=y+V(i)
  71. y2=y2+V(i)^2
  72. x2=x2+(i+1)^2
  73. xy=xy+(i+1)*V(i)
  74. dev(i)=0
  75. next
  76. for i=n to UBound(V)
  77. x=x+n
  78. y=y+V(i)-V(i-n)
  79. y2=y2+V(i)^2-V(i-n)^2
  80. x2=x2+(i+1)^2-(i-n+1)^2
  81. xy=xy+(i+1)*V(i)-(i-n+1)*V(i-n)
  82. t=xy-x*y/n
  83. dev(i)=d*sqr(((y2-y^2/n)-t^2/(x2-x^2/n))/(n-2))
  84. next
  85. DV=dev
  86. end function
  87. %>
  88. script=GetScriptObject();
  89. Graph0=script.STEBandTop(C,30,2);
  90. Graph1=C;
  91. Graph2=script.STEBandBot(C,30,2);
  92. Graph0Style = 1;
  93. Graph1Style = 1;
  94. Graph2Style = 1;