Exemple #1
0
 public static string IsCall(StockValue a, EMAValues b) // DateTime date, decimal open, decimal high, decimal low, decimal close, decimal volume, decimal body, decimal size, decimal ema)
 {
     if ((a.Date.Hour + a.Date.Minute) != 24 && Math.Abs(a.Body) > (a.Low * BodySize))
     {
         if ((a.Open < a.Close) && (b.EMA > a.Open) && (b.EMA < a.Close)) // && (c.EMA > a.Open) && (c.EMA < a.Close))
         {
             return("BUY");
         }
         if ((a.Open >= a.Close) && (b.EMA > a.Close) && (b.EMA < a.Open)) // && (c.EMA > a.Close) && (c.EMA < a.Open))
         {
             return("SELL");
         }
     }
     return(string.Empty);
 }
Exemple #2
0
        public static StockValue FromCsv(string csvLine)
        {
            string[]   values      = csvLine.Split(',');
            StockValue dailyValues = new StockValue();

            dailyValues.Date   = Convert.ToDateTime(values[0]).AddMinutes(570);
            dailyValues.Open   = Convert.ToDecimal(values[1]);
            dailyValues.High   = Convert.ToDecimal(values[2]);
            dailyValues.Low    = Convert.ToDecimal(values[3]);
            dailyValues.Close  = Convert.ToDecimal(values[4]);
            dailyValues.Volume = Convert.ToDecimal(values[5]);
            dailyValues.Body   = dailyValues.Close - dailyValues.Open;
            dailyValues.Size   = dailyValues.High - dailyValues.Low;
            return(dailyValues);
        }
Exemple #3
0
        public List <StockCall> GetStockPrice(Script script)
        {
            string            CSV_Price  = Master.GetData(URL_StockPrice.Replace(APIKEY, script.key).Replace(SYMBOL, script.Code).Replace(INTERVAL, "15min"), script);
            string            CSV_EMA_21 = Master.GetData(URL_EMA.Replace(APIKEY, script.key).Replace(SYMBOL, script.Code).Replace(INTERVAL, "15min").Replace(TIME_PERIOD, "21"), script);
            List <StockValue> Price      = CSV_Price
                                           .Replace('\n', '\r')
                                           .Split(new char[] { '\r' }, StringSplitOptions.RemoveEmptyEntries)
                                           .Skip(1)
                                           .Select(v => StockValue.FromCsv(v))
                                           .ToList();

            List <EMAValues> EMA_21 = CSV_EMA_21
                                      .Replace('\n', '\r')
                                      .Split(new char[] { '\r' }, StringSplitOptions.RemoveEmptyEntries)
                                      .Skip(1)
                                      .Select(v => EMAValues.FromCsv(v))
                                      .ToList();

            string       easternZoneId = "Eastern Standard Time";
            TimeZoneInfo easternZone   = TimeZoneInfo.FindSystemTimeZoneById(easternZoneId);
            var          t             = from a in Price
                                         join b in EMA_21 on a.Date equals b.Date
                                         //join c in EMA_9 on a.Date equals c.Date
                                         //join d in VWAP on a.Date equals d.Date
                                         select new StockCall
            {
                Stock  = script.Code,
                Date   = a.Date,
                Open   = a.Open,
                High   = a.High,
                Low    = a.Low,
                Close  = a.Close,
                Volume = a.Volume,
                Body   = a.Body,
                Size   = a.Size,
                //EMA9 = c.EMA,
                EMA21 = b.EMA,
                //VWAP= d.VWAP,
                LotSize = script.LotSize,
                Call    = Master.IsCall(a, b)
            };


            StringBuilder s = new StringBuilder();

            s.Append("Date,Open,High,Low,Close,Volume,Body,Size,EMA9,EMA21,VWAP,Call,LotSize");
            foreach (var item in t)
            {
                s.Append(Environment.NewLine + item.Date.ToString() + "," + item.Open.ToString("0.00") + "," + item.High.ToString("0.00") + "," + item.Low.ToString("0.00") + "," + item.Close.ToString("0.00") + "," + item.Volume.ToString("0.00") + "," + item.Body.ToString("0.00") + "," + item.Size.ToString("0.00") + "," + item.EMA9.ToString("0.00") + "," + item.EMA21.ToString("0.00") + "," + item.VWAP.ToString("0.00") + "," + item.Call + "," + item.LotSize.ToString("0"));
            }
            System.IO.File.WriteAllText(Path.Combine(_path, script.Code + "_" + script.ProxyDurty.ToString() + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".csv"), s.ToString());
            var call = t.First();

            if (call != null)
            {
                if (!string.IsNullOrEmpty(call.Call) && call.Date.Day == DateTime.Today.Day && call.Date.Month == DateTime.Today.Month)
                {
                    call.AvgVolume = t.Average(a => a.Volume);
                    Master.Sendmail(call);
                    if (!File.Exists(Path.Combine(_path, "Tread_" + DateTime.Now.ToString("yyyyMMdd") + ".txt")))
                    {
                        System.IO.File.AppendAllText(Path.Combine(_path, "Tread_" + DateTime.Now.ToString("yyyyMMdd") + ".txt"), "Stock,Call,Date,Open,High,Low,Close,EMA21,Volume,Size,LotSize");
                    }
                    System.IO.File.AppendAllText(Path.Combine(_path, "Tread_" + DateTime.Now.ToString("yyyyMMdd") + ".txt"), Environment.NewLine + call.Print());
                }
            }
            return(t.ToList());
        }