2014-01-21 9 views
2

我有以下的蠟燭什麼是TA-lib的計算數據順序

+----------------+-------+----------+---------+----------+ 
|date   |curency|high_price|low_price|last_price| 
+----------------+-------+----------+---------+----------+ 
|2014-01-16 16:07|2  |24.98  |23.9  |24.2  | 
+----------------+-------+----------+---------+----------+ 
|2014-01-16 16:06|2  |24.98  |23.9  |24.12202 | 
+----------------+-------+----------+---------+----------+ 
|2014-01-16 16:05|2  |24.98  |23.9  |24.12202 | 
+----------------+-------+----------+---------+----------+ 
|2014-01-16 16:04|2  |24.98  |23.9  |24.21626 | 
+----------------+-------+----------+---------+----------+ 
|2014-01-16 16:03|2  |24.98  |23.9  |24.11102 | 
+----------------+-------+----------+---------+----------+ 
|2014-01-16 16:02|2  |24.98  |23.9  |24.21628 | 
+----------------+-------+----------+---------+----------+ 
|2014-01-16 16:01|2  |24.98  |23.9  |24.2  | 
+----------------+-------+----------+---------+----------+ 
|2014-01-16 16:00|2  |24.98  |23.9  |24.2  | 
+----------------+-------+----------+---------+----------+ 

我用TA-lib的計算EMA的如下

public MovingAverage CalculateEMA(List<OHLC> candles, int periodsAverage) 
{ 
    double[] closePrice = candles.Select(x => (double)x.last_price).ToArray(); 
    double[] output = new double[closePrice.Length]; 
    int begin; 
    int length; 

    TicTacTec.TA.Library.Core.RetCode retCode = Core.Ema(0, closePrice.Length - 1, closePrice, periodsAverage, out begin, out length, output); 

    if (retCode == TicTacTec.TA.Library.Core.RetCode.Success) 
     return new MovingAverage() { Begin = begin, Length = length, Output = output, Period = periodsAverage }; 

    return null; 
} 

的問題是什麼正確的蠟燭以便與最新的條目是頂部還是底部? 圖書館如何進行計算?我應該在計算Ema之前反轉蠟燭列表嗎? 另外我有用於計算MACD同樣的問題

謝謝

+0

我在我的C#項目中使用ta-lib,但卡在EMA計算中。你可以請檢查我的問題並相應地回答我。 http://stackoverflow.com/questions/40028051/c-sharp-ta-lib-exponential-moving-averageema-calculation –

回答

2

最早的日期/時間是陣列中的第一個元素 - 元素[0]。時間順序=數組順序。最近一次(最後一次)應該是數組中的最後一個元素。
此邏輯適用於所有TA-Lib功能。

2
public static double TA_MACDTest(int startIdx,int endIdx,Object[] InputValues, int FastEMAPeriods, int SlowEMAPeriods, int SignalEMAPeriods) 
{ 
    int i = 1; 
    double[] newInputValues = new double[InputValues.Count()]; 
    int intItr = 0; 
    foreach (object objValue in InputValues) 
    { 
     newInputValues[intItr] = Convert.ToDouble(objValue); 
     intItr = intItr + 1; 
    } 
    int outBegIdx; 
    int outNBElement; 

    double[] outMACD = new double[endIdx - startIdx + 1]; 
    double[] outMACDSignal = new double[endIdx - startIdx + 1]; 
    double[] outMACDHist = new double[endIdx - startIdx + 1]; 

    Core.RetCode res = Core.Macd(startIdx, endIdx, newInputValues, FastEMAPeriods, SlowEMAPeriods, SignalEMAPeriods, out outBegIdx, out outNBElement, outMACD, outMACDSignal, outMACDHist); 
    List<Macdres> resarr = new List<Macdres>(endIdx - startIdx + 1); 
    Macdres macdres = new Macdres(); 
    macdres.Index = i; 
    macdres.Macd = outMACD.Last(); 
    macdres.Signal = outMACDSignal[i]; 
    macdres.MacdHistogram = outMACDHist[i]; 
    return macdres.Macd; 
}