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

金融证券系统

开发平台:

Others

  1. //------------------------------------------------------------------------------
  2. //
  3. //  Formula Name:    Adaptive Price Channel
  4. //  Author/Uploader: Denis Dube 
  5. //  E-mail:          
  6. //  Date/Time Added: 2004-04-29 12:32:15
  7. //  Origin:          From the book " The Ultimate Trading Guide".
  8. //  Keywords:        Adaptive channel
  9. //  Level:           medium
  10. //  Flags:           indicator
  11. //  Formula URL:     http://www.amibroker.com/library/formula.php?id=356
  12. //  Details URL:     http://www.amibroker.com/library/detail.php?id=356
  13. //
  14. //------------------------------------------------------------------------------
  15. //
  16. //  This price channel starts with a lookback period of 20.
  17. //
  18. //  The lookback period changes according to volatility, measured by a 30
  19. //  period standard deviation of prices.
  20. //
  21. //  A maximum and a minimum lookback period are defined.
  22. //
  23. //------------------------------------------------------------------------------
  24. //Adaptive price channel
  25. Plot(C,"",colorBlack,styleCandle);
  26. Lookback=20;
  27. MaxLookback=Param("Max Lookback period",40,20,60,5);
  28. MinLookback=Param("Min Lookback period",20,10,20,5);
  29. Vol=StDev(C,30);
  30. Change=(Vol-Ref(Vol,-1))/Ref(Vol,-1);
  31. StartBar = BeginValue( BarIndex() ); ;
  32. FinishBar = EndValue( BarIndex() ); 
  33. i = StartBar; 
  34. for (i = StartBar+31; i<Finishbar; i++) 
  35. Lookback[i]=round(Lookback[i-1]*(1+Change[i]));
  36. if(Lookback[i]>MaxLookback)
  37. {
  38. Lookback[i]=MaxLookback;
  39. }
  40. if(Lookback[i]<MinLookback)
  41. {
  42. Lookback[i]=MinLookback;
  43. }
  44. }
  45. HighChannel=Ref(HHV(H,Lookback),-1);
  46. LowChannel=Ref(LLV(L,Lookback),-1);
  47. Plot(HighChannel,"",colorPink,styleThick | styleNoRescale);
  48. Plot(LowChannel,"",colorSeaGreen,styleThick | styleNoRescale );
  49. GraphXSpace=7;