public override dynamic Get(IEnumerable <ICandle> source, IIndicatorOptions options = null) { TemaOptions config = options != null ? (TemaOptions)options.Options : new TemaOptions(30, CandleVariableCode.CLOSE); double[] temaValues = new double[source.Count()]; double[] valuesToCheck; if (config.Type == (ICandleVariableCode)CandleVariableCode.OPEN) { valuesToCheck = source.Select(x => Convert.ToDouble(x.Open)).ToArray(); } else if (config.Type == (ICandleVariableCode)CandleVariableCode.LOW) { valuesToCheck = source.Select(x => Convert.ToDouble(x.Low)).ToArray(); } else if (config.Type == (ICandleVariableCode)CandleVariableCode.HIGH) { valuesToCheck = source.Select(x => Convert.ToDouble(x.High)).ToArray(); } else { valuesToCheck = source.Select(x => Convert.ToDouble(x.Close)).ToArray(); } TicTacTec.TA.Library.Core.RetCode tema = TicTacTec.TA.Library.Core.Tema(0, source.Count() - 1, valuesToCheck, config.Period, out int outBegIdx, out int outNbElement, temaValues); if (tema == TicTacTec.TA.Library.Core.RetCode.Success) { return(FixIndicatorOrdering(temaValues.ToList(), outBegIdx, outNbElement)); } throw new Exception("Could not calculate TEMA"); }
public override dynamic Get(IEnumerable <decimal?> source, IIndicatorOptions options = null) { SmaOptions config = options != null ? (SmaOptions)options.Options : new SmaOptions(30, CandleVariableCode.CLOSE); double[] smaValues = new double[source.Count()]; List <double?> outValues = new List <double?>(); int sourceNullCount = source.Count(x => x == null); double[] sourceFix = source.Where(x => x != null).Select(x => Convert.ToDouble(x)).ToArray(); TicTacTec.TA.Library.Core.RetCode sma = TicTacTec.TA.Library.Core.Sma(0, source.Count() - 1 - sourceNullCount, sourceFix, config.Period, out int outBegIdx, out int outNbElement, smaValues); if (sma == TicTacTec.TA.Library.Core.RetCode.Success) { List <decimal?> smas = FixIndicatorOrdering(smaValues.ToList(), outBegIdx, outNbElement); for (int i = 0; i < sourceNullCount; i++) { smas.Insert(0, null); } return(smas); } throw new Exception("Could not calculate SMA!"); }
/// <summary> /// /// </summary> protected void PerformCalculation(object[] parametersArray, int beginIdxPosition, int actualStartingIndex) { // This is how the normal call looks like: // TicTacTec.TA.Library.Core.Adx((int)parameters[0], (int)parameters[1], (double[])parameters[2], // (double[])parameters[3], (double[])parameters[4], (int)parameters[5], // out outBeginIdx, out outNBElemenet, (double[])parameters[8]); TicTacTec.TA.Library.Core.RetCode code = (TicTacTec.TA.Library.Core.RetCode) _methodInfo.Invoke(null, parametersArray); int outBeginIdx = (int)parametersArray[beginIdxPosition]; int outNBElement = (int)parametersArray[beginIdxPosition + 1]; lock (this) { for (int i = 0; outNBElement > 0 && i < _outputArraysParameters.Count; i++) { int index = beginIdxPosition + 2 + i; if (parametersArray[index].GetType() == typeof(double[])) {// Double output. Results.AddSetValues(_outputArraysParameters[i].Name, actualStartingIndex + outBeginIdx, outNBElement, true, (double[])parametersArray[index]); } else if (parametersArray[index].GetType() == typeof(int[])) {// Int output. Results.AddSetValues(_outputArraysParameters[i].Name, actualStartingIndex + outBeginIdx, outNBElement, true, GeneralHelper.IntsToDoubles((int[])parametersArray[index])); } } } }
public static bool MakeBBANDS(int startIdx, int endIdx, double[] list, int period, int kUp, int kDn, out int begin, out int length, double[] outUpperList, double[] outMiddleList, double[] outLowerList) { begin = 0; length = 0; TicTacTec.TA.Library.Core.RetCode retCode = TicTacTec.TA.Library.Core.RetCode.UnknownErr; retCode = TicTacTec.TA.Library.Core.Bbands(startIdx, endIdx, list, period, kUp, kDn, Core.MAType.Sma, out begin, out length, outUpperList, outMiddleList, outLowerList); if (retCode != TicTacTec.TA.Library.Core.RetCode.Success) { return(false); } return(true); }
public static bool MakeStockRSI(int startIdx, int endIdx, double[] list, int rsiPeriod, int fastK_Period, int fastD_Period, out int begin, out int length, double[] outFastK, double[] outFastD) { begin = 0; length = 0; TicTacTec.TA.Library.Core.RetCode retCode = TicTacTec.TA.Library.Core.RetCode.UnknownErr; retCode = TicTacTec.TA.Library.Core.StochRsi(startIdx, endIdx, list, rsiPeriod, fastK_Period, fastD_Period, Core.MAType.Ema, out begin, out length, outFastK, outFastD); if (retCode != TicTacTec.TA.Library.Core.RetCode.Success) { return(false); } return(true); }
public override dynamic Get(IEnumerable <ICandle> source, IIndicatorOptions options = null) { CmoOptions config = options != null ? (CmoOptions)options.Options : new CmoOptions(14); double[] cmoValues = new double[source.Count()]; double[] valuesToCheck = source.Select(x => Convert.ToDouble(x.Close)).ToArray(); TicTacTec.TA.Library.Core.RetCode cmo = TicTacTec.TA.Library.Core.Cmo(0, source.Count() - 1, valuesToCheck, config.Period, out int outBegIdx, out int outNbElement, cmoValues); if (cmo == TicTacTec.TA.Library.Core.RetCode.Success) { return(FixIndicatorOrdering(cmoValues.ToList(), outBegIdx, outNbElement)); } throw new Exception("Could not calculate CMO"); }
//public override Type StateEnumType //{ // get { return typeof(EMAStates); } //} protected override void OnCalculate(int startingIndex, int indecesCount) { _closeResultValues = DataProvider.GetDataValues(BarData.DataValueSourceEnum.Close, startingIndex, indecesCount); double[] emaResults = new double[indecesCount]; int beginIndex = 0; int numberElements = 0; TicTacTec.TA.Library.Core.RetCode code = TicTacTec.TA.Library.Core.Ema(0, indecesCount - 1, _closeResultValues, TimePeriod, out beginIndex, out numberElements, emaResults); System.Diagnostics.Debug.Assert(code == TicTacTec.TA.Library.Core.RetCode.Success); Results.SetResultSetValues("EMA", beginIndex, numberElements, emaResults); }
public override dynamic Get(IEnumerable <ICandle> source, IIndicatorOptions options = null) { MomOptions config = options != null ? (MomOptions)options.Options : new MomOptions(10); double[] momValues = new double[source.Count()]; double[] closes = source.Select(x => Convert.ToDouble(x.Close)).ToArray(); TicTacTec.TA.Library.Core.RetCode mom = TicTacTec.TA.Library.Core.Mom(0, source.Count() - 1, closes, config.Period, out int outBegIdx, out int outNbElement, momValues); if (mom == TicTacTec.TA.Library.Core.RetCode.Success) { return(FixIndicatorOrdering(momValues.ToList(), outBegIdx, outNbElement)); } throw new Exception("Could not calculate MOM!"); }
public override void Process(Tick tick) { TimeFrame tf = TimeFrame; int candleCount = Math.Min(tf.CandleCount, period); double[] priceArray = tf.GetPriceArray(applyTo, candleCount); TicTacTec.TA.Library.Core.RetCode retCode = TicTacTec.TA.Library.Core.MovingAverage( priceArray.Length - 1, priceArray.Length - 1, priceArray, period, (TicTacTec.TA.Library.Core.MAType)method, out begIdx, out nbElement, outReal); if (retCode != TicTacTec.TA.Library.Core.RetCode.Success) { throw new Exception("Error calculating indicator value"); } currentValue = outReal[0]; //switch (method) //{ // case MAMethodType.Simple: // { // sma(candleCount); // break; // } // case MAMethodType.Exponential: // { // ema(candleCount); // break; // } // case MAMethodType.Smoothed: // { // smma(candleCount); // break; // } // case MAMethodType.LinearWeighted: // { // lwma(candleCount); // break; // } // default: // { // throw new Exception("Invalid method"); // } //} }
//public override Type StateEnumType //{ // get { return typeof(ATRStates); } //} protected override void OnCalculate(int startingIndex, int indecesCount) { double[] high = DataProvider.GetDataValues(BarData.DataValueSourceEnum.High, startingIndex, indecesCount); double[] low = DataProvider.GetDataValues(BarData.DataValueSourceEnum.Low, startingIndex, indecesCount); double[] close = DataProvider.GetDataValues(BarData.DataValueSourceEnum.Close, startingIndex, indecesCount); double[] result = new double[high.Length]; int beginIndex, number; TicTacTec.TA.Library.Core.RetCode code = TicTacTec.TA.Library.Core.Atr(0, indecesCount - 1, high, low, close, TimePeriod, out beginIndex, out number, result); System.Diagnostics.Debug.Assert(code == TicTacTec.TA.Library.Core.RetCode.Success); Results.SetResultSetValues("ATR", beginIndex, number, result); }
public override dynamic Get(IEnumerable <decimal?> source, IIndicatorOptions options = null) { RsiOptions config = options != null ? (RsiOptions)options.Options : new RsiOptions(14); double[] rsiValues = new double[source.Count()]; double[] sourceFix = source.Select(x => Convert.ToDouble(x)).ToArray(); TicTacTec.TA.Library.Core.RetCode rsi = TicTacTec.TA.Library.Core.Rsi(0, source.Count() - 1, sourceFix, config.Period, out int outBegIdx, out int outNbElement, rsiValues); if (rsi == TicTacTec.TA.Library.Core.RetCode.Success) { return(FixIndicatorOrdering(rsiValues.ToList(), outBegIdx, outNbElement)); } throw new Exception("Could not calculate RSI"); }
public override dynamic Get(IEnumerable <decimal?> source, IIndicatorOptions options = null) { EmaOptions config = options != null ? (EmaOptions)options.Options : new EmaOptions(30, CandleVariableCode.CLOSE); double[] emaValues = new double[source.Count()]; List <double?> outValues = new List <double?>(); double[] sourceFix = source.Select(x => x.HasValue ? Convert.ToDouble(x) : 0).ToArray(); TicTacTec.TA.Library.Core.RetCode ema = TicTacTec.TA.Library.Core.Ema(0, source.Count() - 1, sourceFix, config.Period, out int outBegIdx, out int outNbElement, emaValues); if (ema == TicTacTec.TA.Library.Core.RetCode.Success) { return(FixIndicatorOrdering(emaValues.ToList(), outBegIdx, outNbElement)); } throw new Exception("Could not calculate EMA!"); }
public override dynamic Get(IEnumerable <ICandle> source, IIndicatorOptions options = null) { SarOptions config = options != null ? (SarOptions)options.Options : new SarOptions(0.02, 02); double[] sarValues = new double[source.Count()]; double[] highs = source.Select(x => Convert.ToDouble(x.High)).ToArray(); double[] lows = source.Select(x => Convert.ToDouble(x.Low)).ToArray(); TicTacTec.TA.Library.Core.RetCode sar = TicTacTec.TA.Library.Core.Sar(0, source.Count() - 1, highs, lows, 0.02, 0.2, out int outBegIdx, out int outNbElement, sarValues); if (sar == TicTacTec.TA.Library.Core.RetCode.Success) { // party return(FixIndicatorOrdering(sarValues.ToList(), outBegIdx, outNbElement)); } throw new Exception("Could not calculate SAR"); }
public override dynamic Get(IEnumerable <ICandle> source, IIndicatorOptions options = null) { MinusDiOptions config = options != null ? (MinusDiOptions)options.Options : new MinusDiOptions(14); double[] diValues = new double[source.Count()]; double[] highs = source.Select(x => Convert.ToDouble(x.High)).ToArray(); double[] lows = source.Select(x => Convert.ToDouble(x.Low)).ToArray(); double[] closes = source.Select(x => Convert.ToDouble(x.Close)).ToArray(); TicTacTec.TA.Library.Core.RetCode minusDi = TicTacTec.TA.Library.Core.MinusDI(0, source.Count() - 1, highs, lows, closes, config.Period, out int outBegIdx, out int outNbElement, diValues); if (minusDi == TicTacTec.TA.Library.Core.RetCode.Success) { return(FixIndicatorOrdering(diValues.ToList(), outBegIdx, outNbElement)); } throw new Exception("Could not calculate EMA"); }
/// <summary> /// Calculates the moving averages for a set of candles /// </summary> /// <param name="candles">The candles</param> /// <param name="periodsAverage">The EMA period</param> /// <returns></returns> public static MovingAverage CalculateEMA(IList <OHLC> candles, int periodsAverage) { double[] closePrice = candles.Select(x => (double)x.Close).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); }
//public override Type StateEnumType //{ // get { return typeof(MACDStates); } //} protected override void OnCalculate(int startingIndex, int indecesCount) { double[] averages = DataProvider.GetDataValues(BarData.DataValueSourceEnum.Average, startingIndex, indecesCount); double[] macd = new double[averages.Length]; double[] macdSignal = new double[averages.Length]; double[] macdHistory = new double[averages.Length]; int beginIndex, number; TicTacTec.TA.Library.Core.RetCode code = TicTacTec.TA.Library.Core.Macd(0, indecesCount - 1, averages, FastPeriod, SlowPeriod, Signal, out beginIndex, out number, macd, macdSignal, macdHistory); System.Diagnostics.Debug.Assert(code == TicTacTec.TA.Library.Core.RetCode.Success); Results.SetResultSetValues("MACD", beginIndex, number, macd); Results.SetResultSetValues("MACDHistory", beginIndex, number, macdHistory); Results.SetResultSetValues("MACDSignal", beginIndex, number, macdSignal); }
public override dynamic Get(IEnumerable <ICandle> source, IIndicatorOptions options = null) { StochRsiOptions config = options != null ? (StochRsiOptions)options.Options : new StochRsiOptions(14, CandleVariableCode.CLOSE, 5, 3, TicTacTec.TA.Library.Core.MAType.Sma); double[] kValues = new double[source.Count()]; double[] dValues = new double[source.Count()]; double[] valuesToCheck; if (config.Type == (ICandleVariableCode)CandleVariableCode.OPEN) { valuesToCheck = source.Select(x => Convert.ToDouble(x.Open)).ToArray(); } else if (config.Type == (ICandleVariableCode)CandleVariableCode.LOW) { valuesToCheck = source.Select(x => Convert.ToDouble(x.Low)).ToArray(); } else if (config.Type == (ICandleVariableCode)CandleVariableCode.HIGH) { valuesToCheck = source.Select(x => Convert.ToDouble(x.High)).ToArray(); } else { valuesToCheck = source.Select(x => Convert.ToDouble(x.Close)).ToArray(); } TicTacTec.TA.Library.Core.RetCode tema = TicTacTec.TA.Library.Core.StochRsi(0, source.Count() - 1, valuesToCheck, config.OptInTimePeriod, config.FastKPeriod, config.FastDPeriod, config.FastDmaType, out int outBegIdx, out int outNbElement, kValues, dValues); if (tema == TicTacTec.TA.Library.Core.RetCode.Success) { return(new StochItem() { D = FixIndicatorOrdering(dValues.ToList(), outBegIdx, outNbElement), K = FixIndicatorOrdering(kValues.ToList(), outBegIdx, outNbElement) }); } throw new Exception("Could not calculate STOCH"); }
public override dynamic Get(IEnumerable <ICandle> source, IIndicatorOptions options = null) { MacdOptions config = options != null ? (MacdOptions)options.Options : new MacdOptions(26, 12, 9); double[] macdValues = new double[source.Count()]; double[] signalValues = new double[source.Count()]; double[] histValues = new double[source.Count()]; double[] closes = source.Select(x => Convert.ToDouble(x.Close)).ToArray(); TicTacTec.TA.Library.Core.RetCode macd = TicTacTec.TA.Library.Core.Macd(0, source.Count() - 1, closes, config.FastPeriod, config.SlowPeriod, config.SignalPeriod, out int outBegIdx, out int outNbElement, macdValues, signalValues, histValues); if (macd == TicTacTec.TA.Library.Core.RetCode.Success) { return(new MacdItem() { Macd = FixIndicatorOrdering(macdValues.ToList(), outBegIdx, outNbElement), Signal = FixIndicatorOrdering(signalValues.ToList(), outBegIdx, outNbElement), Hist = FixIndicatorOrdering(histValues.ToList(), outBegIdx, outNbElement) }); } throw new Exception("Could not calculate MACD!"); }
public override dynamic Get(IEnumerable <ICandle> source, IIndicatorOptions options = null) { StochOptions config = options != null ? (StochOptions)options.Options : new StochOptions(5, 2, TicTacTec.TA.Library.Core.MAType.Sma, 3, TicTacTec.TA.Library.Core.MAType.Sma); double[] kValues = new double[source.Count()]; double[] dValues = new double[source.Count()]; double[] highs = source.Select(x => Convert.ToDouble(x.High)).ToArray(); double[] lows = source.Select(x => Convert.ToDouble(x.Low)).ToArray(); double[] closes = source.Select(x => Convert.ToDouble(x.Close)).ToArray(); TicTacTec.TA.Library.Core.RetCode stoch = TicTacTec.TA.Library.Core.Stoch(0, source.Count() - 1, highs, lows, closes, config.FastKPeriod, config.SlowKPeriod, config.SlowKmaType, config.SlowDPeriod, config.SlowDmaType, out int outBegIdx, out int outNbElement, kValues, dValues); if (stoch == TicTacTec.TA.Library.Core.RetCode.Success) { return(new StochItem() { D = FixIndicatorOrdering(dValues.ToList(), outBegIdx, outNbElement), K = FixIndicatorOrdering(kValues.ToList(), outBegIdx, outNbElement) }); } throw new Exception("Could not calculate STOCH!"); }
protected override void OnCalculate(int startingIndex, int indexCount) { // Format of a TA method. //int startIdx, - mandatory //int endIdx, - mandatory //double[] inReal[added 0/1] or/and inOpen or/and inLow or/and inHigh or/and inClose //int/double optIn[NAME] or/and another one or none - parameters //out int outBegIdx, //out int outNBElement, //double/int[] out[Real/Integer] and or another one // Example: //TicTacTec.TA.Library.Core.RetCode code = TicTacTec.TA.Library.Core.Sma(0, indecesCount - 1, _closeResultValues, Period, out beginIndex, out number, ma); } // Consider the result returned. List <object> parameters = new List <object>(); parameters.Add(0); parameters.Add(indexCount - 1); int outBeginIdxPosition = 0; lock (this) { foreach (ParameterInfo info in _inputDefaultArrayParameters) { parameters.Add(GetInputArrayValues(info.Name, startingIndex, indexCount)); } foreach (object parameter in _inputParametersValues) { parameters.Add(parameter); } outBeginIdxPosition = parameters.Count; // outBeginIdx parameters.Add(0); // outNBElemenet parameters.Add(0); foreach (ParameterInfo info in _outputArraysParameters) { if (info.ParameterType == typeof(double[])) {// Passed arrays must be prepared to the proper size. double[] array = new double[indexCount]; parameters.Add(array); } else if (info.ParameterType == typeof(int[])) {// Passed arrays must be prepared to the proper size. int[] array = new int[indexCount]; parameters.Add(array); } else { Console.WriteLine("Class operation logic error."); } } // This is how the normal call looks like. //TicTacTec.TA.Library.Core.Adx((int)parameters[0], (int)parameters[1], (double[])parameters[2], // (double[])parameters[3], (double[])parameters[4], (int)parameters[5], // out outBeginIdx, out outNBElemenet, (double[])parameters[8]); } object[] parametersArray = parameters.ToArray(); TicTacTec.TA.Library.Core.RetCode code = (TicTacTec.TA.Library.Core.RetCode) _methodInfo.Invoke(null, parametersArray); lock (this) { int outBeginIdx = (int)parametersArray[outBeginIdxPosition]; int outNBElemenet = (int)parametersArray[outBeginIdxPosition + 1]; for (int i = 0; i < _outputArraysParameters.Count; i++) { int index = outBeginIdxPosition + 2 + i; if (parametersArray[index].GetType() == typeof(double[])) { Results.SetResultSetValues(_outputArraysParameters[i].Name, outBeginIdx, outNBElemenet, (double[])parametersArray[index]); } else if (parametersArray[index].GetType() == typeof(int[])) {// Valid scenario, implement. //SystemMonitor.NotImplementedCritical(); Results.SetResultSetValues(_outputArraysParameters[i].Name, outBeginIdx, outNBElemenet, GeneralHelper.IntsToDoubles((int[])parametersArray[index])); } } } }