コード例 #1
0
ファイル: Program.cs プロジェクト: vcoda/fastquant.dll
        protected override void OnBar(Instrument instrument, Bar bar)
        {
            // Add bar to bar series.
            Bars.Add(bar);

            Log(bar, barsGroup);

            if (fastSMA.Count > 0)
            {
                Log(fastSMA.Last, fastSmaGroup);
            }

            if (slowSMA.Count > 0)
            {
                Log(slowSMA.Last, slowSmaGroup);
            }

            // Calculate performance.
            Portfolio.Performance.Update();

            Log(Portfolio.Value, equityGroup);

            if (!SuspendTrading)
            {
                // Check strategy logic.
                if (fastSMA.Count > 0 && slowSMA.Count > 0)
                {
                    Cross cross = fastSMA.Crosses(slowSMA, bar.DateTime);

                    if (!HasPosition(instrument))
                    {
                        // Enter long/short.
                        if (cross == Cross.Above)
                        {
                            Order enterOrder = BuyOrder(Instrument, Qty, "Enter Long");
                            Send(enterOrder);
                        }
                        else if (cross == Cross.Below)
                        {
                            Order enterOrder = SellOrder(Instrument, Qty, "Enter Short");
                            Send(enterOrder);
                        }
                    }
                    else
                    {
                        // Reverse to long/short.
                        if (Position.Side == PositionSide.Long && cross == Cross.Below)
                        {
                            Order reverseOrder = SellOrder(Instrument, Math.Abs(Position.Amount) + Qty, "Reverse to Short");
                            Send(reverseOrder);
                        }
                        else if (Position.Side == PositionSide.Short && cross == Cross.Above)
                        {
                            Order reverseOrder = BuyOrder(Instrument, Math.Abs(Position.Amount) + Qty, "Reverse to Long");
                            Send(reverseOrder);
                        }
                    }
                }
            }
        }
コード例 #2
0
        void InitializeAdditionBar()
        {
            BarViewModel addingBar = ViewModelSource.Create(() => new BarViewModel()
            {
                Name = "Addition"
            });

            Bars.Add(addingBar);
            var addGroupCommand = ViewModelSource.Create(() => new GroupBarButtonInfo()
            {
                Caption = "Add", LargeGlyph = DXImageHelper.GetDXImage("Add_32x32.png"), SmallGlyph = DXImageHelper.GetDXImage("Add_16x16.png")
            });
            var parentCommand = ViewModelSource.Create(() => new ParentBarButtonInfo(this, MyParentCommandType.CommandCreation)
            {
                Caption = "Add Command", LargeGlyph = DXImageHelper.GetDXImage("Add_32x32.png"), SmallGlyph = DXImageHelper.GetDXImage("Add_16x16.png")
            });
            var parentBar = ViewModelSource.Create(() => new ParentBarButtonInfo(this, MyParentCommandType.BarCreation)
            {
                Caption = "Add Bar", LargeGlyph = DXImageHelper.GetDXImage("Add_32x32.png"), SmallGlyph = DXImageHelper.GetDXImage("Add_16x16.png")
            });

            addGroupCommand.Commands.Add(parentCommand);
            addGroupCommand.Commands.Add(parentBar);
            addingBar.Commands.Add(addGroupCommand);
            addingBar.Commands.Add(parentCommand);
            addingBar.Commands.Add(parentBar);
        }
コード例 #3
0
        /// <summary>
        /// See <see cref="UIElementAdapter{TUIElement}.Add(TUIElement)"/> for more information.
        /// </summary>
        protected override Bar Add(Bar uiElement)
        {
            Guard.ArgumentNotNull(uiElement, "Bar");

            bars.Add(uiElement);
            return(uiElement);
        }
コード例 #4
0
 public void AddBar(double value, string tooltip, string cssClass)
 {
     Bars.Add(new Bar()
     {
         Value = value, Tooltip = tooltip, CssClass = cssClass
     });
 }
コード例 #5
0
        void InitializeClipboardBar()
        {
            BarViewModel clipboardBar = ViewModelSource.Create(() => new BarViewModel()
            {
                Name = "Clipboard"
            });

            Bars.Add(clipboardBar);
            var cutCommand = ViewModelSource.Create(() => new BarButtonInfo(cutCommandExecuteFunc)
            {
                Caption = "Cut", LargeGlyph = DXImageHelper.GetDXImage("Cut_32x32.png"), SmallGlyph = DXImageHelper.GetDXImage("Cut_16x16.png")
            });
            var copyCommand = ViewModelSource.Create(() => new BarButtonInfo(copyCommandExecuteFunc)
            {
                Caption = "Copy", LargeGlyph = DXImageHelper.GetDXImage("Copy_32x32.png"), SmallGlyph = DXImageHelper.GetDXImage("Copy_16x16.png")
            });
            var pasteCommand = ViewModelSource.Create(() => new BarButtonInfo(pasteCommandExecuteFunc)
            {
                Caption = "Paste", LargeGlyph = DXImageHelper.GetDXImage("Paste_32x32.png"), SmallGlyph = DXImageHelper.GetDXImage("Paste_16x16.png")
            });
            var selectCommand = ViewModelSource.Create(() => new BarButtonInfo(selectAllCommandExecuteFunc)
            {
                Caption = "Select All", LargeGlyph = DXImageHelper.GetDXImage("SelectAll_32x32.png"), SmallGlyph = DXImageHelper.GetDXImage("SelectAll_16x16.png")
            });
            var blankCommand = ViewModelSource.Create(() => new BarButtonInfo(blankCommandExecuteFunc)
            {
                Caption = "Clear Page", LargeGlyph = DXImageHelper.GetDXImage("New_32x32.png"), SmallGlyph = DXImageHelper.GetDXImage("New_16x16.png")
            });

            clipboardBar.Commands.Add(cutCommand);
            clipboardBar.Commands.Add(copyCommand);
            clipboardBar.Commands.Add(pasteCommand);
            clipboardBar.Commands.Add(selectCommand);
            clipboardBar.Commands.Add(blankCommand);
        }
コード例 #6
0
        private ToolBarVm AddChild(string key)
        {
            var barVm = new ToolBarVm(HostVm, this, Key);

            Bars.Add(barVm);
            return(barVm);
        }
コード例 #7
0
        public static Bars PathLoad(string path)
        {
            string name = path.Substring(path.Length - 9, 5).Replace(@"\", "");

            Bars bars = new Bars(name, BarScale.Daily, 0);

            StreamReader sr = new StreamReader(path);

            while (sr.Peek() >= 0)
            {
                string   next_line = sr.ReadLine();
                string[] temp_ar   = next_line.Split('	');
                string   date      = temp_ar[0].Trim();
                string   open      = temp_ar[1].Trim();
                string   high      = temp_ar[2].Trim();
                string   low       = temp_ar[3].Trim();
                string   close     = temp_ar[4].Trim();
                string   volume    = temp_ar[5].Trim();

                if ((Convert.ToDouble(open) > 0) & (Convert.ToDouble(high) > 0) & (Convert.ToDouble(low) > 0) & (Convert.ToDouble(close) > 0))
                {
                    bars.Add(Convert.ToDateTime(date), Convert.ToDouble(open), Convert.ToDouble(high), Convert.ToDouble(low), Convert.ToDouble(close), Convert.ToDouble(volume));
                }
            }

            sr.Close();

            return(bars);
        }
コード例 #8
0
        public SmoothedParabolic(Bars bars, int period, string description)
            : base(bars, description)
        {
            base.FirstValidValue = period * 3;
            EMACalculation em = EMACalculation.Modern;

            DataSeries o = EMA.Series(bars.Open, period, em);
            DataSeries h = EMA.Series(bars.High, period, em);
            DataSeries l = EMA.Series(bars.Low, period, em);
            DataSeries c = EMA.Series(bars.Close, period, em);

            Bars newBars = new Bars(bars);

            for (int bar = 0; bar < bars.Count; bar++)
            {
                newBars.Add(Date[bar], o[bar], h[bar], l[bar], c[bar], bars.Volume[bar]);
            }

            DataSeries SmoothedPar = Parabolic2.Series(newBars, 0.02, 0.02, 0.2);

            for (int bar = base.FirstValidValue; bar < bars.Count; bar++)
            {
                base[bar] = SmoothedPar[bar];
            }
        }
コード例 #9
0
ファイル: Score.cs プロジェクト: statementreply/DereTore
        public Bar InsertBar(int indexBefore, BarParams barParams)
        {
            var bar = new Bar(this, indexBefore)
            {
                Params = barParams
            };

            if (indexBefore == Bars.Count)
            {
                Bars.Add(bar);
                bar.UpdateTimings();
            }
            else
            {
                Bars.Insert(indexBefore, bar);
                bar.UpdateTimings();

                foreach (var b in Bars.Skip(indexBefore + 1))
                {
                    ++b.Index;
                    b.UpdateTimings();
                }
            }
            return(bar);
        }
コード例 #10
0
 private void AddStopCode()
 {
     foreach (var bar in BarViewModel.CreateRange(new[] { 1, 1, 0, 1 }, new[] { 1d, 1d, 1d, 1d }, DefaultBarHeight))
     {
         Bars.Add(bar);
     }
 }
コード例 #11
0
 private void LoadBarsFromDatabase()
 {
     // Psuedocode to load all Bars.
     foreach (var barData in barIdsLinkedToFooTable.Rows)
     {
         Bars.Add(new Bar(this, barData["barId"]));
     }
 }
コード例 #12
0
        void NewBar()
        {
            var oldBar = current;

            current = new StockBarData(oldBar.Close, Period);
            Bars.Add(current);
            OnUpdate(current);
        }
コード例 #13
0
 public void AddBar(BarTickLookup bar)
 {
     Bars.Add(bar);
     if (!BarLookup.ContainsKey(bar.Bar.Index))
     {
         BarLookup[bar.Bar.Index] = bar;
     }
 }
コード例 #14
0
        public Bar AddBar()
        {
            var bar = new Bar(this);

            Bars.Add(bar);
            BarAdded?.Invoke(this, bar);
            return(bar);
        }
コード例 #15
0
        void AddBarsAndMakeVisible(int[] percentages)
        {
            for (int i = 0; i < percentages.Length; i++)
            {
                Bars.Add(new BarViewModel(_barColors[i], percentages[i]));
            }

            Visible = true;
        }
コード例 #16
0
        /// <summary>
        /// Sets up the bars object.  Must be called with every new set of data.
        /// </summary>
        /// <param name="buckets">buckets BCCharts</param>
        protected void BucketsToBars(List <TradeBucket> buckets)
        {
            _data    = new Bars("SADF", BarScale.Minute, 60);
            _buckets = buckets;

            foreach (TradeBucket bucket in buckets)
            {
                _data.Add(TimeUtil.FromUnixTime((long)bucket.Time), (double)bucket.Open, (double)bucket.High, (double)bucket.Low, (double)bucket.Close, (double)bucket.Volume);
            }
        }
コード例 #17
0
ファイル: Backtest.cs プロジェクト: vcoda/fastquant.dll
        protected override void OnBar(Instrument instrument, Bar bar)
        {
            // Add bar to bar series.
            Bars.Add(bar);

            // Add bar to group.
            Log(bar, barsGroup);

            // Add upper bollinger band value to group.
            if (bbu.Count > 0)
            {
                Log(bbu.Last, bbuGroup);
            }

            // Add lower bollinger band value to group.
            if (bbl.Count > 0)
            {
                Log(bbl.Last, bblGroup);
            }

            // Add simple moving average value bands to group.
            if (sma.Count > 0)
            {
                Log(sma.Last, smaGroup);
            }

            // Calculate performance.
            Portfolio.Performance.Update();

            // Add equity to group.
            Log(Portfolio.Value, equityGroup);

            // Check strategy logic.
            if (!HasPosition(instrument))
            {
                if (bbu.Count > 0 && bar.Close >= bbu.Last)
                {
                    Order enterOrder = SellOrder(Instrument, Qty, "Enter");
                    Send(enterOrder);
                }
                else if (bbl.Count > 0 && bar.Close <= bbl.Last)
                {
                    Order enterOrder = BuyOrder(Instrument, Qty, "Enter");
                    Send(enterOrder);
                }
            }
            else
            {
                UpdateExitLimit();
            }
        }
コード例 #18
0
        protected override void OnBar(Instrument instrument, Bar bar)
        {
            // Add bar to bar series.
            Bars.Add(bar);

            // Add bar to group.
            Log(bar, barsGroup);

            // Calculate performance.
            Portfolio.Performance.Update();

            // Add equity to group.
            Log(Portfolio.Value, equityGroup);

            // Check strategy logic.
            if (Bars.Count > 2)
            {
                if (!HasPosition(Instrument))
                {
                    if (Bars[Bars.Count - 1].Close > Bars[Bars.Count - 2].Close &&
                        Bars[Bars.Count - 2].Close > Bars[Bars.Count - 3].Close)
                    {
                        Order enterOrder = BuyOrder(Instrument, Qty, "Enter Long");
                        Send(enterOrder);
                    }
                    else if (Bars[Bars.Count - 1].Close < Bars[Bars.Count - 2].Close &&
                             Bars[Bars.Count - 2].Close < Bars[Bars.Count - 3].Close)
                    {
                        Order enterOrder = SellOrder(Instrument, Qty, "Enter Short");
                        Send(enterOrder);
                    }
                }
                else
                {
                    if (Position.Side == PositionSide.Short &&
                        Bars[Bars.Count - 1].Close > Bars[Bars.Count - 2].Close &&
                        Bars[Bars.Count - 2].Close > Bars[Bars.Count - 3].Close)
                    {
                        Order reverseOrder = BuyOrder(Instrument, Math.Abs(Position.Amount) + Qty, "Reverse to Long");
                        Send(reverseOrder);
                    }
                    else if (Position.Side == PositionSide.Long &&
                             Bars[Bars.Count - 1].Close < Bars[Bars.Count - 2].Close &&
                             Bars[Bars.Count - 2].Close < Bars[Bars.Count - 3].Close)
                    {
                        Order reverseOrder = SellOrder(Instrument, Math.Abs(Position.Amount) + Qty, "Reverse to Short");
                        Send(reverseOrder);
                    }
                }
            }
        }
コード例 #19
0
 private void UpdateBars()
 {
     Transactions.Clear();
     Bars.Clear();
     for (int month = 1; month < 13; month++)
     {
         Core.Instance.GetSpendings(SelectedYear, month).ForEach((s) =>
         {
             if (s.Category == SelectedCategory.category)
             {
                 Bars.Add(new BudgetBar(s));
             }
         });
     }
 }
コード例 #20
0
        public void AddEntry(int x, int z, MutableObject mutable)
        {
            var barGo = new GameObject("Iso sub-bound");

            var barBound = barGo.AddComponent <BoundingBox>();

            barGo.transform.SetParent(BarRoot);
            barGo.transform.localRotation = Quaternion.identity;
            barGo.transform.localPosition = new Vector3(x, 0, z);
            barGo.transform.localScale    = Vector3.one;

            VisualPayload newPayload = new VisualPayload(mutable,
                                                         new VisualDescription(barBound));

            Bars.Add(newPayload);
        }
コード例 #21
0
        protected override void OnBar(Instrument instrument, Bar bar)
        {
            Bars.Add(bar);

            Log(bar, barsGroup);

            if (pc.Count == 0)
            {
                return;
            }

            Log(pc.Last, pcGroup);
            Log(PriceChannel.Value(Bars, Bars.Count - 1, length, calcType, useLast, barData), pcValueGroup);

            Console.WriteLine("{0}, {1}", pc.LastDateTime, pc.Last);
        }
コード例 #22
0
ファイル: BIAS_Strategy.cs プロジェクト: zjtan1992/Demo
        protected override void OnBar(Instrument instrument, Bar bar)
        {
            Bars.Add(bar);

            Log(bar, barsGroup);


            if (bias.Count == 0)
            {
                return;
            }

            Log(bias.Last, biasGroup);
            Log(BIAS.Value(Bars, Bars.Count - 1, 10, BarData.Close), bias2Group);

            Console.WriteLine("{0}, {1}", bias.LastDateTime, bias.Last);
        }
コード例 #23
0
        private Bars GetHistory(BarDataScale dataScale, string symbol, string suffix)
        {
            string securityName;

            List <Candle> candles;

            lock (_getHistoryLocker)
                candles = _staticProvider.GetStaticData(dataScale, symbol, suffix, out securityName);

            Bars bars = new Bars(symbol, dataScale.Scale, dataScale.BarInterval);

            foreach (Candle candle in candles)
            {
                bars.Add(candle.Date, candle.Open, candle.High, candle.Low, candle.Close, candle.Volume);
            }

            return(bars);
        }
コード例 #24
0
ファイル: Program.cs プロジェクト: vcoda/fastquant.dll
        protected override void OnBar(Instrument instrument, Bar bar)
        {
            // Add bar to bar series.
            Bars.Add(bar);

            Log(bar, barsGroup);

            if (fastSMA.Count > 0)
            {
                Log(fastSMA.Last, fastSmaGroup);
            }

            if (slowSMA.Count > 0)
            {
                Log(slowSMA.Last, slowSmaGroup);
            }

            // Calculate performance.
            Portfolio.Performance.Update();

            // Add equity to group.
            Log(Portfolio.Value, equityGroup);

            // Check strategy logic.
            if (fastSMA.Count > 0 && slowSMA.Count > 0)
            {
                Cross cross = fastSMA.Crosses(slowSMA, bar.DateTime);

                // Enter long/short.
                if (!HasPosition(instrument))
                {
                    if (cross == Cross.Above)
                    {
                        enterOrder = BuyOrder(Instrument, Qty, "Enter Long");
                        Send(enterOrder);
                    }
                    else if (cross == Cross.Below)
                    {
                        enterOrder = SellOrder(Instrument, Qty, "Enter Short");
                        Send(enterOrder);
                    }
                }
            }
        }
コード例 #25
0
        /// <summary>
        /// Computes the next value of this indicator from the given state
        /// </summary>
        /// <param name="input">The input given to the indicator</param>
        /// <returns>A new value for this indicator</returns>
        protected override decimal ComputeNextValue(TradeBar input)
        {
            // Save the bar for summing
            Bars.Add(input);

            // check if it is not ready add a 0 to the RviWindow
            if (!Bars.IsReady)
            {
                RviWindow.Add(new IndicatorDataPoint(input.EndTime, 0.0m));
            }
            else
            {
                // Bars have been added, so Bars[0] is the current value of the input


                // Filter the Close - Open with a four-bar symetical FIR filter before the terms are summed.
                var v1 = ((Bars[0].Close - Bars[0].Open) + 2 * (Bars[1].Close - Bars[1].Open) +
                          2 * (Bars[2].Close - Bars[3].Open) + (Bars[3].Close - Bars[3].Open) / 6);
                value1.Add(new IndicatorDataPoint(input.EndTime, v1));

                // Filter the High - Low with a four-bar symetical FIR filter before the terms are summed.
                var v2 = ((Bars[0].High - Bars[0].Low) + 2 * (Bars[1].High - Bars[1].Low) +
                          2 * (Bars[2].High - Bars[3].Low) + (Bars[3].High - Bars[3].Low) / 6);
                value2.Add(new IndicatorDataPoint(input.EndTime, v2));

                // The numerator and denominator are summed independently
                decimal num   = value1.Sum(point => point.Value);
                decimal denom = value2.Sum(point => point.Value);

                try
                {
                    // The RVI is the ratio of the numerator to the denominator.  Since
                    //  they are lagged by the same amount, due to the filtering,
                    //  the lag is removed by taking the ratio.
                    RviWindow.Add(new IndicatorDataPoint(input.EndTime, num / denom));
                }
                catch (DivideByZeroException zex)
                {
                    throw new Exception(zex.Message + zex.StackTrace);
                }
            }
            return(RviWindow[0].Value);
        }
コード例 #26
0
        protected override void OnBar(Instrument instrument, Bar bar)
        {
            Bars.Add(bar);

            if (lookBackDays.Count == 0)
            {
                return;
            }

            int    length = (int)lookBackDays.Last;
            double a      = SMA.Value(Bars, Bars.Count - 1, length, BarData.Close);

            Log(bar, barsGroup);
            Log(smd.Last, smdGroup);
            Log(lookBackDays.Last, lookBackDaysGroup);
            Log(LookBackDays.Value(smd, smd.Count - 1, 20, 20, 60), lookBackDaysGroup2);

            Console.WriteLine("{0}, {1}", smd.LastDateTime, smd.Last);
            Console.WriteLine("{0}, {1}", lookBackDays.LastDateTime, lookBackDays.Last);
        }
コード例 #27
0
        protected override void OnBar(Instrument instrument, Bar bar)
        {
            Bars.Add(bar);

            Log(bar, barsGroup);

            if (ama.Count == 0)
            {
                return;
            }

            Log(ama.Last, amaGroup);
            Log(ama.ERSeries.Last, erGroup);
            Log(sma.Last, smaGroup);

            Log(KaufmanAMA.Value(Bars, Bars.Count - 1, N, SL, FS), ama2Group);

            Console.WriteLine("{0}, {1}", ama.LastDateTime, ama.Last);
            Console.WriteLine("{0}, {1}", sma.LastDateTime, sma.Last);
        }
コード例 #28
0
        protected override void OnBar(Instrument instrument, Bar bar)
        {
            Log(bar, barChartGroup);

            Bars.Add(bar);

            if (Bars.Count % 20 == 0)
            {
                if (!HasPosition(instrument))
                {
                    Buy(instrument, 5, "Buy");
                }
                else
                {
                    Sell(instrument, 5, "Sell");
                }
            }

            Portfolio.Performance.Update();
        }
コード例 #29
0
        public static DataSeries SMAFilter(string path, int len)
        {
            DataSeries f = new DataSeries("");

            Bars bars = new Bars("", BarScale.Daily, 0);

            StreamReader sr = new StreamReader(path);

            while (sr.Peek() >= 0)
            {
                string   next_line = sr.ReadLine();
                string[] temp_ar   = next_line.Split('	');
                string   date      = temp_ar[0].Trim();
                string   open      = temp_ar[1].Trim();
                string   high      = temp_ar[2].Trim();
                string   low       = temp_ar[3].Trim();
                string   close     = temp_ar[4].Trim();
                string   volume    = temp_ar[5].Trim();

                if ((Convert.ToDouble(open) > 0) & (Convert.ToDouble(high) > 0) & (Convert.ToDouble(low) > 0) & (Convert.ToDouble(close) > 0))
                {
                    bars.Add(Convert.ToDateTime(date), Convert.ToDouble(open), Convert.ToDouble(high), Convert.ToDouble(low), Convert.ToDouble(close), Convert.ToDouble(volume));
                }
            }

            sr.Close();

            for (int b = len; b < bars.Count; b++)
            {
                if (bars.Close[b] > SMA.Value(b, bars.Close, len))
                {
                    f.Add(0, bars.Date[b]);
                }
                else
                {
                    f.Add(1, bars.Date[b]);
                }
            }

            return(f);
        }
コード例 #30
0
ファイル: DPO1_Strategy.cs プロジェクト: zjtan1992/Demo
        protected override void OnBar(Instrument instrument, Bar bar)
        {
            Bars.Add(bar);

            Log(bar, barsGroup);

            if (dpo1.Count == 0)
            {
                return;
            }

            if (sma.Count < length)
            {
                return;
            }

            Log(dpo1.Last, dpo1Group);
            Log(DPO1.Value(Bars, Bars.Count - 1, length, BarData.Close), dpo1ValueGroup);

            Console.WriteLine("{0}, {1}", dpo1.LastDateTime, dpo1.Last);
        }