COCO研究院

 找回密碼
 註冊
搜索
查看: 10729|回復: 15

[範例程式碼] KD指標

[複製鏈接]
發表於 10-1-12 14:16 | 顯示全部樓層 |閱讀模式
本帖最後由 thirtycm 於 10-1-12 02:32 PM 編輯

  1. _SECTION_BEGIN("Stochastic %KDJ");
  2. SetChartOptions(0,0,chartGrid20|chartGrid80);
  3. periods = Param( "Periods", 15, 1, 200, 1 );
  4. Ksmooth = Param( "%K avg", 3, 1, 200, 1 );
  5. Dsmooth = Param( "%D avg", 3, 1, 200, 1 );
  6. Plot( StochK( periods , Ksmooth),"%K", ParamColor( "Color_K", colorCycle ), ParamStyle("Style_K") );
  7. Plot( StochD( periods , Ksmooth, DSmooth ),"%D", ParamColor( "Color_D", colorCycle ), ParamStyle("Style_D") );
  8. K=StochK( periods , Ksmooth);
  9. D=StochD( periods , Ksmooth, DSmooth );
  10. j=3*K-2*D;
  11. Plot( j, "%J", ParamColor( "Color_J", colorCycle ), ParamStyle("Style_J") );
  12. Plot( 20, "", colorBlue, styleline  );
  13. Plot( 80, "", colorRed,  styleline   );
  14. Plot( 50, "", colorGreen,  styleline   );
  15. _SECTION_END();
複製代碼
發表於 10-1-12 14:53 | 顯示全部樓層
kd指標參數(15,3,3)?

我發現我越來越看的懂AFL的程式了。哈。
程式13~15行是畫三條線,分別為20,80,50。以標出超賣超買。
 樓主| 發表於 10-1-12 14:57 | 顯示全部樓層
(15,3,3)是預設值,在parameters可以調整的!!!
發表於 10-1-17 17:56 | 顯示全部樓層
kd.gif

補上圖。

順請請問一下,怎麼樣把成交量拉到下面的單一區域?
每次都和k線圖混合一區,很不容易看。
 樓主| 發表於 10-1-17 18:04 | 顯示全部樓層

1.jpg
   

 樓主| 發表於 10-1-17 18:07 | 顯示全部樓層
本帖最後由 thirtycm 於 10-1-17 06:09 PM 編輯

  1. _SECTION_BEGIN("Bull vs Bear Volume");
  2. SetChartBkColor(16);

  3. C1 = Ref(C, -1);
  4. uc = C > C1; dc = C <= C1;
  5. ud = C > O; dd = C <= O;

  6. green = 1; blue = 2; yellow = 3; red = 4; white = 5;
  7. VType = IIf(ud,         
  8.          IIf(uc, green, yellow),
  9.        IIf(dd,
  10.          IIf(dc, red, blue), white));

  11. gv = IIf(VType == green, V, 0);
  12. yv = IIf(VType == yellow, V, 0);
  13. rv = IIf(VType == red, V, 0);
  14. bv = IIf(VType == blue, V, 0);
  15. uv = gv + bv; uv1 = Ref(uv, -1);
  16. dv = rv + yv; dv1 = Ref(dv, -1);
  17. VolPer = Param("Adjust Vol. MA per.", 34, 1, 255, 1);
  18. ConvPer = Param("Adjust Conv. MA per.", 9, 1, 255, 1);
  19. MAuv = TEMA(uv, VolPer ); mauv1 = Ref(mauv, -1);
  20. MAdv = TEMA(dv, VolPer ); madv1 = Ref(madv, -1);
  21. MAtv = TEMA(V, VolPer );
  22. OscillatorOnly = Param("Show Oscillator Only", 0, 0, 1, 1);
  23. CompareBullVolume = Param("Show Bull Level", 1, 0, 1, 1);
  24. if(CompareBullvolume AND !OscillatorOnly){
  25. Plot(SelectedValue(MAuv), "", colorRed, styleLine);
  26. }

  27. CompareBearVolume = Param("Show Bear Level", 1, 0, 1, 1);
  28. if(CompareBearVolume AND !OscillatorOnly){
  29. Plot(SelectedValue(MAdv), "", colorGreen, styleLine);
  30. }
  31. bullvolume = Param("Show Bull Volume", 1, 0, 1, 1);
  32. bearvolume = Param("Show Bear Volume", 1, 0, 1, 1);
  33. totalvolume = Param("Show Total Volume", 1, 0, 1, 1);
  34. bearToFront = Param("Show Bear Vol in Front", 0, 0, 1, 1);
  35. if(bearToFront AND !OscillatorOnly){
  36. Plot(MAdv, "", colorGreen, styleHistogram|styleNoLabel);
  37. }
  38. if(bullvolume AND !OscillatorOnly){
  39. Plot(MAuv, "Average Bull Volume", colorRed, styleHistogram|styleNoLabel);
  40. }
  41. if(bearvolume AND !OscillatorOnly){
  42. Plot(MAdv, "Average Bear Volume", colorGreen, styleHistogram|styleNoLabel);
  43. }
  44. if(totalVolume AND !OscillatorOnly){
  45. Plot(MAtv, "Total Volume", colorWhite, styleHistogram|styleNoLabel);
  46. Plot(MAtv, "", colorWhite, styleLine);
  47. }
  48. if(bullvolume AND !OscillatorOnly){
  49. Plot(MAuv, "", colorGreen, styleLine);
  50. }
  51. if(bearvolume AND !OscillatorOnly){
  52. Plot(MAdv, "", colorRed, styleLine);
  53. }
  54. Plot(0, "", colorBlue, 1);
  55. Converge = (TEMA(MAuv - MAdv, ConvPer));
  56. Converge1 = Ref(Converge, -1);
  57. ConvergeUp = Converge > Converge1;
  58. ConvergeOver = Converge > 0;
  59. rising = ConvergeUp AND ConvergeOver;
  60. falling = !ConvergeUp AND ConvergeOver;
  61. convergenceOscillator = Param("Show Oscillator", 0, 0, 1, 1);
  62. if(convergenceOscillator OR OscillatorOnly){
  63. Plot(Converge, "Bull/Bear Volume Convergence/Divergence", colorViolet,
  64. 1|styleLeftAxisScale|styleNoLabel|styleThick);
  65. Plot(0,"", colorYellow, 1|styleLeftAxisScale|styleNoLabel);
  66. }
  67. riseFallColor = IIf(rising, 14,15);
  68. riseFallShadows = Param("Show RiseFallShadows", 0, 0, 1, 1);
  69. if(riseFallShadows){
  70. Plot(IIf(rising OR falling, 1, 0), "", riseFallColor,
  71. styleHistogram|styleArea|styleOwnScale|styleNoLabel);
  72. }
  73. GraphXSpace = 0.5;
  74. _SECTION_END();
複製代碼
另一種成交量!白色是總量,紅色的買進的量,綠色是賣出的量!
發表於 10-1-17 22:10 | 顯示全部樓層
回復 5# thirtycm


    謝謝。這樣子清楚多了。
發表於 10-4-28 15:38 | 顯示全部樓層
請問一下,如果我要以KD指標來選股的話,應該怎麼寫呢??

譬如說,我要挑出所以K破50的股票

謝謝各位大大!
發表於 10-4-28 20:19 | 顯示全部樓層
回復 8# egglee


    http://www.coco-in.net/viewthread.php?tid=1753

這一篇為AmiBroker的選股功能,條件改成KD就能用了。
發表於 10-4-29 12:49 | 顯示全部樓層
回復 9# 綠茶妹


    綠茶大,那篇我爬過了,但是我不知道KD值的K值要怎麼取出來耶
發表於 10-5-3 10:58 | 顯示全部樓層
呼~~好不容易寫出來了~~

但是跑出來的數值跟看盤軟體的不一樣說

除了參數,還有那裡需要注意呢

拜託好心人指點一下吧
發表於 10-5-3 13:29 | 顯示全部樓層
本帖最後由 minc 於 10-5-3 01:31 PM 編輯

_SECTION_BEGIN("k over 50");
periods = Param( "Periods", 15, 1, 200, 1 );
Ksmooth = Param( "%K avg", 3, 1, 200, 1 );
K=StochK( periods , Ksmooth);
Buy = K > 50 and Ref(K, -1) < 50;
Sell = K <50 and Ref(K, -1) >50;
_SECTION_END();

當k今天大於50時,出現Buy,跌破50時,為sell
發表於 10-5-3 13:52 | 顯示全部樓層
kd指標參數(15,3,3)?

我發現我越來越看的懂AFL的程式了。哈。
程式13~15行是畫三條線,分別為20,80,50。 ...
綠茶妹 發表於 10-1-12 02:53 PM


其實不一定要劃這三條線


在kd圖中,按右鍵,選parameters -> Axes & Grids -> levels -> 在20/80,50 打勾就行了,另外,show middle line 改no
發表於 10-5-3 13:57 | 顯示全部樓層
回復 13# minc


    謝謝...原來可以這樣子用啊

發表於 11-4-15 00:10 | 顯示全部樓層
回復 13# minc


    之前竟然沒注意到原來也可以這樣用
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

手機版|Archiver|站長信箱|廣告洽詢|COCO研究院

GMT+8, 24-4-27 19:06

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回復 返回頂部 返回列表
理財討論網站 | AI繪圖AI超擬真美女AI beauty AI Stable DiffusionAI正妹AI Lookbook