ATR Volatility System.afl
上传用户:shiqiang
上传日期:2009-06-12
资源大小:1289k
文件大小:3k
源码类别:

金融证券系统

开发平台:

Others

  1. //------------------------------------------------------------------------------
  2. //
  3. //  Formula Name:    ATR Volatility System
  4. //  Author/Uploader: Marcelin 
  5. //  E-mail:          marcelint@xnet.ro
  6. //  Date/Time Added: 2006-01-14 13:08:22
  7. //  Origin:          
  8. //  Keywords:        
  9. //  Level:           medium
  10. //  Flags:           system
  11. //  Formula URL:     http://www.amibroker.com/library/formula.php?id=578
  12. //  Details URL:     http://www.amibroker.com/library/detail.php?id=578
  13. //
  14. //------------------------------------------------------------------------------
  15. //
  16. //  ATR trading system for short terms tradings. You can use it with Absolute
  17. //  Strength Index for confirmation of signals.
  18. //
  19. //------------------------------------------------------------------------------
  20. _SECTION_BEGIN("NewSystem ATR");
  21.    /*Writed & composed by Tudor Marcelin - Art Invest*/
  22.    n=Param( "perioada", 14, 5 , 20, 1 );
  23.    k=Param( "factor de multiplicare", 1.4, 0.5 , 2.5, 0.1 );
  24.   f=ATR(n);
  25.     
  26. /*R rezistenta pentru ziua curenta*/
  27.     R[0] = C[0]; 
  28. /*S rezistenta pentru ziua curenta*/ 
  29.     S[0] = C[0];
  30.   
  31. for( i = n+1; i < BarCount; i++ ) 
  32.     R[i]=R[i-1];
  33.     S[i]=S[i-1];
  34.     if (( S[i-1]<=C[i-1]) AND (C[i-1] <=R[i-1] ) AND (C[i-1]+k*f[i-1])<=RV)
  35.  
  36.         r[i] = C[i-1]+k*f[i-1];
  37.    
  38.      if (( S[i-1]<=C[i-1]) AND (C[i-1]<=R[i-1] ) AND  (C[i-1]-k*f[i-1])>=SV)
  39.         s[i]= C[i-1]-k*f[i-1];
  40.   
  41.   
  42.     if ( C[i-1] >R[i-1] )
  43. {
  44.        r[i] = C[i-1]+k*f[i-1];
  45.        s[i]= C[i-1]-k*f[i-1];
  46.        RV=r[i];
  47.        SV=s[i]; 
  48. }   
  49.     if ( C[i-1] <S[i-1] )
  50. {
  51.        r[i] = C[i-1]+k*f[i-1];
  52.        s[i]= C[i-1]-k*f[i-1];
  53.        RV=r[i];
  54.        SV=s[i]; 
  55.  Buy=Close>R;
  56.  Sell=Close<S;
  57.  
  58. Cump=IIf(Close>R,1,0);
  59. Vanz=IIf(Close<S,1,0);
  60. }
  61. Plot(Close,"Close",colorBlack,styleCandle);
  62. Plot(R, "Rez:",colorGreen,styleDots|styleNoLine);
  63. Plot(S, "Sup:",colorRed,styleDots|styleNoLine);
  64. Buy = ExRem( Buy, Sell ); //Elimina semnalele buy consecutive
  65. Sell = ExRem( Sell, Buy ); //Elimina semnalele sell consecutive
  66. shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
  67. fig=Cump*shapeHollowUpArrow + Vanz*shapeHollowDownArrow;
  68. PlotShapes( fig, IIf( Cump, colorPaleGreen  , colorPink), 0, IIf( Cump, Low, High)); //Pentru a vizualiza semnalele consecutive eliminate de ExRem
  69. PlotShapes( shape, IIf( Buy, colorGreen, colorRed ), 0, IIf( Buy, Low, High)); 
  70. AlertIf( Buy, "", "Volatility System", 1 );
  71. AlertIf( Sell, "", "Volatility System",2);
  72. Color = IIf( Vanz OR Sell, colorRed, IIf(Buy,colorGreen,colorLightGrey)); 
  73. Plot( 2, "", Color, styleArea | styleOwnScale | styleNoLabel, -0.1, 50 );
  74. GraphXSpace = 3;
  75. Title=EncodeColor(colorBlue)+"Volatility System"+EncodeColor(colorBlack)+ " Open:"+O+" High:"+H+" Low:"+L+" Close:"+C+EncodeColor(colorGreen)+" Rez:"+R+EncodeColor(colorRed)+" Sup:"+S+EncodeColor(colorBlue)+
  76. " nDate: "+EncodeColor(colorRed)+Date();
  77. _SECTION_END();