Пример #1
0
 public static bool IsShootingStar(Candlestick previous, Candlestick current)
 {
     return(_isBullish(previous) &&
            _isBearish(current) &&
            _isGapUp(previous, current) &&
            _isInvertedHammerLike(current));
 }
Пример #2
0
 public static bool IsHangingMan(Candlestick previous, Candlestick current)
 {
     return(_isBullish(previous) &&
            _isBearish(current) &&
            _isGapUp(previous, current) &&
            _isHammerLike(current));
 }
Пример #3
0
        private static bool _isHammerLike(Candlestick candle)
        {
            return((((candle.HighPrice - candle.LowPrice) > 3 * (candle.OpenPrice - candle.ClosePrice)) &&
                    ((candle.ClosePrice - candle.LowPrice) / (.001 + candle.HighPrice - candle.LowPrice) > 0.6) &&
                    ((candle.OpenPrice - candle.LowPrice) / (.001 + candle.HighPrice - candle.LowPrice) > 0.6)) && ((_bodyLen(candle) * 100 / _tailLen(candle)) >= 25 && (_bodyLen(candle) * 100 / _tailLen(candle)) >= 50));

            //return _tailLen(candle) > _bodyLen(candle) * 2 &&
            //       _wickLen(candle) < _bodyLen(candle);
        }
Пример #4
0
        static void Main(string[] args)
        {
            string connectionString =
                "Data Source=.;Initial Catalog=Candlesticks_v01;"
                + "Integrated Security=true";

            // Provide the query string with a parameter placeholder.
            string queryString =
                "SELECT top(1000) * from cndl.Candlesticks "
                + "WHERE IntervalID=@interval "
                + "AND stockid = 294 ORDER  BY [opentime] DESC  ";

            int paramValue = 6;
            var list       = new List <Candlestick>();

            using SqlConnection connection =
                      new SqlConnection(connectionString);
            SqlCommand command = new SqlCommand(queryString, connection);

            command.Parameters.AddWithValue("@interval", paramValue);

            try
            {
                connection.Open();
                SqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    var candle = new Candlestick();
                    var ddd    = double.Parse(reader["OpenPrice"].ToString());
                    candle.Id         = long.Parse(reader["Id"].ToString() ?? string.Empty);
                    candle.OpenPrice  = double.Parse(reader["OpenPrice"].ToString() ?? string.Empty);
                    candle.ClosePrice = double.Parse(reader["ClosePrice"].ToString() ?? string.Empty);
                    candle.HighPrice  = double.Parse(reader["HighPrice"].ToString() ?? string.Empty);
                    candle.LowPrice   = double.Parse(reader["LowPrice"].ToString() ?? string.Empty);
                    if (CandleDetector.IsHammer(candle))
                    {
                        DoUpdate(candle.Id);
                    }
                }
                reader.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadLine();
        }
Пример #5
0
 private static bool _isGap(Candlestick lowest, Candlestick upmost)
 {
     return(Math.Max(lowest.OpenPrice, lowest.ClosePrice) < Math.Min(upmost.OpenPrice, upmost.ClosePrice));
 }
Пример #6
0
 private static bool _isEngulfed(Candlestick shortest, Candlestick longest)
 {
     return(_bodyLen(shortest) < _bodyLen(longest));
 }
Пример #7
0
 private static bool _isInvertedHammerLike(Candlestick candle)
 {
     return(_wickLen(candle) > (_bodyLen(candle) * 2) &&
            _tailLen(candle) < _bodyLen(candle));
 }
Пример #8
0
 private static bool _isBearish(Candlestick candle)
 {
     return(candle.OpenPrice > candle.ClosePrice);
 }
Пример #9
0
 private static double _tailLen(Candlestick candle)
 {
     return(Math.Min(candle.OpenPrice, candle.ClosePrice) - candle.LowPrice);
 }
Пример #10
0
        //List<Candlestick> findPattern(List<Candlestick> dataArray, Func<List<Candlestick>, bool> callback)
        //{
        //    var upperBound = (dataArray.Count - callback.length) + 1;
        //    var matches = new List<Candlestick>();

        //    for (var i = 0; i < upperBound; i++)
        //    {
        //        var args = new List<Candlestick>();

        //        // Read the leftmost j values at position i in array.
        //        // The j values are callback arguments.
        //        for (var j = 0; j < callback.; j++)
        //        {
        //            args.Add(dataArray[i + j]);
        //        }

        //        // Destructure args and find matches.
        //        if (callback(args))
        //        {
        //            matches.Add(args[1]);
        //        }
        //    }

        //    return matches;
        //}

        // Boolean pattern detection.
        // @public

        public static bool IsHammer(Candlestick candle)
        {
            return //_isBullish(candle) &&
                   (_isHammerLike(candle));
        }
Пример #11
0
 private static double _bodyLen(Candlestick candle)
 {
     return(Math.Abs(candle.OpenPrice - candle.ClosePrice));
 }
Пример #12
0
 public static bool IsBearishKicker(Candlestick previous, Candlestick current)
 {
     return(_isBullish(previous) &&
            _isBearish(current) &&
            _isGapDown(previous, current));
 }
Пример #13
0
 public static bool IsBearishHarami(Candlestick previous, Candlestick current)
 {
     return(_isBullish(previous) &&
            _isBearish(current) &&
            _isEngulfed(current, previous));
 }
Пример #14
0
 public static bool IsBearishEngulfing(Candlestick previous, Candlestick current)
 {
     return(_isBullish(previous) &&
            _isBearish(current) &&
            _isEngulfed(previous, current));
 }
Пример #15
0
 public static bool IsInvertedHammer(Candlestick candle)
 {
     return(_isBearish(candle) &&
            _isInvertedHammerLike(candle));
 }
Пример #16
0
 private static bool _isGapUp(Candlestick previous, Candlestick current)
 {
     return(_isGap(previous, current));
 }
Пример #17
0
 private static bool _isGapDown(Candlestick previous, Candlestick current)
 {
     return(_isGap(current, previous));
 }
Пример #18
0
 private static double _wickLen(Candlestick candle)
 {
     return(candle.HighPrice - Math.Max(candle.OpenPrice, candle.ClosePrice));
 }