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

金融证券系统

开发平台:

Others

  1. //------------------------------------------------------------------------------
  2. //
  3. //  Formula Name:    ATR Trading System
  4. //  Author/Uploader: Marcelin 
  5. //  E-mail:          marcelint@xnet.ro
  6. //  Date/Time Added: 2005-04-10 11:26:02
  7. //  Origin:          
  8. //  Keywords:        
  9. //  Level:           basic
  10. //  Flags:           system
  11. //  Formula URL:     http://www.amibroker.com/library/formula.php?id=456
  12. //  Details URL:     http://www.amibroker.com/library/detail.php?id=456
  13. //
  14. //------------------------------------------------------------------------------
  15. //
  16. //  A trading system based on volatility
  17. //
  18. //------------------------------------------------------------------------------
  19.    /*Writed & composed by Tudor Marcelin - Art Invest*/
  20.   k=1; /* multiplication factor*/
  21.   n=10; /*period*/
  22.   f=ATR(n);
  23.     
  24.     R[0] = Close[0]; 
  25.     S[0] = C[0];
  26. for( i = 11; i < BarCount; i++ ) 
  27.    R[i]=R[i-1];
  28.    S[i]=S[i-1];
  29.     if ( C[i-1] >R[i-1] )
  30. {
  31.        r[i] = C[i-1]+k*f[i-1];
  32.        s[i]= C[i-1]-k*f[i-1];
  33. }   
  34.     if ( C[i-1] <S[i-1] )
  35. {
  36.        r[i] = C[i-1]+k*f[i-1];
  37.        s[i]= C[i-1]-k*f[i-1];
  38. Buy=Close>R;
  39. Sell=Close<S;
  40. Cump=IIf(Close>R,1,0);
  41. Vanz=IIf(Close<S,1,0);
  42. }
  43. Plot(Close,"Close",colorBlack,styleCandle);
  44. Plot(R, "Rez:",colorGreen,styleDots|styleNoLine);
  45. Plot(S, "Sup:",colorRed,styleDots|styleNoLine);
  46. Buy = ExRem( Buy, Sell ); //Elimina semnalele buy consecutive
  47. Sell = ExRem( Sell, Buy ); //Elimina semnalele sell consecutive
  48. shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
  49. fig=Cump*shapeHollowUpArrow + Vanz*shapeHollowDownArrow;
  50. PlotShapes( fig, IIf( Cump, colorPaleGreen  , colorPink), 0, IIf( Cump, Low-50, High+50)); //Pentru a vizualiza semnalele consecutive eliminate de ExRem
  51. PlotShapes( shape, IIf( Buy, colorGreen, colorRed ), 0, IIf( Buy, Low-50, High+50)); 
  52. AlertIf( Buy, "", "Experiment", 1 );
  53. AlertIf( Sell, "", "Experiment",2);
  54. GraphXSpace = 3;
  55. Title=EncodeColor(colorBlue)+"Experiment"+EncodeColor(colorBlack)+ " Open:"+O+" High:"+H+" Low:"+L+" Close:"+C+EncodeColor(colorGreen)+" Rez:"+R+EncodeColor(colorRed)+" Sup:"+S+EncodeColor(colorBlue)+
  56. " nDate: "+EncodeColor(colorRed)+Date();