自通达信软件的专用函数XMA偏移移动平均问世以来,引起了热议。原因并不在于其带未来性质的准确性,而在于其一直没有公开的源代码或者说数学表达式。今天不准备就其原理及其运用多啰嗦,我们只要用搜索引擎就能在网上找到很多关于XMA的东东。
下面发两套源码,一是飞狐版的XMA,二是通达信上使用的XMA验证源码,供同好者研究参考。
{公式显示:XMA(C,N);N值最大做到50}
先上图:
飞狐版XMA:
INPUT:N(7,1,50);
P:=(DATACOUNT-BARPOS+1);
XMA:IF(P=1,REFX(MA(CLOSE,N/2+1),N/2),IF(P=2 AND N>1,
REFX(MA(CLOSE,N/2+2),N/2),IF(P=3 AND N>4,REFX(MA(CLOSE,N/2+3),N/2),
IF(P=4 AND N>6,REFX(MA(CLOSE,N/2+4),N/2),IF(P=5 AND N>8,
REFX(MA(CLOSE,N/2+5),N/2),IF(P=6 AND N>10,REFX(MA(CLOSE,N/2+6),N/2),
IF(P=7 AND N>12,REFX(MA(CLOSE,N/2+7),N/2),IF(P=8 AND
N>14,REFX(MA(CLOSE,N/2+8),N/2),IF(P=9 AND N>16,REFX(MA(CLOSE,N/2+9),N/2),
IF(P=10 AND N>18,REFX(MA(CLOSE,N/2+10),N/2),IF(P=11 AND
N>20,REFX(MA(CLOSE,N/2+11),N/2),IF(P=12 AND N>22,REFX(MA(CLOSE,N/2+12),
N/2),IF(P=13 AND N>24,REFX(MA(CLOSE,N/2+13),N/2),IF(P=14
AND N>26,REFX(MA(CLOSE,N/2+14),N/2),IF(P=15 AND N>28,REFX(MA(CLOSE,N/2+15),
N/2),IF(P=16 AND N>30,REFX(MA(CLOSE,N/2+16),N/2),IF(P=17
AND N>32,REFX(MA(CLOSE,N/2+17),N/2),IF(P=18 AND N>34,REFX(MA(CLOSE,N/2+18),
N/2),IF(P=19 AND N>36,REFX(MA(CLOSE,N/2+19),N/2),IF(P=20
AND N>38,REFX(MA(CLOSE,N/2+20),N/2),IF(P=21 AND N>40,REFX(MA(CLOSE,N/2+21),
N/2),IF(P=22 AND N>42,REFX(MA(CLOSE,N/2+22),N/2),IF(P=23
AND N>44,REFX(MA(CLOSE,N/2+23),N/2),IF(P=24 AND N>46,REFX(MA(CLOSE,N/2+24),
N/2),REFX(MA(CLOSE,N),(N+1)/2-1)))))))))))))))))))))))));
通达信XMA验证版:
系统XMA:XMA(C,N);
X:IF(CURRBARSCOUNT=1,REFX(MA(C,N/2+1),N/2),IF(CURRBARSCOUNT=2 AND N>1,
REFX(MA(C,N/2+2),N/2),IF(CURRBARSCOUNT=3 AND N>4,REFX(MA(C,N/2+3),N/2),
IF(CURRBARSCOUNT=4 AND N>6,REFX(MA(C,N/2+4),N/2),IF(CURRBARSCOUNT=5 AND N>8,
REFX(MA(C,N/2+5),N/2),IF(CURRBARSCOUNT=6 AND N>10,REFX(MA(C,N/2+6),N/2),
IF(CURRBARSCOUNT=7 AND N>12,REFX(MA(C,N/2+7),N/2),IF(CURRBARSCOUNT=8 AND
N>14,REFX(MA(C,N/2+8),N/2),IF(CURRBARSCOUNT=9 AND N>16,REFX(MA(C,N/2+9),N/2),
IF(CURRBARSCOUNT=10 AND N>18,REFX(MA(C,N/2+10),N/2),IF(CURRBARSCOUNT=11 AND
N>20,REFX(MA(C,N/2+11),N/2),IF(CURRBARSCOUNT=12 AND N>22,REFX(MA(C,N/2+12),
N/2),IF(CURRBARSCOUNT=13 AND N>24,REFX(MA(C,N/2+13),N/2),IF(CURRBARSCOUNT=14
AND N>26,REFX(MA(C,N/2+14),N/2),IF(CURRBARSCOUNT=15 AND N>28,REFX(MA(C,N/2+15),
N/2),IF(CURRBARSCOUNT=16 AND N>30,REFX(MA(C,N/2+16),N/2),IF(CURRBARSCOUNT=17
AND N>32,REFX(MA(C,N/2+17),N/2),IF(CURRBARSCOUNT=18 AND N>34,REFX(MA(C,N/2+18),
N/2),IF(CURRBARSCOUNT=19 AND N>36,REFX(MA(C,N/2+19),N/2),IF(CURRBARSCOUNT=20
AND N>38,REFX(MA(C,N/2+20),N/2),IF(CURRBARSCOUNT=21 AND N>40,REFX(MA(C,N/2+21),
N/2),IF(CURRBARSCOUNT=22 AND N>42,REFX(MA(C,N/2+22),N/2),IF(CURRBARSCOUNT=23
AND N>44,REFX(MA(C,N/2+23),N/2),IF(CURRBARSCOUNT=24 AND N>46,REFX(MA(C,N/2+24),
N/2),REFX(MA(C,N),(N+1)/2-1)))))))))))))))))))))))));
有了飞狐和通达信的XMA,有人会想到要大智慧的,哈哈,别想了!函数所限无法实现。
当年已跟大智慧官方提出过好多次,要求增加函数以及数组,回答是“已够用了”,无语中........
本文作者:周易2000 |