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

金融证券系统

开发平台:

Others

  1. //------------------------------------------------------------------------------
  2. //
  3. //  Formula Name:    Automatic Fib Levels
  4. //  Author/Uploader: Aron Pipa 
  5. //  E-mail:          
  6. //  Date/Time Added: 2005-12-11 09:02:48
  7. //  Origin:          
  8. //  Keywords:        
  9. //  Level:           basic
  10. //  Flags:           indicator
  11. //  Formula URL:     http://www.amibroker.com/library/formula.php?id=573
  12. //  Details URL:     http://www.amibroker.com/library/detail.php?id=573
  13. //
  14. //------------------------------------------------------------------------------
  15. //
  16. //  Plots automatically Fib leveles.
  17. //
  18. //------------------------------------------------------------------------------
  19. /*---------------------------------------------------
  20. Automatic Fib Levels
  21. Aron Pipa, December, 11, 2005
  22. --------------------------------------------------------*/
  23. Plot(C,"", colorWhite,styleCandle);
  24. // Get values for fib levels 
  25. StartBar=SelectedValue(BarIndex());
  26. FinishBar = EndValue( BarIndex() ); 
  27. i = startbar;
  28. period = FinishBar - StartBar;
  29. Lo =LLV(L,period);
  30. Hi = HHV(H,period);
  31. Line0 = 0; 
  32. Line1 = 0;
  33. Line2 = 0;
  34. Line3 = 0;
  35. Line4= 0;
  36. Line100 = 0;
  37. for( i = startbar; i < finishbar; i++ )
  38. {
  39. if(EndValue(C)<SelectedValue(C))
  40. {
  41. Line0  = EndValue(Lo);
  42. Line100 = EndValue(Hi);
  43. Line1 = Line0 + abs(Line100-Line0)*0.236;
  44. Line2 = Line0 + abs(Line100-Line0)*0.382;
  45. Line3 = Line0 + abs(Line100-Line0)*0.5;
  46. Line4 = Line0 + abs(Line100-Line0)*0.618;
  47. }
  48. else
  49. {
  50. Line100  = EndValue(Lo);
  51. Line0 = EndValue(Hi);
  52. Line1 =Line0 - abs(Line100-Line0)*0.236;
  53. Line2 = Line0 - abs(Line100-Line0)*0.382;
  54. Line3 = Line0 - abs(Line100-Line0)*0.5;
  55. Line4 = Line0 - abs(Line100-Line0)*0.618;
  56. }
  57. }
  58. // external fib lines begining fom selecetdbarindex()
  59. fib0= LineArray(startbar, Line0, finishbar, Line0, 0, 1);
  60. fib100 = LineArray(startbar, Line100, finishbar, Line100, 0, 1);
  61. // depth of middle lines
  62. n= round((finishbar-startbar)/2);
  63. // middle lines
  64. fib1= LineArray((finishbar-n), Line1, finishbar, Line1, 0, 1);
  65. fib2= LineArray((finishbar-n), Line2, finishbar, Line2, 0, 1);
  66. fib3= LineArray((finishbar-n), Line3, finishbar, Line3, 0, 1);
  67. fib4= LineArray((finishbar-n), Line4, finishbar, Line4, 0, 1);
  68. Plot(fib0,"", colorWhite);
  69. Plot(fib100,"", colorRed);
  70. Plot(fib1,"", colorGrey50);
  71. Plot(fib2,"", colorGrey50);
  72. Plot(fib3,"", colorOrange);
  73. Plot(fib4,"", colorGrey50);
  74. Title = Name() + " -  FIB LEVELS ";