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

金融证券系统

开发平台:

Others

  1. //------------------------------------------------------------------------------
  2. //
  3. //  Formula Name:    Automatic Fib Levels V.2
  4. //  Author/Uploader: Aron Pipa 
  5. //  E-mail:          
  6. //  Date/Time Added: 2006-03-23 20:52:16
  7. //  Origin:          
  8. //  Keywords:        
  9. //  Level:           medium
  10. //  Flags:           indicator
  11. //  Formula URL:     http://www.amibroker.com/library/formula.php?id=609
  12. //  Details URL:     http://www.amibroker.com/library/detail.php?id=609
  13. //
  14. //------------------------------------------------------------------------------
  15. //
  16. //  It is a little better than the previous one,
  17. //
  18. //  for points 1, 2, 3, on chart diplays retracements for 1-2 and 2-3.
  19. //
  20. //------------------------------------------------------------------------------
  21. /*---------------------------------------------------
  22. Automatic Fib Levels V.2
  23. Aron Pipa, March, 24, 2006
  24. --------------------------------------------------------*/
  25. shift =Param("Left Shift Chart ", 20, 10, 100, 2);
  26. Plot(C, "", 39, styleBar, Null, Null, -shift); 
  27. finishbar = BarCount;
  28. StartBar=SelectedValue(BarIndex())+shift ;
  29. bar = BarIndex();
  30. period = finishBar - StartBar;
  31. top =LastValue( HHV(H, period)) ; 
  32. bot =LastValue(LLV(L, period)) ; 
  33. retrace =0;
  34. x1=0;
  35. x2=0;
  36. x3=0;
  37. direction=0;
  38. Color=0;
  39. Line1 = Line2=Line3=Null;
  40. for (i =startbar; i<finishbar; i++)
  41. {
  42. if (H[i] ==top)
  43. {
  44. x1=bar[i];
  45. }
  46. if (L[i] ==bot)
  47. {
  48. x2=bar[i];
  49. }
  50. if(x1<x2) //direction down
  51. {
  52. direction=-1;
  53. Color= colorRed;
  54. retrace = LastValue( HHV(H, finishbar -x2)); 
  55. if(H[i] ==retrace)
  56. x3=bar[i];
  57. }
  58. else
  59. {
  60. direction=1;
  61. Color =colorGreen;
  62. retrace = LastValue(LLV(L, finishbar -x1)); 
  63. if(L[i] ==retrace)
  64. x3=bar[i];
  65. }
  66. }
  67. Line1 =LineArray(x1-shift, top, finishbar, top);
  68. Line2 =LineArray(x2-shift, bot, finishbar, bot);
  69. /*
  70. if(direction<0)
  71. trendline = LineArray(x2-shift, bot, x3-shift, retrace, 1);
  72. else
  73. trendline = LineArray(x1-shift, top, x3-shift, retrace, 1);
  74. Plot(trendline,"", color); 
  75. */
  76. // calculate fib levels I
  77. distance= abs(top-bot);
  78. fib1 =distance *0.236;
  79. fib2 =distance *0.382;
  80. fib3 =distance *0.5;
  81. fib4 =distance *0.618;
  82. // calculate fib levels II
  83. distance1 = IIf(direction<0,abs(retrace-bot),abs(top-retrace))  ;
  84. fib11 =distance1 *0.236;
  85. fib12 =distance1 *0.382;
  86. fib13 =distance1 *0.5;
  87. fib14 =distance1 *0.618;
  88. n = Param(" Fiblines depth %", 50, 10, 90, 2)/100; 
  89. Maxfib = finishbar-round(shift*n);
  90. fibline1 = LineArray(Maxfib, IIf(direction<0, bot+fib1, top-fib1), finishbar, IIf(direction<0, bot+fib1, top-fib1));
  91. fibline2 = LineArray(Maxfib, IIf(direction<0, bot+fib2, top-fib2), finishbar, IIf(direction<0, bot+fib2, top-fib2));
  92. fibline3 = LineArray(Maxfib, IIf(direction<0, bot+fib3, top-fib3), finishbar, IIf(direction<0, bot+fib3, top-fib3));
  93. fibline4 = LineArray(Maxfib, IIf(direction<0, bot+fib4, top-fib4), finishbar, IIf(direction<0, bot+fib4, top-fib4));
  94. Minfib = finishbar-shift+1;
  95. fibline11 = LineArray(Minfib, IIf(direction<0, retrace-fib11, retrace+fib11), Maxfib, IIf(direction<0, retrace-fib11, retrace+fib11));
  96. fibline12 = LineArray(Minfib, IIf(direction<0, retrace-fib12, retrace+fib12), Maxfib, IIf(direction<0, retrace-fib12, retrace+fib12));
  97. fibline13 = LineArray(Minfib, IIf(direction<0, retrace-fib13, retrace+fib13), Maxfib, IIf(direction<0, retrace-fib13, retrace+fib13));
  98. fibline14 = LineArray(Minfib, IIf(direction<0, retrace-fib14, retrace+fib14), Maxfib, IIf(direction<0, retrace-fib14, retrace+fib14));
  99. Line3=LineArray(x3 -shift ,retrace, maxfib, retrace);
  100. Color3=IIf(color==colorGreen, colorRed, colorGreen);
  101. if(startbar<finishbar)
  102. {
  103. Plot(Line1,"", color); 
  104. Plot(Line2,"", color);
  105. Plot(Line3,"", Color3);
  106. Plot(fibLine1,"", Color);
  107. Plot(fibLine2,"", Color);
  108. Plot(fibLine3,"", Color);
  109. Plot(fibLine4,"", Color);
  110. Plot(fibLine11,"", Color3);
  111. Plot(fibLine12,"", Color3);
  112. Plot(fibLine13,"", Color3);
  113. Plot(fibLine14,"", Color3);
  114. }
  115. else
  116. {
  117. Null;
  118. }
  119. Title= Name() +"  Auto Fib V.2";
  120.