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

金融证券系统

开发平台:

Others

  1. //------------------------------------------------------------------------------
  2. //
  3. //  Formula Name:    Elders AutoEnvelopes
  4. //  Author/Uploader: Hoyala 
  5. //  E-mail:          hoyheyhay@hotmail.com
  6. //  Date/Time Added: 2006-01-17 16:51:20
  7. //  Origin:          USA
  8. //  Keywords:        Elder's AutoEnvelopes
  9. //  Level:           advanced
  10. //  Flags:           indicator
  11. //  Formula URL:     http://www.amibroker.com/library/formula.php?id=581
  12. //  Details URL:     http://www.amibroker.com/library/detail.php?id=581
  13. //
  14. //------------------------------------------------------------------------------
  15. //
  16. //  Who can translate this formula to Amibroker?
  17. //
  18. //  Please help me!
  19. //
  20. //------------------------------------------------------------------------------
  21. ====================
  22. Elder's AutoEnvelope
  23. ====================
  24. ---8<---------------------------
  25. {Dr A. Elder's AutoEnvelope interpretation v1.0}
  26. { www.elder.com/MetaStock/AutoEnvelope.htm }
  27. { http://www.metastocktools.com }
  28. { User inputs }
  29. pds:=Input("EMA periods",1,252,21);
  30. pdsBak:=Input("lookback periods",1,252,42);
  31. x:=Input("use: Open=1, High=2, Low=3, Close=4, WClose=5",1,5,4);
  32. plot:=Input("[1]AutoEnvelope, [2]Long signals, [3]All signals",1,3,1);
  33. delay:=Input("Entry/Exit signals delay",0,5,0);
  34. { Price field }
  35. x:=If(x=1,O,If(x=2,H,If(x=3,L,If(x=5,WC(),C))));
  36. { Envelope bands }
  37. Avg:=Mov(x,pds,E);
  38. hiAvg:=HHV(H,pdsBak);
  39. loAvg:=LLV(L,pdsBak);
  40. shift:=
  41.  Mov(If(hiAvg>Avg,hiAvg-Avg,Avg-loAvg),pds,E);
  42. UpperBand:=Avg+shift;
  43. LowerBand:=Avg-shift;
  44. { Envelope signals }
  45. In:=Cross(x,LowerBand);
  46. Out:=Cross(x,UpperBand);
  47. Init:=Cum(In+Out>-1)=1;
  48. InInit:=Cum(In)=1;
  49. flag:=BarsSince(Init OR In)
  50.  <BarsSince(Init OR Out)+InInit;
  51. signals:=Ref((InInit AND Alert(InInit=0,2)
  52.   OR flag AND Alert(flag=0,2))
  53.    -(flag=0 AND Alert(flag,2)),-delay);
  54. { Plot envelope on price chart }
  55. If(plot=1,UpperBand,If(plot=2,signals,In-Out));
  56. If(plot=1,Avg,If(plot=2,0,0));
  57. If(plot=1,LowerBand,If(plot=2,signals,In-Out))
  58. ---8<---------------------------
  59. http://www.metastocktools.com