public static bool IsShootingStar(Candlestick previous, Candlestick current) { return(_isBullish(previous) && _isBearish(current) && _isGapUp(previous, current) && _isInvertedHammerLike(current)); }
public static bool IsHangingMan(Candlestick previous, Candlestick current) { return(_isBullish(previous) && _isBearish(current) && _isGapUp(previous, current) && _isHammerLike(current)); }
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); }
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(); }
private static bool _isGap(Candlestick lowest, Candlestick upmost) { return(Math.Max(lowest.OpenPrice, lowest.ClosePrice) < Math.Min(upmost.OpenPrice, upmost.ClosePrice)); }
private static bool _isEngulfed(Candlestick shortest, Candlestick longest) { return(_bodyLen(shortest) < _bodyLen(longest)); }
private static bool _isInvertedHammerLike(Candlestick candle) { return(_wickLen(candle) > (_bodyLen(candle) * 2) && _tailLen(candle) < _bodyLen(candle)); }
private static bool _isBearish(Candlestick candle) { return(candle.OpenPrice > candle.ClosePrice); }
private static double _tailLen(Candlestick candle) { return(Math.Min(candle.OpenPrice, candle.ClosePrice) - candle.LowPrice); }
//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)); }
private static double _bodyLen(Candlestick candle) { return(Math.Abs(candle.OpenPrice - candle.ClosePrice)); }
public static bool IsBearishKicker(Candlestick previous, Candlestick current) { return(_isBullish(previous) && _isBearish(current) && _isGapDown(previous, current)); }
public static bool IsBearishHarami(Candlestick previous, Candlestick current) { return(_isBullish(previous) && _isBearish(current) && _isEngulfed(current, previous)); }
public static bool IsBearishEngulfing(Candlestick previous, Candlestick current) { return(_isBullish(previous) && _isBearish(current) && _isEngulfed(previous, current)); }
public static bool IsInvertedHammer(Candlestick candle) { return(_isBearish(candle) && _isInvertedHammerLike(candle)); }
private static bool _isGapUp(Candlestick previous, Candlestick current) { return(_isGap(previous, current)); }
private static bool _isGapDown(Candlestick previous, Candlestick current) { return(_isGap(current, previous)); }
private static double _wickLen(Candlestick candle) { return(candle.HighPrice - Math.Max(candle.OpenPrice, candle.ClosePrice)); }