ZigZag filter rewrited from scratch in AFL.afl
上传用户:shiqiang
上传日期:2009-06-12
资源大小:1289k
文件大小:3k
源码类别:

金融证券系统

开发平台:

Others

  1. //------------------------------------------------------------------------------
  2. //
  3. //  Formula Name:    ZigZag filter rewrited from scratch in AFL
  4. //  Author/Uploader: Tintin92 
  5. //  E-mail:          
  6. //  Date/Time Added: 2004-12-28 17:42:50
  7. //  Origin:          
  8. //  Keywords:        
  9. //  Level:           medium
  10. //  Flags:           indicator
  11. //  Formula URL:     http://www.amibroker.com/library/formula.php?id=417
  12. //  Details URL:     http://www.amibroker.com/library/detail.php?id=417
  13. //
  14. //------------------------------------------------------------------------------
  15. //
  16. //  ZigZag filter rewrited from scratch in AFL
  17. //
  18. //------------------------------------------------------------------------------
  19. _SECTION_BEGIN("Reversal");
  20. Reversal = Param( _DEFAULT_NAME(), 01.0,0.01,20,0.01);
  21. _SECTION_END();
  22. ZigZArray = Avg;
  23. ZigZArray = Null;
  24. ValFromPro=0;
  25. ValToPro=0;
  26. ValRead=0;
  27. BarFromPro=0;
  28. BarToPro=0;
  29. BarRead=0;
  30. ProcessUndef = 10;
  31. ProcessIncrease = 11;
  32. ProcessDecrease = 12;
  33. Process = ProcessUndef;
  34. ValFromPro=Avg[0];
  35. ValToPro=Avg[0];
  36. BarFromPro=0;
  37. BarToPro=0;
  38. BarRead=0;
  39. function FillLine( startbar, startval, endbar, endval )
  40. {
  41. for( j = startbar; j <= endbar; j++ )
  42. {
  43. ZigZArray[ j ] = startval + (( j - startbar) * (endval-startval)/( endbar - startbar ));
  44. }
  45. }
  46. function TrtUndef( )
  47. {
  48. if ( ValRead > ( ((100 + Reversal)/100 ) * ValFromPro ) )///If rupture Increase
  49. {
  50. Process = ProcessIncrease;
  51. ValToPro=ValRead;
  52. BarToPro=BarRead;
  53. }
  54. else
  55. {
  56. if ( ValRead < ( ((100- Reversal)/100 ) * ValFromPro ) )  // If rupture Decrease
  57. {
  58. Process = ProcessDecrease;
  59. ValToPro=ValRead;
  60. BarToPro=BarRead;
  61. }
  62. else
  63. {
  64. Process = ProcessUndef;
  65. }
  66. }
  67. }
  68. function TrtIncrease( )
  69. {
  70. if ( ValRead > ValToPro )  // Still Increase
  71. {
  72. Process = ProcessIncrease;
  73. ValToPro=ValRead;
  74. BarToPro=BarRead;
  75. }
  76. else   // Break Increase Process
  77. {
  78. if ( ValRead <  ( ((100- Reversal)/100 ) * ValToPro ) )   // If break Decrease
  79. {
  80. Process = ProcessDecrease;
  81. ValFromPro=ValToPro;
  82. BarFromPro=BarToPro;
  83. ValToPro=ValRead;
  84. BarToPro=BarRead;
  85. }
  86. }
  87. }
  88. function TrtDecrease( )
  89. {
  90. if ( ValRead < ValToPro )  // Still Decrease
  91. {
  92. Process = ProcessDecrease;
  93. ValToPro=ValRead;
  94. BarToPro=BarRead;
  95. }
  96. else  // Break Decrease Process
  97. {
  98. if ( ValRead >  ( ( (100+ Reversal)/100 ) * ValToPro ) ) // If break Decrease
  99. {
  100.        Process = ProcessIncrease;
  101. ValFromPro=ValToPro;
  102. BarFromPro=BarToPro;
  103. ValToPro=ValRead;
  104. BarToPro=BarRead;
  105. }
  106. }
  107. }
  108. for( i = 1; i < BarCount; i++ )
  109. {
  110. ValRead = Avg[i];
  111. BarRead = i;
  112. if ( Process == ProcessUndef )
  113. {
  114. TrtUndef();
  115. }
  116. else
  117. {
  118. if ( Process == ProcessIncrease )
  119. {
  120. TrtIncrease();
  121. }
  122. else
  123. {
  124. TrtDecrease();
  125. }
  126. }
  127. if ( BarToPro == BarRead )
  128. FillLine( BarFromPro, ValFromPro, BarToPro, ValToPro );
  129. else
  130. FillLine( BarToPro, ValToPro, BarRead, ValRead );
  131. }
  132. _SECTION_BEGIN("avg");
  133. SetChartOptions(0,chartShowArrows);
  134. Plot( Avg, _DEFAULT_NAME(), ParamColor("Color", colorBlack ), ParamStyle("Style", styleLine + styleDots, maskPrice ) ); 
  135. _SECTION_END();
  136.  _SECTION_BEGIN("ZigZArray");
  137. Plot( ZigZArray, _DEFAULT_NAME(), ParamColor("Color", colorRed ), ParamStyle("Style", styleLine + styleThick) ); 
  138. _SECTION_END();