Ejemplo n.º 1
0
        IsolateNumericLiteral(
            ScanStream ScanStream,
            TextTraits Traits,
            int Bx)
        {
            // for now, all numeric literals are simple integers.
            // have to expand to determine if a float, decimal, what the sign is,
            // what the precision is.
            LiteralType litType = LiteralType.Integer;

            string             litText = null;
            PatternScanResults nonWord = null;

            // step from char to char. Look for a char that is not part of the
            // numeric literal.
            int ix    = Bx;
            int litEx = Bx;

            while (true)
            {
                if (ix >= ScanStream.Stream.Length)
                {
                    break;
                }
                char ch1 = ScanStream.Stream[ix];
                if (Char.IsDigit(ch1) == false)
                {
                    break;
                }

                litEx = ix;
                ix   += 1;
            }

            // isolate the numeric literal.
            int lx = litEx - Bx + 1;

            litText = ScanStream.Substring(Bx, lx);

            // isolate the delim that follows that numeric literal.
            int bx = litEx + 1;

            if (bx < ScanStream.Stream.Length)
            {
                nonWord = Scanner.ScanEqualAny(ScanStream.Stream, bx, Traits.DelimPatterns);
//        foundPat = rv.Item1;
//        foundIx = rv.Item2;
//        foundLx = rv.Item3;
//        nonWord = rv.Item3;
            }

            return(new Tuple <LiteralType, string, PatternScanResults>(
                       litType, litText, nonWord));
        }
        private async Task <List <PatternScanResults> > GetPatternScanResultsAsync(List <CandleStick> candleSticks, CandleStickPattern patternToScanFor)
        {
            List <PatternScanResults> patternScanResults = new List <PatternScanResults>();

            int[] patternIndexLoc = new int[candleSticks.Count()];
            int   out1            = 0;
            int   out2            = 0;

            object[] parameters = new object[] { 1, candleSticks.Count() - 1, candleSticks.Select(x => (float)x.Open).ToArray(),
                                                 candleSticks.Select(x => (float)x.High).ToArray(), candleSticks.Select(x => (float)x.Low).ToArray(), candleSticks.Select(x => (float)x.Close).ToArray(), 0, out1, out2, patternIndexLoc };

            Type thisType = typeof(TicTacTec.TA.Library.Core);

            try
            {
                MethodInfo theMethod = thisType.GetMethod("CdlMorningStar");
                var        result    = theMethod.Invoke(this, parameters);
            }
            catch (AmbiguousMatchException)
            {
                MethodInfo[] methods = thisType.GetMethods();

                var result = methods[0].Invoke(this, parameters);

                if ((RetCode)result == RetCode.Success)
                {
                    out1 = (int)parameters[7];
                    out2 = (int)parameters[8];
                }
            }

            //Create PatternScanResults
            int iterator = 0;

            foreach (var candle in candleSticks)
            {
                var isPatternTriggered = patternIndexLoc[iterator] != 0 ? true : false;
                var patternScanResult  = PatternScanResults.Create(candle, isPatternTriggered);

                if (isPatternTriggered)
                {
                    patternScanResults.Add(patternScanResult);
                }

                iterator++;
            }

            return(patternScanResults);
        }