[通达信指标/源码] [转载]K线微积分律与MACD

0
回复
3631
查看
[复制链接]

87

主题

6

回帖

1289

积分

超级版主

积分
1289
来源: 2020-6-10 22:48:45 显示全部楼层 |阅读模式
  1. {K线微积分律与MACD;MACD_DCIC_K ;原创及版权属于JIPGEMLING.见凌见;}
  2. {关键词:K线微积分律,MACD指标}
  3. {仅允许个人自用、互联网传播并带上作者笔名及版权声明}

  4. {本文实际证明了等式:
  5. DIF=(LONG-SHORT)/2*EMA(EMA((C-REF(C,1)),SHORT),LONG)
  6.    =((LONG-SHORT)/2)*EMA(EMA(C,SHORT)-REF(EMA(C,SHORT),1),LONG)
  7.    =EMA(C,SHORT)-EMA(C,LONG) }
  8. {即,对于SHORT>=1和LONG>=1 的所有正整数,上述等式成立。}


  9. {证明:用数学归纳法。由于我们不知道股软函数EMA()、REF()的具体形式,所以计算过程要结合股软(TDX)辅证。
  10. 1、首先当SHORT=1、LONG=1时,公式两边0=0,等式显然成立;
  11. 2、当SHORT=1、LONG=>2时并在股软上任意调节对比,等式两边数值非恒量但均相等,故等式成立;
  12. 3、当LONG=1时,SHORT=>2并在股软上任意调节对比,等式两边数值非恒量但均相等,故等式成立;
  13. 4、其余任意正整数,在股软上任意调节对比,等式两边数值非恒量但均相等,故等式成立;
  14. 5、根据上述结论和数学归纳法原理,对于SHORT>=1和LONG>=1 的所有正整数,等式成立。证毕。}

  15. {同理可证1:DIF_H =(LONG-SHORT)/2*EMA(EMA((H-REF(H,1)),SHORT),LONG)=  }
  16. {=((LONG-SHORT)/2)*EMA(EMA(H,SHORT)-REF(EMA(H,SHORT),1),LONG)=EMA(H,SHORT)-EMA(H,LONG);}
  17. {同理可证2:DIF_L =(LONG-SHORT)/2*EMA(EMA((L-REF(L,1)),SHORT),LONG)=  }
  18. {=((LONG-SHORT)/2)*EMA(EMA(L,SHORT)-REF(EMA(L,SHORT),1),LONG)=EMA(L,SHORT)-EMA(L,LONG);}
  19. {同理可证3:DIF_O =(LONG-SHORT)/2*EMA(EMA((O-REF(O,1)),SHORT),LONG)=  }
  20. {=((LONG-SHORT)/2)*EMA(EMA(O,SHORT)-REF(EMA(O,SHORT),1),LONG)=EMA(O,SHORT)-EMA(O,LONG);}
  21. {同理可证4:DIF_CC =(LONG-SHORT)/2*EMA(EMA((CC-REF(CC,1)),SHORT),LONG)=  }
  22. {=((LONG-SHORT)/2)*EMA(EMA(CC,SHORT)-REF(EMA(CC,SHORT),1),LONG)=EMA(CC,SHORT)-EMA(CC,LONG);}
  23. {其中CC=(C+H+L)/3;只要C、H、L、O 属于相同时序的常系数线性组合(可否为有理式组合?)}

  24. {可否考虑将上述事实作为一个【K线定理、定律】来看待?}

  25. {MACD功效、一般应用、典型应用条件}
  26. {一般应用条件:LONG>SHORT;典型应用:LONG=2*(SHORT+1),}
  27. {即LONG是SHORT的2个倍频程+2个K线单位时程(看待为积分一个完整的脉冲周期而又不致于丢失信息和混入杂波)}
  28. {微分具有剔除低频(长线资金)的作用,积分是微分的反运算,并有压制高频杂波(投机资金)的作用。}
  29. {MACD式子是个“有源平直中频带通滤波器”,做法是差值滤波并作2倍放大,取得中线资金激励信息。}
  30. {MACD指标突出中线资金的买卖趋势。0轴为多空平衡位。参数设置应考虑是否符合指标本身固有功能}

  31. {受中波广播频段(535kHz--1605kHz)设置的启发,现提出 LONG<=3*SHORT 这样的条件是否合理?}

  32. {语句注释}
  33. DFC:=C-REF(C,1);{收盘价前差值,K线微分}
  34. WJXS:=(LONG-SHORT)/2;{微积分系数,可由中值定理导出,为兼顾后面引用及统一标尺,前移至此}
  35. JGL_JF:=WJXS*EMA(DFC,SHORT);{内层积分,隐含积分限[1--SHORT],结果:WJXS*EMA(EMA(CC,SHORT)-REF(EMA(CC,SHORT),1),LONG)}
  36. DIF_JIP:EMA(JGL_JF,LONG);{外层积分,重积分,隐含积分限[1--LONG],结果:EMA(CC,SHORT)-EMA(CC,LONG)}
  37. DEA_GEM:EMA(DIF_JIP,MID);{平滑,压制高频}
  38. MACD_LING:2*(DIF_JIP-DEA_GEM),COLOR1133FF,COLORSTICK;{差值滤波然后作2倍放大,显示红、青色针状线柱}

  39. {“类KDJ”}
  40. {以下为“类KDJ”及显示“J值前差值柱”,后者可提高对涨跌的肉眼分辨率,提高对短线波动的感知度}
  41. {J值式子具有“有源高频滤波器”性质,经典KDJ的J是对高频信号作3倍放大,D是对中高频作2倍放大,}
  42. {然后差值滤波,滤掉中低频和杂波信号,所以在选择系数时应考虑使激励与阻尼达平衡,避免过激励和欠激励}
  43. {J_DF系数,设A=2.00~3.00,B=1.00~2.00,弱必要条件是 A-B=1,使差值信号仍有1倍放大,3条线间隔大致等距}

  44. K_DF_J:SMA(JGL_JF,M1,1),COLORFEDCBA;{平滑,压制超短线杂波}
  45. D_DF_G:SMA(K_DF_J,M2,1),COLOR13F8F9;{再平滑,圆滑超短线造成的扰动}
  46. J_DF_L:2.5*K_DF_J-1.5*D_DF_G,COLORF813F9;{有源差值滤波,取得中高频短线信号}
  47. RF:=REF(J_DF_L,1);
  48. DJ:=ABS(J_DF_L-RF);
  49. MM:=(HHV(DJ,120)+LLV(DJ,120))/2;
  50. STICKLINE(J_DF_L>RF,J_DF_L,RF,2.3,0),COLOR1388D3;
  51. STICKLINE(J_DF_L>RF,J_DF_L,RF,1.0,0),COLOR13AAD3;
  52. STICKLINE(J_DF_L<RF,J_DF_L,RF,2.3,0),COLOR338833;
  53. STICKLINE(J_DF_L<RF,J_DF_L,RF,1.0,0),COLOR33AA33;
  54. STICKLINE(J_DF_L<RF AND DJ<0.2*MM,J_DF_L+0.15*MM,RF-0.15*MM,0.1,0),COLOR33AA33;
  55. STICKLINE(J_DF_L>=RF AND DJ<0.2*MM,RF-0.1*MM,J_DF_L+0.1*MM,0.1,0),COLOR13AADD;

  56. {轨道设置,仅作试用;KG(开关,默认 开);{飞狐等版本可考虑用虚线}}

  57. N:=SQRT(SHORT*LONG);
  58. NN:=IF(N<9,9,N);
  59. BZC:=STD(DFC,NN);
  60. U:IF(KG=1,K_DF_J+2*BZC,MA(C,25600)),COLORFE9813,CROSSDOT,LINETHICK2;
  61. D:IF(KG=1,K_DF_J-2*BZC,MA(C,25600)),COLOR33EAEA,CROSSDOT,LINETHICK2;



  62. {实际加入编译的语句及“说明头”如下}



  63. {副图:MACD_DCIC ;K线微积分律与MACD;}
  64. {原创及版权属于JIPGEMLING.见凌见;JIPGEMLING.签名版}
  65. {参数设置: SHORT(1,300,12);LONG(2,300,26);MID(2,200,9);}
  66. {参数设置: M1(2,300,3);M2(2,300,3);KG(1,2,1);}
  67. {坐标线位置:自动;额外Y轴分界 值1=0;}
  68. {TDX版(基本通用版)中高分辨率屏幕;如嫁接其他版本,可调整“J值前差值柱”的宽度}

  69. DFC:=C-REF(C,1);
  70. WJXS:=(LONG-SHORT)/2;
  71. JGL_JF:=WJXS*EMA(DFC,SHORT);
  72. DIF_JIP:EMA(JGL_JF,LONG),COLOR1188FF,LINETHICK2;
  73. DEA_GEM:EMA(DIF_JIP,MID),COLORGREEN,LINETHICK2;
  74. MACD_LING:2*(DIF_JIP-DEA_GEM),COLOR1133FF,COLORSTICK;
  75. K_DF_J:SMA(JGL_JF,M1,1),COLORFEDCBA;
  76. D_DF_G:SMA(K_DF_J,M2,1),COLOR13F8F9;
  77. J_DF_L:2.5*K_DF_J-1.5*D_DF_G,COLORF813F9;
  78. RF:=REF(J_DF_L,1);
  79. DJ:=ABS(J_DF_L-RF);
  80. MM:=(HHV(DJ,120)+LLV(DJ,120))/2;
  81. STICKLINE(J_DF_L>RF,J_DF_L,RF,2.3,0),COLOR1388D3;
  82. STICKLINE(J_DF_L>RF,J_DF_L,RF,1.0,0),COLOR13AAD3;
  83. STICKLINE(J_DF_L<RF,J_DF_L,RF,2.3,0),COLOR338833;
  84. STICKLINE(J_DF_L<RF,J_DF_L,RF,1.0,0),COLOR33AA33;
  85. STICKLINE(J_DF_L<RF AND DJ<0.2*MM,J_DF_L+0.15*MM,RF-0.15*MM,0.1,0),COLOR33AA33;
  86. STICKLINE(J_DF_L>=RF AND DJ<0.2*MM,RF-0.1*MM,J_DF_L+0.1*MM,0.1,0),COLOR13AADD;
  87. N:=SQRT(SHORT*LONG);
  88. NN:=IF(N<9,9,N);
  89. BZC:=STD(DFC,NN);
  90. U:IF(KG=1,K_DF_J+2*BZC,MA(C,25600)),COLORFE9813,CROSSDOT,LINETHICK2;
  91. D:IF(KG=1,K_DF_J-2*BZC,MA(C,25600)),COLOR33EAEA,CROSSDOT,LINETHICK2;

  92. *************************************************************************************************

  93. MACD的微积分解析与再造

  94. {副图名:DF_MACD ;中文名:微分MACD;发明人及版权属于JIPGEMLING.见凌见};
  95. {参数:SHORT(2,200,12);LONG(2,200,26);MID(2,200,9);M(2,100,3)};
  96. {额外Y轴分界,值1:0.00  ;坐标线位置:自动 };
  97. {环球通用版};
  98. WXS:=(LONG-SHORT)/2;{系数};
  99. JGL_DF:=WXS*(EMA(CLOSE,SHORT)-REF(EMA(CLOSE,SHORT),1));{微分};
  100. DIF_J:EMA(JGL_DF,LONG),COLORFEDCBA,LINETHICK2;{积分};
  101. DEA_G:EMA(DIF_J,MID),LINETHICK2;{平滑};
  102. MACD_L:(DIF_J-DEA_G)*2,COLOR1133FE,COLORSTICK;
  103. K_DF:SMA(JGL_DF,M,1),COLOR1188FF;{以下为“类KDJ”};
  104. D_DF:SMA(K_DF,3,1),COLOR13FF99;
  105. J_DF:2.6*K_DF-1.6*D_DF,COLORAF13FA;
  106. RF:=REF(J_DF,1);
  107. STICKLINE(J_DF>=RF,J_DF,RF,2.3,0),COLOR1399FE;
  108. STICKLINE(J_DF>=RF,J_DF,RF,1.0,0),COLOR13DDFE;
  109. STICKLINE(J_DF<RF,J_DF,RF,2.3,0),COLORFF9913;
  110. STICKLINE(J_DF<RF,J_DF,RF,1.0,0),COLORFFDD13;
  111. **************************************************************************

  112. 修改版,提高了显示效果。


  113. {副图名:DF_MACD ;中文名:微分MACD;发明人及版权属于JIPGEMLING.见凌见}
  114. {参数:SHORT(2,200,12);LONG(2,200,26);MID(2,200,9);M(2,100,3)}
  115. {额外Y轴分界,值1:0.00  ;坐标线位置:自动 }

  116. WXS:=(LONG-SHORT)/2;{系数}
  117. JGL_DF:=WXS*(EMA(CLOSE,SHORT)-REF(EMA(CLOSE,SHORT),1));{微分}
  118. DIF_J:EMA(JGL_DF,LONG),COLOR1234AA,LINETHICK2;{积分}
  119. DEA_G:EMA(DIF_J,MID),COLOR338833,LINETHICK2;{平滑}
  120. MACD_L:(DIF_J-DEA_G)*2,COLORA9A813,COLORSTICK;
  121. K_DF:SMA(JGL_DF,M,1)*1,COLORFEDCBA;{以下为“类KDJ”}
  122. D_DF:SMA(K_DF,M,1),COLOR13F8F9;
  123. J_DF:3*K_DF-2*D_DF,COLORF813F9;
  124. {以下显示“J_DF前差值柱”,柱子太薄时显示“十”字星}
  125. RF:=REF(J_DF,1);
  126. DJ:=ABS(J_DF-RF);
  127. MM:=(HHV(DJ,240)+LLV(DJ,240))/2;
  128. STICKLINE(J_DF>RF,J_DF,RF,2.3,0),COLOR1388D3;
  129. STICKLINE(J_DF>RF,J_DF,RF,1.0,0),COLOR13AAD3;
  130. STICKLINE(J_DF<RF,J_DF,RF,2.3,0),COLOR338833;
  131. STICKLINE(J_DF<RF,J_DF,RF,1.0,0),COLOR33AA33;
  132. STICKLINE(J_DF<RF AND DJ<0.2*MM,J_DF-0.1*MM,RF+0.1*MM,0.1,0),COLOR33AA33;
  133. STICKLINE(J_DF>=RF AND DJ<0.2*MM,J_DF+0.1*MM,RF-0.1*MM,0.1,0),COLOR13AADD;


  134. 以上是位高手发现之旅
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 免费注册
关注微信