예제 #1
0
파일: Program.cs 프로젝트: zeropool/Vigoth
        public void MACD()
        {
            //you'll probably have to do this next call every time you add a value to your data array
            //I haven't checked this in a live app yet
            resetArrayValues();

            //The "lookback" is really your indicator's period minus one because it's expressed as an array index
            //At least that's true for movingAverage(...)
            lookback = Core.MacdLookback(9, 12, 26);

            double[] MacD   = new double[fclose.Length];
            double[] Signal = new double[fclose.Length];
            double[] Hist   = new double[fclose.Length];

            Console.WriteLine("Starting everthing off...");
            Console.WriteLine("Lookback=" + Convert.ToString(lookback));
            Console.WriteLine("outBegIdx.value=" + Convert.ToString(outBegIdx));
            Console.WriteLine("outNbElement.value=" + Convert.ToString(outNbElement));
            retCode = Core.Macd(0, fclose.Length - 1, fclose, 12, 24, 9, out outBegIdx, out outNbElement, MacD, Signal, Hist);

            double[] roc = new double[fclose.Length];

            retCode = Core.Roc(0, fclose.Length - 1, fclose, 14, out outBegIdx, out outNbElement, roc);

            showDefaultTALIBOutput();
            showFinalOutput();

            for (int x = 0; x < roc.Length - 1; x++)
            {
                Console.WriteLine($"roc:{roc[x]}");
            }
            Console.Read();
        }
예제 #2
0
 internal TaLibMacdResult(double[] line, double[] signal, double[] histogram, Core.RetCode ret, int index)
     : base(line, ret, index)
 {
     MacdHistogram = histogram;
     MacdLine      = line;
     MacdSignal    = signal;
 }
예제 #3
0
        /// <summary>
        /// Calculation of LINEARREG_INTERCEPT indicators
        /// </summary>
        /// <param name="db">data to calculate LINEARREG_INTERCEPT</param>
        /// <param name="period">period to calculate</param>
        /// <param name="name"></param>
        public LINEARREG_INTERCEPT(DataSeries db, double period, string name)
            : base(db, name)
        {
            int begin = 0, length = 0;

            Core.RetCode retCode = Core.RetCode.UnknownErr;

            double[] output = new double[db.Count];

            retCode = Core.LinearRegIntercept(0, db.Count - 1, db.Values, (int)period, out begin, out length, output);

            if (retCode != Core.RetCode.Success)
            {
                return;
            }
            //Assign first bar that contains indicator data
            if (length <= 0)
            {
                FirstValidValue = begin + output.Length + 1;
            }
            else
            {
                FirstValidValue = begin;
            }
            this.Name = name;

            for (int i = begin, j = 0; j < length; i++, j++)
            {
                this[i] = output[j];
            }
        }
예제 #4
0
파일: Stock.cs 프로젝트: chandusekhar/Gip
        public void tawrap(int fastk, int k, int d, DateTime from, int period, out int begid, out int noblemen, out Core.RetCode b)
        {
            TradingDay mod   = History.OrderBy(x => Math.Abs(x.TradeDate.Ticks - from.Ticks)).First();
            int        index = History.IndexOf(mod);

            double[] Highs    = History.Select(x => x.High).ToArray();
            double[] Lows     = History.Select(x => x.Low).ToArray();
            double[] Close    = History.Select(x => x.ClosingPrice).ToArray();
            int      endindex = index + period;

            int begidx;
            int NBElement;

            double[]     slowk = new double[endindex];
            double[]     slowd = new double[endindex];
            Core.RetCode a     = TicTacTec.TA.Library.Core.Stoch(index, endindex, Highs, Lows, Close, fastk, k, Core.MAType.Ema, d, Core.MAType.Ema, out begidx, out NBElement, slowk, slowd);

            begid    = begidx;
            noblemen = NBElement;
            b        = a;

            Stoick = slowk.ToList();
            Stoicd = slowd.ToList();

            System.IO.StreamWriter t = new System.IO.StreamWriter(@"C:\Temp\Res.csv");


            for (int i = 0; i < endindex; i++)
            {
                string wrietline = Environment.NewLine + slowk[i] + " ," + slowd[i];
                t.Write(wrietline);
            }
        }
예제 #5
0
        public static BollingerBand CalculateBB(IList <OHLC> candles, int periodsAverage)
        {
            var upperDeviation = 1.00;
            var lowerDeviation = 0.50;

            double[] closePrice = candles.Select(x => (double)x.Close).ToArray();
            double[] upperBand  = new double[closePrice.Length];
            double[] midBand    = new double[closePrice.Length];
            double[] lowerBand  = new double[closePrice.Length];
            int      begin;
            int      length;

            Core.RetCode retCode = Core.Bbands(0, closePrice.Length - 1, closePrice, periodsAverage, upperDeviation, lowerDeviation, Core.MAType.Ema, out begin, out length, upperBand, midBand, lowerBand);

            if (retCode == Core.RetCode.Success)
            {
                return new BollingerBand()
                       {
                           Begin = begin, Length = length, UpperBand = upperBand, MidBand = midBand, LowerBand = lowerBand, Period = periodsAverage
                       }
            }
            ;

            return(null);
        }
    }
예제 #6
0
        protected override List <Signal> GetSignalsBase(HistoricalData historicalData, List <Signal> dependencySignals = null)
        {
            List <Signal> resultSignals = new List <Signal>();

            int count  = historicalData.Count;
            int endIdx = count - 1;
            int outBegIdx;
            int outNbElement;

            double[] outFastK = new double[count];
            double[] outFastD = new double[count];

            Core.RetCode retCode = Core.StochF(StartIdx, endIdx, historicalData.High, historicalData.Low, historicalData.Close, OptInFastKPeriod,
                                               OptInSlowKPeriod, Core.MAType.Sma, out outBegIdx, out outNbElement, outFastK, outFastD);

            if (retCode != Core.RetCode.Success)
            {
                LogError(retCode);
            }
            else
            {
                resultSignals = GetSignals(historicalData.SecurityCode, outFastK, historicalData.Date, outBegIdx, outNbElement);
            }
            return(resultSignals);
        }
예제 #7
0
        protected override List <Signal> GetSignalsBase(HistoricalData historicalData, List <Signal> dependencySignals = null)
        {
            List <Signal> signals = new List <Signal>();

            int count  = historicalData.Count;
            int endIdx = count - 1;

            int outBegIdx;
            int outNbElement;

            double[] outWma = new double[count];
            double[] inReal = GetInRealArray(historicalData);

            Core.RetCode retCode = Core.Wma(StartIdx, endIdx, inReal, AvgPeriod, out outBegIdx, out outNbElement, outWma);
            if (retCode != Core.RetCode.Success)
            {
                LogError(retCode);
            }
            else
            {
                signals = GetSignals(historicalData.SecurityCode, outWma, historicalData.Date, outBegIdx, outNbElement);
            }

            return(signals);
        }
예제 #8
0
        public CDLBELTHOLD(DataBars db, string name)
            : base(db, name)
        {
            int begin = 0, length = 0;

            Core.RetCode retCode = Core.RetCode.UnknownErr;

            int[] output = new int[db.Count];

            retCode = Core.CdlBeltHold(0, db.Count - 1, db.Open.Values, db.High.Values, db.Low.Values, db.Close.Values, out begin, out length, output);

            if (retCode != Core.RetCode.Success)
            {
                return;
            }
            //Assign first bar that contains indicator data
            if (length <= 0)
            {
                FirstValidValue = begin + output.Length + 1;
            }
            else
            {
                FirstValidValue = begin;
            }
            this.Name = name;
            for (int i = begin, j = 0; j < length; i++, j++)
            {
                this[i] = output[j];
            }
        }
예제 #9
0
        /// <summary>
        /// Calculation of WILLR indicators
        /// </summary>
        /// <param name="db">data to calculate WILLR</param>
        /// <param name="period">period to calculate</param>
        /// <param name="name"></param>
        public WILLR(DataBars db, double period, string name)
            : base(db, name)
        {
            int begin = 0, length = 0;

            Core.RetCode retCode = Core.RetCode.UnknownErr;

            double[] output = new double[db.Count];

            retCode = Core.WillR(0, db.Count - 1, db.High.Values, db.Low.Values, db.Close.Values, (int)period, out begin, out length, output);

            if (retCode != Core.RetCode.Success)
            {
                return;
            }
            //Assign first bar that contains indicator data
            if (length <= 0)
            {
                FirstValidValue = begin + output.Length + 1;
            }
            else
            {
                FirstValidValue = begin;
            }
            this.Name = name;

            for (int i = begin, j = 0; j < length; i++, j++)
            {
                this[i] = output[j];
            }
        }
예제 #10
0
        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;

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

            double[] bias = new double[output.Length];
            if (retCode == Core.RetCode.Success)
            {
                for (int i = 0; i < output.Length; i++)
                {
                    if (output[i] != 0)
                    {
                        bias[i] = 100 * (closePrice[i] - output[i]) / output[i];
                    }
                }

                return(new MovingAverage()
                {
                    Begin = begin, Length = length, Output = output, Bias = bias, Period = periodsAverage
                });
            }

            return(null);
        }
예제 #11
0
        protected override List <Signal> GetSignalsBase(HistoricalData historicalData, List <Signal> dependencySignals = null)
        {
            List <Signal> signals = new List <Signal>();

            if (historicalData == null)
            {
                return(signals);
            }

            int count = historicalData.Count;

            int endIdx = count - 1;

            int outBegIdx;
            int outNbElement;

            double[] outPpo = new double[count];

            Core.RetCode retCode = Core.Ppo(StartIdx, endIdx, historicalData.Close, FastPeriod, SlowPeriod, Core.MAType.Ema, out outBegIdx, out outNbElement, outPpo);
            if (retCode != Core.RetCode.Success)
            {
                LogError(retCode);
            }
            else
            {
                signals = GetSignals(historicalData.SecurityCode, outPpo, historicalData.Date, outBegIdx, outNbElement);
            }

            return(signals);
        }
예제 #12
0
        /// <summary>
        /// Calculation of Average True Range indicators
        /// </summary>
        /// <param name="db">data to calculate HT_DCPERIOD</param>
        /// <param name="period">the period</param>
        /// <param name="name"></param>
        public HT_DCPERIOD(DataSeries db, string name)
            : base(db, name)
        {
            int begin = 0, length = 0;

            Core.RetCode retCode = Core.RetCode.UnknownErr;

            double[] output = new double[db.Count];

            retCode = Core.HtDcPeriod(0, db.Count - 1, db.Values, out begin, out length, output);

            if (retCode != Core.RetCode.Success)
            {
                return;
            }
            //Assign first bar that contains indicator data
            if (length <= 0)
            {
                FirstValidValue = begin + output.Length + 1;
            }
            else
            {
                FirstValidValue = begin;
            }
            this.Name = name;
            for (int i = begin, j = 0; j < length; i++, j++)
            {
                this[i] = output[j];
            }
        }
예제 #13
0
        private void CheckCandlePatternResult(Core.RetCode ret, int outBegIdx, int outNBElement, int[] outInteger, string candlePatternFile)
        {
            //if (!m_minOutNBElements.ContainsKey(m_currentPeriod))
            //{
            //    m_minOutNBElements[m_currentPeriod] = outNBElement - (minOutBegIdx - outBegIdx);
            //}
            //int minOutNBElement = m_minOutNBElements[m_currentPeriod];
            int minOutNBElement = outInteger.Length - minOutBegIdx;

            WekaUtils.DebugAssert(ret == Core.RetCode.Success, "ret == Core.RetCode.Success");
            WekaUtils.DebugAssert(outBegIdx <= minOutBegIdx, "outBegIdx <= minOutBegIdx");
            WekaUtils.DebugAssert(outNBElement >= minOutNBElement + (minOutBegIdx - outBegIdx), "outNBElement >= minOutNBElement + (minOutBegIdx - outBegIdx)");

            using (StreamWriter sw = new StreamWriter(candlePatternFile, true))
            {
                for (int i = 0; i < minOutNBElement; ++i)
                {
                    WekaUtils.DebugAssert(outInteger[minOutBegIdx - outBegIdx + i] != -1, "outInteger[minOutBegIdx - outBegIdx + i] != -1");

                    sw.Write(outInteger[minOutBegIdx - outBegIdx + i]);
                    sw.Write(",");
                }
                sw.WriteLine();
            }
            //WekaUtils.DebugAssert(outInteger[minOutBegIdx - outBegIdx + minOutNBElement - 1 + 1] == -1);
            for (int i = 0; i < outInteger.Length; ++i)
            {
                outInteger[i] = -1;
            }
        }
예제 #14
0
 private static void ErrChk(Core.RetCode retCode)
 {
     if (retCode != Core.RetCode.Success)
     {
         logger.Error("Error:" + retCode);
     }
 }
예제 #15
0
        /// <summary>
        /// Returns the True Range indicator
        /// </summary>
        /// <param name="high"></param>
        /// <param name="low"></param>
        /// <param name="close"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        public TaLibSingleResult TrueRange(double[] high, double[] low, double[] close, int offset = 0)
        {
            double[] output = new double[high.Length];
            int      begin;
            int      length;

            Core.RetCode retCode = Core.TrueRange(0, high.Length - 1 - offset, high, low, close, out begin, out length, output);

            //Return the return object
            return(new TaLibSingleResult(output, retCode, length));
        }
예제 #16
0
        /// <summary>
        /// Returns the Parabolic SAR calculated value
        /// </summary>
        /// <param name="high"></param>
        /// <param name="low"></param>
        /// <param name="acc"></param>
        /// <param name="max"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        public TaLibSingleResult Sar(double[] high, double[] low, double acc, double max, int offset = 0)
        {
            int begin;
            int length;

            double[] output = new double[high.Length];

            Core.RetCode retCode = Core.Sar(0, high.Length - 1 - offset, high, low, acc, max, out begin, out length, output);

            //Return the return object
            return(new TaLibSingleResult(output, retCode, length));
        }
예제 #17
0
        /// <summary>
        /// Used for general Moving Average calculations
        /// </summary>
        /// <param name="input"></param>
        /// <param name="period"></param>
        /// <param name="maType"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        public TaLibSingleResult Ma(double[] input, int period, int maType, int offset = 0)
        {
            double[] output = new double[input.Length];
            int      begin;
            int      length;

            Core.RetCode retCode = Core.MovingAverage(0, input.Length - 1 - offset, input,
                                                      period, (Core.MAType)maType, out begin, out length, output);

            //Return the return object
            return(new TaLibSingleResult(output, retCode, length));
        }
예제 #18
0
        /// <summary>
        /// Returns the Commodity Channel Index calculated value
        /// </summary>
        /// <param name="high"></param>
        /// <param name="low"></param>
        /// <param name="close"></param>
        /// <param name="period"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        public TaLibSingleResult Cci(double[] high, double[] low, double[] close, int period, int offset = 0)
        {
            int begin;
            int length;

            double[] result = new double[high.Length];

            Core.RetCode retCode = Core.Cci(0, high.Length - 1 - offset, high, low, close, period, out begin, out length, result);

            //Return the return object
            return(new TaLibSingleResult(result, retCode, length));
        }
예제 #19
0
        /// <summary>
        /// Calculate the RSI based on the input data
        /// </summary>
        /// <param name="input"></param>
        /// <param name="period"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        public TaLibSingleResult Rsi(double[] input, int period, int offset = 0)
        {
            double[] output = new double[input.Length];
            int      begin;
            int      length;

            Core.RetCode retCode = Core.Rsi(0, input.Length - 1 - offset, input,
                                            period, out begin, out length, output);

            //Return the return object
            return(new TaLibSingleResult(output, retCode, length));
        }
예제 #20
0
        /// <summary>
        /// Returns the MACD indicator
        /// </summary>
        /// <param name="input"></param>
        /// <param name="fastperiod"></param>
        /// <param name="slowperiod"></param>
        /// <param name="signalperiod"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        public TaLibMacdResult Macd(double[] input, int fastperiod, int slowperiod, int signalperiod, int offset = 1)
        {
            double[] macdline   = new double[input.Length];
            double[] macdsignal = new double[input.Length];
            double[] macdhisto  = new double[input.Length];
            int      begin;
            int      length;

            Core.RetCode retCode = Core.Macd(0, input.Length - 1 - offset, input,
                                             fastperiod, slowperiod, signalperiod, out begin, out length, macdline, macdsignal, macdhisto);

            return(new TaLibMacdResult(macdline, macdsignal, macdhisto, retCode, length));
        }
예제 #21
0
 public static bool MakeStochasticFast(int startIdx, int endIdx, double[] hiList, double[] loList, double[] closeList,
                                       int fastK_Period, int fastD_Period,
                                       out int begin, out int length, double[] outFastK, double[] outFastD)
 {
     begin = 0; length = 0;
     Core.RetCode retCode = Core.StochF(startIdx, endIdx, hiList, loList, closeList, fastK_Period, fastD_Period, Core.MAType.Sma,
                                        out begin, out length, outFastK, outFastD);
     if (retCode != TicTacTec.TA.Library.Core.RetCode.Success)
     {
         return(false);
     }
     return(true);
 }
예제 #22
0
        /// <summary>
        /// Returns the Bollinger Bands calculated value
        /// </summary>
        /// <param name="input"></param>
        /// <param name="sdUp"></param>
        /// <param name="sdLow"></param>
        /// <param name="period"></param>
        /// <param name="maType"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        public TaLibBandResult Bbands(double[] input, double sdUp, double sdLow, int period, int maType = 0, int offset = 0)
        {
            int begin;
            int length;

            double[] upperBand  = new double[input.Length];
            double[] middleBand = new double[input.Length];
            double[] lowerBand  = new double[input.Length];

            Core.RetCode retCode = Core.Bbands(0, input.Length - 1 - offset, input, period, sdUp, sdLow, (Core.MAType)maType, out begin, out length, upperBand, middleBand, lowerBand);

            //Return the return object
            return(new TaLibBandResult(upperBand, middleBand, lowerBand, retCode, length));
        }
예제 #23
0
        /// <summary>
        /// Returns the Aroon calculated value
        /// </summary>
        /// <param name="high"></param>
        /// <param name="low"></param>
        /// <param name="period"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        public TaLibAroonResult Aroon(double[] high, double[] low, int period, int offset = 0)
        {
            int begin;
            int length;

            double[] ups   = new double[high.Length];
            double[] downs = new double[high.Length];

            Core.RetCode retCode = Core.Aroon(0, high.Length - 1 - offset, high, low,
                                              period, out begin, out length, downs, ups);

            //Return the return object
            return(new TaLibAroonResult(ups, downs, retCode, length));
        }
예제 #24
0
        /// <summary>
        /// Returns the Stochastic Oscillator indicator
        /// </summary>
        /// <param name="high"></param>
        /// <param name="low"></param>
        /// <param name="close"></param>
        /// <param name="fastperiod"></param>
        /// <param name="slowperiod"></param>
        /// <param name="slowDperiod"></param>
        /// <param name="matype"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        public TaLibStochResult Stoch(double[] high, double[] low, double[] close,
                                      int fastperiod, int slowperiod, int slowDperiod, Core.MAType matype, int offset = 1)
        {
            double[] outputK = new double[high.Length];
            double[] outputD = new double[high.Length];

            int begin;
            int length;

            Core.RetCode retCode = Core.Stoch(0, high.Length - 1 - offset, high, low, close,
                                              fastperiod, slowperiod, matype, slowDperiod, matype, out begin, out length, outputK, outputD);

            return(new TaLibStochResult(outputK, outputD, retCode, length));
        }
예제 #25
0
        /// <summary>
        /// Calculate the Directional Movement Index based on the inserted values
        /// </summary>
        /// <param name="high"></param>
        /// <param name="low"></param>
        /// <param name="period"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        public TaLibDmiResult Dmi(double[] high, double[] low, int period, int offset = 1)
        {
            double[] plusoutput = new double[high.Length];
            double[] minoutput  = new double[high.Length];
            int      begin;
            int      length;

            Core.RetCode retCode = Core.MinusDM(0, high.Length - 1 - offset, high, low,
                                                period, out begin, out length, plusoutput);

            Core.MinusDM(0, high.Length - 1 - offset, high, low,
                         period, out begin, out length, minoutput);

            return(new TaLibDmiResult(plusoutput, minoutput, retCode, length));
        }
예제 #26
0
        protected baseDX(DataBars db, Types type, double period, string name) : base(db, name)
        {
            int begin = 0, length = 0;

            Core.RetCode retCode = Core.RetCode.UnknownErr;
            double[]     output  = new double[db.Count];
            switch (type)
            {
            case Types.ADX:
                retCode = Core.Dx(0, db.Count - 1, db.High.Values, db.Low.Values, db.Close.Values, (int)period, out begin, out length, output);
                break;

            case Types.PlusDI:
                retCode = Core.PlusDI(0, db.Count - 1, db.High.Values, db.Low.Values, db.Close.Values, (int)period, out begin, out length, output);
                break;

            case Types.MinusDI:
                retCode = Core.MinusDI(0, db.Count - 1, db.High.Values, db.Low.Values, db.Close.Values, (int)period, out begin, out length, output);
                break;

            case Types.MinusDM:
                retCode = Core.MinusDM(0, db.Count - 1, db.High.Values, db.Low.Values, (int)period, out begin, out length, output);
                break;

            case Types.PlusDM:
                retCode = Core.PlusDM(0, db.Count - 1, db.High.Values, db.Low.Values, (int)period, out begin, out length, output);
                break;
            }
            if (retCode != Core.RetCode.Success)
            {
                return;
            }
            //Assign first bar that contains indicator data
            if (length <= 0)
            {
                FirstValidValue = begin + output.Length + 1;
            }
            else
            {
                FirstValidValue = begin;
            }
            this.Name = name;
            for (int i = begin, j = 0; j < length; i++, j++)
            {
                this[i] = output[j];
            }
        }
예제 #27
0
        protected baseDX(DataBars ds, Types type, int period, string name) : base(ds, name)
        {
            int begin = 0, length = 0;

            Core.RetCode retCode = Core.RetCode.UnknownErr;
            double[]     output  = new double[ds.Count];
            switch (type)
            {
            case Types.ADX:
                retCode = Core.Dx(0, ds.Count - 1, ds.High.Values, ds.Low.Values, ds.Close.Values, period, out begin, out length, output);
                break;

            case Types.PlusDI:
                retCode = Core.PlusDI(0, ds.Count - 1, ds.High.Values, ds.Low.Values, ds.Close.Values, period, out begin, out length, output);
                break;

            case Types.MinusDI:
                retCode = Core.MinusDI(0, ds.Count - 1, ds.High.Values, ds.Low.Values, ds.Close.Values, period, out begin, out length, output);
                break;

            case Types.MinusDM:
                retCode = Core.MinusDM(0, ds.Count - 1, ds.High.Values, ds.Low.Values, period, out begin, out length, output);
                break;

            case Types.PlusDM:
                retCode = Core.PlusDM(0, ds.Count - 1, ds.High.Values, ds.Low.Values, period, out begin, out length, output);
                break;
            }
            if (retCode != Core.RetCode.Success)
            {
                return;
            }
            //Assign first bar that contains indicator data
            FirstValidValue = begin;
            this.Name       = name;
            for (int idx = 0; idx < begin; idx++)
            {
                this[idx] = 0;
            }
            for (int i = begin, j = 0; j < length; i++, j++)
            {
                this[i] = output[j];
            }
        }
예제 #28
0
파일: Function.cs 프로젝트: mpvyard/forexai
        public double[] Execute(FunctionParameters parameters, out Core.RetCode code)
        {
            Core.SetCompatibility(Core.Compatibility.Metastock);
            //Core.SetUnstablePeriod(Core.FuncUnstId.FuncUnstAll, 255);

            var retCode = Core.RetCode.UnknownErr;

            try
            {
                retCode = (Core.RetCode)method.Invoke(null, parameters.Arguments);
            }
            catch (Exception e)
            {
                debug($"exception: {e.Message}");
            }

            resultLen = (int)parameters.Arguments[parameters.OutNbElement];
            //debug($"retCode: {retCode} resultLen: {resultLen}");
            code       = retCode;
            returnData = new double[resultLen];

            if (parameters.Arguments[parameters.OutIndex].GetType().ToString() == "System.Int32[]")
            {
                resultsInt = (int[])parameters.Arguments[parameters.OutIndex];

                for (var i = 0; i < resultLen; i++)
                {
                    results[i] = resultsInt[i];
                }
            }
            else
            {
                results = parameters.Arguments[parameters.OutIndex] as double[];
            }

            if (results != null)
            {
                Array.Copy(results, returnData, resultLen);
            }

            //DumpValues(method, returnData);

            return(returnData);
        }
예제 #29
0
        protected override List <Signal> GetSignalsBase(HistoricalData historicalData, List <Signal> dependencySignals = null)
        {
            List <Signal> signals = new List <Signal>();

            int avgPeriod = AvgPeriod;
            int count     = historicalData.Count;
            int endIdx    = count - 1;

            int outBegIdx;
            int outNbElement;

            if (count <= avgPeriod)
            {
                avgPeriod = count;
            }
            double[] outStdDev = new double[count - avgPeriod + 1];

            double[]   inReal  = GetInRealArray(historicalData);
            DateTime[] inDates = GetDateArray(historicalData);

            double[]   lastPrices = new double[count - avgPeriod + 1];
            DateTime[] dates      = new DateTime[count - avgPeriod + 1];

            Array.Copy(inReal, avgPeriod - 1, lastPrices, 0, lastPrices.Count());
            Array.Copy(inDates, avgPeriod - 1, dates, 0, dates.Count());

            double[]     result  = new double[count - avgPeriod + 1];
            Core.RetCode retCode = Core.StdDev(StartIdx, endIdx, inReal, avgPeriod, 1, out outBegIdx, out outNbElement, outStdDev);
            if (retCode != Core.RetCode.Success)
            {
                LogError(retCode);
            }
            retCode = Core.Div(StartIdx, outStdDev.Count() - 1, outStdDev, lastPrices, out outBegIdx, out outNbElement, result);
            if (retCode != Core.RetCode.Success)
            {
                LogError(retCode);
            }
            else
            {
                signals = GetSignals(historicalData.SecurityCode, result, dates, outBegIdx, outNbElement);
            }

            return(signals);
        }
예제 #30
0
        public void simpleMovingAverageCall()
        {
            //you'll probably have to do this next call every time you add a value to your data array
            //I haven't checked this in a live app yet
            resetArrayValues();

            //The "lookback" is really your indicator's period minus one because it's expressed as an array index
            //At least that's true for movingAverage(...)
            lookback = Core.MovingAverageLookback(10, Core.MAType.Sma);

            Console.WriteLine("Starting everthing off...");
            Console.WriteLine("Lookback=" + Convert.ToString(lookback));
            Console.WriteLine("outBegIdx.value=" + Convert.ToString(outBegIdx));
            Console.WriteLine("outNbElement.value=" + Convert.ToString(outNbElement));
            retCode = Core.MovingAverage(0, close.Length - 1, close, lookback + 1, Core.MAType.Sma, out outBegIdx, out outNbElement, output);

            showDefaultTALIBOutput();
            showFinalOutput();
        }
예제 #31
0
        /**
        * resets the arrays used in this application since they are only
        * initialized once
        */
        private void resetArrayValues()
        {
            //provide default "fill" values to avoid nulls.

            for (int i = 0; i < input.Length; i++)
            {
                input[i] = (double)i;
                inputInt[i] = i;
            }
            for (int i = 0; i < output.Length; i++)
            {
                output[i] = (double)-999999.0;
                outputInt[i] = -999999;
            }

            //provide some "fail" values up front to ensure completion if correct.
            outBegIdx = -1;
            outNbElement = -1;
            retCode = Core.RetCode.InternalError;
            lookback = -1;
        }
예제 #32
0
        public void simpleMovingAverageCall()
        {
            //you'll probably have to do this next call every time you add a value to your data array
            //I haven't checked this in a live app yet
            resetArrayValues();

            //The "lookback" is really your indicator's period minus one because it's expressed as an array index
            //At least that's true for movingAverage(...)
            lookback = Core.MovingAverageLookback(10, Core.MAType.Sma);

            Console.WriteLine("Starting everthing off...");
            Console.WriteLine("Lookback=" + Convert.ToString(lookback));
            Console.WriteLine("outBegIdx.value=" + Convert.ToString(outBegIdx));
            Console.WriteLine("outNbElement.value=" + Convert.ToString(outNbElement));
            retCode = Core.MovingAverage(0, close.Length - 1, close, lookback + 1, Core.MAType.Sma, out outBegIdx, out outNbElement, output);

            showDefaultTALIBOutput();
            showFinalOutput();
        }