Tom DeMark Range Expansion Index (TDREI).afl
上传用户:shiqiang
上传日期:2009-06-12
资源大小:1289k
文件大小:4k
源码类别:

金融证券系统

开发平台:

Others

  1. //------------------------------------------------------------------------------
  2. //
  3. //  Formula Name:    Tom DeMark Range Expansion Index (TDREI)
  4. //  Author/Uploader: Brian 
  5. //  E-mail:          brianrichard99@hotmail.com
  6. //  Date/Time Added: 2006-03-20 22:52:16
  7. //  Origin:          Created by Tom DeMark
  8. //  Keywords:        TD REI, TDREI, Range Expansion Index, DeMark
  9. //  Level:           medium
  10. //  Flags:           indicator
  11. //  Formula URL:     http://www.amibroker.com/library/formula.php?id=607
  12. //  Details URL:     http://www.amibroker.com/library/detail.php?id=607
  13. //
  14. //------------------------------------------------------------------------------
  15. //
  16. //  Tom DeMark's REI indicator oftentimes gives leading signals before other
  17. //  indicators begin signalling. Use this together with other leading
  18. //  indicators, for signal confirmation. This version also includes the TD
  19. //  Price Oscillator Qualifier (TD POQ) and DeMark's Duration Analysis, for
  20. //  identifying extreme overbought and oversold conditions.
  21. //
  22. //------------------------------------------------------------------------------
  23. /* 
  24. Tom DeMark's Range Expansion Index (TD REI)
  25. with Price Oscillator Qualifier (TD POQ)
  26. and Duration Analysis OverBought/Uptrend (yellow) 
  27. and OverSold/Downtrend (red) signals
  28. */
  29. // Set variables here
  30. varOversoldSignal = (-35); // default (-45)
  31. varOverboughtSignal = 35; // default 45
  32. varPeriod = 5; // default 5 or 8
  33. // End set variables
  34. HighMom = H - Ref( H, -2 );
  35. LowMom = L - Ref( L, -2 );
  36. Cond1 = ( H >= Ref( L,-5) OR H >= Ref( L, -6 ) );
  37. Cond2 = ( Ref( H, -2 ) >= Ref( C, -7 ) OR Ref( H, -2 ) >= Ref( C, -8 ) ); 
  38. Cond3 = ( L <= Ref( H, -5 ) OR L <= Ref( H, -6) ); 
  39. Cond4 = ( Ref( L, -2 ) <= Ref( C, -7 ) OR Ref( L, -2 ) <= Ref( C, -8 ) );
  40. Cond = ( Cond1 AND Cond3 ) OR ( Cond2 AND Cond4 );
  41. Num = IIf( Cond, HighMom + LowMom, 0 );
  42. Den = abs( HighMom ) + abs( LowMom );
  43. TDREI = 100 * Sum( Num, varPeriod )/Sum( Den, varPeriod ) ;
  44. // Identify oversold conditions, marked with white arrow to denote downtrend
  45. varOversold = IIf(Ref(TDREI,-5)<=varOversoldSignal 
  46. AND Ref(TDREI,-4)<=varOversoldSignal 
  47. AND Ref(TDREI,-3)<=varOversoldSignal 
  48. AND Ref(TDREI,-2)<=varOversoldSignal 
  49. AND Ref(TDREI,-1)<=varOversoldSignal 
  50. AND TDREI<=varOversoldSignal ,1,0);
  51. IIf(VarOversold>0,PlotShapes(shapeHollowDownArrow*varOversold,colorWhite),0);
  52. // Identify overbought conditions, marked with green arrow to denote uptrend
  53. varOverbought = IIf(Ref(TDREI,-5)>=varOverboughtSignal 
  54. AND Ref(TDREI,-4)>=varOverboughtSignal 
  55. AND Ref(TDREI,-3)>=varOverboughtSignal 
  56. AND Ref(TDREI,-2)>=varOverboughtSignal 
  57. AND Ref(TDREI,-1)>=varOverboughtSignal 
  58. AND TDREI>=varOverboughtSignal ,1,0);
  59. IIf(varOverbought>0,PlotShapes(shapeHollowUpArrow*varOverbought,colorYellow),0);
  60. // Tom DeMark Price Oscillator Qualifier (TD POQ)
  61. // Primary and Secondary Buy Setups apply to EOD of today
  62. // Buy = H > (H,-1)
  63. varPrimaryCheck = 0;
  64. varPrimaryBuySetup = (Ref(C,-1) > Ref (C,-2) 
  65. AND O < Ref(H,-1)
  66. AND H > Ref(H,-1));
  67. varSecondaryBuySetup = (Ref(C,-1) > Ref(C,-2) 
  68. AND O > Ref(H,-1) 
  69. AND O < Ref(H,-2)
  70. AND H > Ref(H,-1));
  71. varPrimaryBuySetupSignal = IIf(varPrimaryBuySetup 
  72. AND TDREI>varOversoldSignal
  73. AND Ref(TDREI,-1)<varOversoldSignal,1,0);
  74. varSecondaryBuySetupSignal = IIf(varSecondaryBuySetup
  75. AND TDREI>varOversoldSignal
  76. AND Ref(TDREI,-1)<varOversoldSignal,1,0);
  77. // Start: Plot all lines
  78. Graph0=TDREI;
  79. Graph0Style=4;
  80. Graph0Color=4;
  81. Graph1=varOverboughtSignal;
  82. Graph1Style=1;
  83. Graph1Color=6;
  84. Graph2=varOversoldSignal;
  85. Graph2Style=1;
  86. Graph2Color=6;
  87. IIf(varPrimaryBuySetupSignal>0,PlotShapes(shapeDigit1*varPrimaryBuySetupSignal,colorGreen) AND varPrimaryCheck=1,0);
  88. IIf(varSecondaryBuySetupSignal>0 AND varPrimaryCheck<1,PlotShapes(shapeDigit2*varSecondaryBuySetupSignal,colorDarkGreen),0);
  89. // End: plot all lines
  90. Title =Name() + " -TD REI: " + "("+ WriteVal ( Graph0,format=1.2)+")";