Beispiel #1
0
                public static MyTrade.Core.Model.Candle WeeklyBar(List <MyTrade.Core.Model.Candle> candles)
                {
                    MyTrade.Core.Model.Candle candle = new Model.Candle();

                    double mHigh  = 0;
                    double mOPen  = 0;
                    double mClose = 0;
                    double mLow   = 0;
                    int    i      = 0;

                    foreach (var item in candles.OrderBy(x => x.Time))
                    {
                        if (i == 0)
                        {
                            mClose = item.Close;
                            mLow   = item.Low;
                        }

                        mHigh  = Math.Max(item.High, mHigh);
                        mOPen  = Math.Max(item.Open, mOPen);
                        mClose = Math.Min(item.Close, mClose);
                        mLow   = Math.Min(item.Low, mLow);

                        i += 1;
                    }

                    candle.Open  = mOPen;
                    candle.High  = mHigh;
                    candle.Low   = mLow;
                    candle.Close = mClose;
                    return(candle);
                }
Beispiel #2
0
        private void btnStocksWeeklyCandles_Click(object sender, EventArgs e)
        {
            MyTrade.Core.SqliteDataAccess.WeekyStocksCandles.CleanData();
            List <Instrument> instruments = MyTrade.Alpaca.Data.Instrument.AllFromDB().Where(x => x.IsFavorite == true).ToList();
            DateTime          start       = new DateTime();
            DateTime          end         = new DateTime();

            MyTrade.Core.Utilities.Calculate.Date.StartEndOfWeekBefore(DateTime.Now, out start, out end);
            foreach (Instrument item in instruments)
            {
                List <MyTrade.Core.Model.Candle> candles   = MyTrade.Alpaca.Data.Prices.GetCandles(item.Name, start, end, "1D");
                List <MyTrade.Core.Model.Candle> _candles  = new List <Candle>();
                MyTrade.Core.Model.Candle        weeklyBar = MyTrade.Core.Utilities.Calculate.Bars.WeeklyBar(candles);
                weeklyBar.Instrument = item.Name;
                _candles.Add(weeklyBar);
                MyTrade.Core.SqliteDataAccess.WeekyStocksCandles.SaveCandles(_candles);
            }
        }