What is the data order for ta-lib calculations
Asked Answered
O

2

5

I have the following candles

+----------------+-------+----------+---------+----------+
|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      |
+----------------+-------+----------+---------+----------+

I use TA-lib to calculate Ema's as follows

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;
}

Question is whats the correct candle order with the most recent entry as top or bottom? How does the library make the calculation ? should i reverse candles list before Calculating Ema? Also i have the same question for macd calculation

Thank you,

Orourke answered 21/1, 2014 at 14:17 Comment(1)
i am using ta-lib in my C# project but stuck in EMA calculation. Can you please check my question and answer me accordingly. #40028551Endowment
S
5

Earliest date/time is the FIRST element in the array - element[0]. Chronological order = array order. Your most recent time (the last time) should be the LAST element in the array.
This logic works for all TA-Lib functions.

Severance answered 27/8, 2015 at 17:35 Comment(0)
D
3
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;
}
Dwarfism answered 16/6, 2014 at 10:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.