Exemplo n.º 1
0
        public static Leg GetUpLeg(int numberOfBars, Leg previousLeg = null)
        {
            FxBar[] barlist = new FxBar[numberOfBars + 1];
            FxBar   upBar   = new FxBar(30, 31, 60, 61, 10, 11, 40, 41, 0, DateTime.Now, DateTime.Now);

            barlist[0] = upBar;
            Leg leg = new Leg(upBar, previousLeg);

            for (int i = 1; i < numberOfBars; i++)
            {
                barlist[i] = (new FxBar
                {
                    Open = upBar.Open + (i + 10),
                    AskOpen = upBar.AskOpen + (i + 10),
                    High = upBar.High + (i + 10),
                    AskHigh = upBar.AskHigh + (i + 10),
                    Low = upBar.Low + (i + 10),
                    AskLow = upBar.AskLow + (i + 10),
                    Close = upBar.Close + (i + 10),
                    AskClose = upBar.AskClose + (i + 10),
                    PreviousBar = barlist[i - 1]
                });

                leg.AddBar(barlist[i]);
            }

            return(leg);
        }
Exemplo n.º 2
0
        public static Leg GetDownLeg(int numberOfBars, Leg previousLeg = null)
        {
            FxBar[] barlist = new FxBar[numberOfBars + 1];
            FxBar   downBar = new FxBar(60, 61, 120, 121, 40, 41, 50, 51, 0, DateTime.Now, DateTime.Now);

            barlist[0] = downBar;
            Leg leg = new Leg(downBar, previousLeg);

            for (int i = 1; i < numberOfBars; i++)
            {
                barlist[i] = (new FxBar
                {
                    Open = downBar.Open - (i + 10),
                    AskOpen = downBar.AskOpen - (i + 10),
                    High = downBar.High - (i + 10),
                    AskHigh = downBar.AskHigh - (i + 10),
                    Low = downBar.Low - (i + 10),
                    AskLow = downBar.AskLow - (i + 10),
                    Close = downBar.Close - (i + 10),
                    AskClose = downBar.AskClose - (i + 10),
                    PreviousBar = barlist[i - 1]
                });

                leg.AddBar(barlist[i]);
            }

            return(leg);
        }
Exemplo n.º 3
0
        public void UpdateLastBar__Turn_LastBar_To_DownBar_And_Create_New_DownLeg()
        {
            LegAnalyzer la = new LegAnalyzer();

            List <Bar> barList = new List <Bar>();

            barList.Add(Helper.GetUpBar());
            barList.Add(Helper.GetUpBar(barList.Last(), barList.Last().DateTime.AddDays(1)));
            barList.Add(Helper.GetUpBar(barList.Last(), barList.Last().DateTime.AddDays(1)));

            la.AddBarList(barList);

            FxBar b  = (FxBar)la.LastLeg.BarList[1];
            FxBar nb = new FxBar
            {
                Open     = b.Open,
                AskOpen  = b.AskOpen,
                High     = b.High - 5,
                AskHigh  = b.AskHigh - 5,
                Low      = b.Low - 5,
                AskLow   = b.AskLow - 5,
                Close    = b.Open - 3,
                AskClose = b.AskOpen - 3,
                DateTime = b.DateTime,
                Volume   = 100
            };

            la.UpdateLastBar(nb);

            Assert.AreEqual(2, la.LegsCount);
            Assert.AreEqual(LegDirection.Down, la.LastLeg.Direction);
        }
Exemplo n.º 4
0
        public void FxBar_Update()
        {
            FxBar upBar = new FxBar(50, 51, 100, 101, 20, 21, 60, 61, 0, DateTime.Now, DateTime.Now);

            upBar.Update(new FxBar(10, 10, 10, 10, 10, 10, 10, 10, 0, DateTime.Now, DateTime.Now));

            Assert.AreEqual(10, upBar.AskHigh);
            Assert.AreEqual(10, upBar.AskLow);
        }
Exemplo n.º 5
0
        private static IEnumerable <Bar> normalizeToQuarterlyTimeFrame(List <FxBar> barList)
        {
            List <FxBar> quarterlyBarList = new List <FxBar>();

            var index = 0;

            List <FxBar> tempList;

            while (index < barList.Count)
            {
                int count = 3 - ((barList[index].DateTime.Month - 1) % 3);

                tempList = barList.GetRange(index, count);

                index = index + count;

                var open    = tempList.First().Open;
                var askOpen = tempList.First().AskOpen;

                var close    = tempList.Last().Close;
                var askClose = tempList.Last().AskClose;

                var high    = tempList.Max(p => p.High);
                var askHigh = tempList.Max(p => p.AskHigh);

                var low    = tempList.Min(p => p.Low);
                var askLow = tempList.Min((p) => p.AskLow);

                var volume = tempList.Sum(p => p.Volume);

                var dateTime = tempList.Last().DateTime;

                FxBar bar = new FxBar()
                {
                    Open     = open,
                    AskOpen  = askOpen,
                    High     = high,
                    AskHigh  = askHigh,
                    Low      = low,
                    AskLow   = askLow,
                    Close    = close,
                    AskClose = askClose,
                    Volume   = volume,
                    DateTime = dateTime
                };

                quarterlyBarList.Add(bar);
            }
            return(quarterlyBarList);
        }
Exemplo n.º 6
0
        public void UpdateLastBar__Update_Close()
        {
            LegAnalyzer la = new LegAnalyzer();

            la.AddBar(Helper.GetUpBar());
            la.AddBar(Helper.GetUpBar(la.LastBar, la.LastBar.DateTime.AddDays(1)));

            FxBar b = (FxBar)la.LastBar;

            FxBar nb = new FxBar
            {
                Open = b.Open, AskOpen = b.AskOpen, High = b.High + 5, AskHigh = b.AskHigh + 5, Low = b.Low, AskLow = b.AskLow, Close = b.Close + 3, AskClose = b.AskClose + 3, DateTime = b.DateTime, Volume = 100
            };

            la.UpdateLastBar(nb);

            Assert.AreEqual(BarDirection.Up, la.LastBar.Direction);
            Assert.AreEqual(115, la.LastBar.High);
            Assert.AreEqual(116, ((FxBar)la.LastBar).AskHigh);
            Assert.AreEqual(73, la.LastBar.Close);
            Assert.AreEqual(74, ((FxBar)la.LastBar).AskClose);
            Assert.AreEqual(200, la.LastBar.Volume);
        }
Exemplo n.º 7
0
        public IEnumerable <Bar> ReadLocalDataAsync(Instrument instrument, Resolution resolution, DateTime fromDate, DateTime toDate)
        {
            List <Bar> barList = new List <Bar>();

            if (!File.Exists(getFullPath(instrument, resolution)))
            {
                return(barList);
            }

            using (StreamReader sr = new StreamReader(getFullPath(instrument, resolution)))
            {
                string line;
                if (instrument.Type == InstrumentType.Forex)
                {
                    while ((line = sr.ReadLine()) != null)
                    {
                        string[] str = line.Split(new char[] { ',' });
                        FxBar    b   = new FxBar(Convert.ToDouble(str[0]), Convert.ToDouble(str[1]), Convert.ToDouble(str[2]), Convert.ToDouble(str[3]), Convert.ToDouble(str[4]), Convert.ToDouble(str[5]), Convert.ToDouble(str[6]), Convert.ToDouble(str[7]), Convert.ToDouble(str[8]), Convert.ToDateTime(str[9]), Convert.ToDateTime(str[10]));

                        barList.Add(b);
                    }
                }
                else
                {
                    while ((line = sr.ReadLine()) != null)
                    {
                        string[] str = line.Split(new char[] { ',' });
                        Bar      b   = new Bar(Convert.ToDouble(str[0]), Convert.ToDouble(str[1]), Convert.ToDouble(str[2]), Convert.ToDouble(str[3]), Convert.ToDouble(str[4]), Convert.ToDateTime(str[5]), Convert.ToDateTime(str[6]));

                        barList.Add(b);
                    }
                }
            }

            return(barList);
        }