1

我可以请您帮忙解决以下问题吗?

我想创建一个 MS Jet/Ace/Access 查询,它从价格数据表中返回 10 天指数移动平均线 (EMA)。表格格式及其一小部分数据如下……</p>

TableName = Spot
ID (AutoNumber) aDate (DateTime)        Settle (Double)
1               01/10/2007              16.056
2               02/10/2007              15.625
3               03/10/2007              15.655
4               04/10/2007              15.686
5               05/10/2007              15.810
6               08/10/2007              15.665
7               09/10/2007              15.908
8               10/10/2007              16.004
9               11/10/2007              16.319
10              12/10/2007              16.233

如果您不了解指数移动平均线,以下网站可能有助于解释它们……</p>

http://stockcharts.com/help/doku.php?id=chart_school:technical_indicators:moving_averages#exponential_moving_a

http://www.pandacash.com/technical-analysis/moving-average/exponential.htm

但是,希望我可以向您解释这个等式。

Todays EMA = (Settle * Exponent) + ((1 - Exponent) * Yesterdays EMA)

在哪里

Settle = Closing price of the Stock / Asset
Exponent = (2 / (10 Days + 1)) ie 0.1818

我有一个查询返回我需要的一些值,但我无法找到整个事情的解决方案。

到目前为止,我的查询(希望格式可以更清晰地阅读)

SELECT aDate, Settle, 

   (SELECT((SELECT Settle 
            FROM   SPOT AS SubQ 
            WHERE  SubQ.ID = SS.ID)) 
    FROM   SPOT AS SS 
    WHERE  SS.ID = Spot.ID - 1) AS YesterdaySettle,

   ( 2 / 11 ) AS Exponent,

   (SELECT Settle 
    FROM   SPOT AS SS 
    WHERE  SS.ID = Spot.ID) * ( Exponent ) AS [Part A],

   ( 1 - Exponent ) AS [Part B],

   (SELECT ((SELECT Settle 
              FROM   SPOT AS SubQ 
              WHERE  SubQ.ID = SS.ID) * ( 2 / 11 )) 
    FROM   SPOT AS SS 
    WHERE  SS.ID = Spot.ID - 1) AS [Yesterdays Part A],

   (SELECT SUM(Settle) 
    FROM   SPOT AS SubQ 
    WHERE  ID BETWEEN Spot.ID AND Spot.ID -9) / Iif(Spot.id > 10, 10, Spot.id) AS [10DMA] 

FROM   SPOT
ORDER  BY aDate; 

根据我的查询的字段名称,我的等式将是……</p>

Todays EMA = ([Part A])  + ([Part B] * [Part C])

我希望结果类似于以下内容。

[10DMA] [Exponent]  [Part A]    [Part B]    [Part C] (Previous EMA)     [EMA]
15.896  0.181818182 2.919272727 0.818181818     USE 10DMA ie 15.896     15.925
15.911  0.181818182 2.840909091 0.818181818                 15.925      15.871
15.945  0.181818182 2.846363636 0.818181818                 15.871      15.831
15.985  0.181818182 2.852       0.818181818                 15.831      15.805
16.027  0.181818182 2.874545455 0.818181818                 15.805      15.806
16.037  0.181818182 2.848181818 0.818181818                 15.806      15.780
16.052  0.181818182 2.892363636 0.818181818                 15.780      15.803
16.054  0.181818182 2.909818182 0.818181818                 15.803      15.840
16.039  0.181818182 2.967090909 0.818181818                 15.840      15.927
16.025  0.181818182 2.951454545 0.818181818                 15.927      15.983                  

问题是我不知道如何创建 [Part C] 字段。

有些观点是……</p>

  • 如果一天没有 EMA,则 [Part C] 值应为 [10DMA]。例如,第一条记录没有 EMA,所以我需要使用 [10DMA]。
  • 如果昨天有一个 EMA,那么将这个值用于今天 [C 部分]。

我可以请教一些建议吗?到目前为止,我有点偶然发现了我所拥有的东西,但我对 C 部分的价值感到困惑。

我以为我可以按照以下方式做一些事情……</p>

iif (EMA <> 0, EMA, [10DMA]) AS [Part C],
    (([Part A]) + ([Part B] * [Part C])) AS EMA

但是,我收到一个与

Circular reference caused by alias 'Part C'.

任何建议将不胜感激。非常感谢您的时间。

约翰。

4

0 回答 0