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

金融证券系统

开发平台:

Others

  1. //------------------------------------------------------------------------------
  2. //
  3. //  Formula Name:    Candle Stick Demo
  4. //  Author/Uploader: Herman van den Bergen 
  5. //  E-mail:          psytek@magma.ca
  6. //  Date/Time Added: 2005-01-28 16:27:56
  7. //  Origin:          
  8. //  Keywords:        Candle Pattern Demo
  9. //  Level:           medium
  10. //  Flags:           indicator
  11. //  Formula URL:     http://www.amibroker.com/library/formula.php?id=421
  12. //  Details URL:     http://www.amibroker.com/library/detail.php?id=421
  13. //
  14. //------------------------------------------------------------------------------
  15. //
  16. //  This program takes a segment from your price chart and substitutes the last
  17. //  bar visible with a representative Candle stick for the period selected. It
  18. //  allows you to observe how candles are formed and how loss of
  19. //  synchronization of the Candle period, or using different time frames, can
  20. //  result in totally different chart patterns for the same price array.
  21. //
  22. //------------------------------------------------------------------------------
  23. _SECTION_BEGIN("Candle Stick Demo");
  24. // Candlestick demo by herman van den Bergen
  25. BI = BarIndex();
  26. barvisible  = Status("barvisible");
  27. FirstBarIndx= LastValue( Lowest(ValueWhen(BarVisible,BI)));
  28. LastBarIndx = LastValue( Highest(ValueWhen(BarVisible,BI)));
  29. FirstBarVis = FirstBarIndx == BI; 
  30. LastBarVis  = LastBarIndx == BI; 
  31. Width=Param("Bar Width",5,1,30,1);
  32. EndCandle = SelectedValue(BarIndex())+int(Width/2)+1; 
  33. StartCandle = Endcandle-Width;
  34. CandleData = Flip(StartCandle == BI,EndCandle == BI);
  35. MAsk2 = IIf(BI>=StartCandle,1,Null);
  36. MAsk1 = IIf(CandleData OR LastBarVis, 1, Null);
  37. Oc = LastValue(ValueWhen(StartCandle == BI, O));
  38. Hc = LastValue(ValueWhen(CandleData , HHV(H,Width)));
  39. Lc = LastValue(ValueWhen(CandleData , LLV(L,Width)));
  40. CC = LastValue(ValueWhen(CandleData , C));
  41. O = IIf( LastBarVis, Oc, O);
  42. H = IIf( LastBarVis, HC, H);
  43. L = IIf( LastBarVis, LC, L);
  44. C = IIf( LastBarVis, CC, C);
  45. if( Param("Style: Candle/Bar",0,0,1,1) == 0 ) BarStyle = 64; else BarStyle = 128; 
  46. Plot(C,"",1,BarStyle |styleNoLabel|styleThick);
  47. Plot(Mask2*Oc,"",7,styleStaircase);
  48. Plot(Mask2*CC,"",2,styleStaircase);
  49. Plot(Mask2*HC,"",8,styleStaircase);
  50. Plot(Mask2*LC,"",4,styleStaircase);
  51. Co1 = Param("BackGroundColor",47,0,64,1);
  52. Plot(Mask1*LC,"",Co1,styleArea);
  53. Co2 = Param("CandleAreaColor",39,0,64,1);
  54. Plot(Mask1*HC,"",Co2,styleArea);
  55. Title="nCandlestick Demon"+
  56. "Candle Date:   "+Date()+"n"+
  57. "Candle Width:   "+NumToStr(Width,1.0)+" barsn";
  58. GraphXSpace = 5;
  59.  
  60. _SECTION_END();