Esempio n. 1
0
        public override StockOrder TryToBuy(StockDailyValue dailyValue, int index, float amount, ref float benchmark)
        {
            benchmark = dailyValue.CLOSE;

             if (this.adxIndicator == null)
             { return null; }

             #region Create Buy

             if (this.adxDecorator.Events[this.exhaustionSellIndex][index - 1])
             {
            if (this.SupportShortSelling)
            {
               //if (this.adxIndicator.Events[downTrendIndex][index])
               if (this.SRTrailStop.Events[downTrendIndex][index])
               {
                  return StockOrder.CreateBuyAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE,
                     dailyValue.DATE.AddDays(60), amount, true);
               }
            }
            if (this.SRTrailStop.Events[upTrendIndex][index])
            {
               return StockOrder.CreateBuyAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE,
                  dailyValue.DATE.AddDays(60), amount, false);
            }
             }

             #endregion
             return null;
        }
        public override StockOrder TryToSell(StockDailyValue dailyValue, int index, int number, ref float benchmark)
        {
            benchmark = dailyValue.CLOSE;

             #region Create Sell Order

             if (LastBuyOrder.IsShortOrder)
             {
            // Sell in case of Support detected
            if (closeSerie[index] > middleBandSerie[index])
            {
               return StockOrder.CreateSellAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE,
                   dailyValue.DATE.AddDays(30), number, true);
            }
             }
             else
             {
            // Sell in case of Resistance detected
            if (closeSerie[index] < middleBandSerie[index])
            {
               return StockOrder.CreateSellAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE,
                   dailyValue.DATE.AddDays(30), number, false);
            }
             }

             #endregion
             return null;
        }
        public override StockOrder TryToBuy(StockDailyValue dailyValue, int index, float amount, ref float benchmark)
        {
            benchmark = dailyValue.CLOSE;

             if (this.TriggerIndicator == null) { return null; }

             if (this.SupportShortSelling)
             {
            if (float.IsNaN(hilbertSR.Series[1][index - 1]) && !float.IsNaN(hilbertSR.Series[1][index]))
            {
               return StockOrder.CreateBuyAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(30), amount, true);
            }
             }

             // If we have a support
             if (!float.IsNaN(hilbertSR.Series[0][index]) && dailyValue.CLOSE > hilbertSR.Series[0][index])
             {
            if (float.IsNaN(hilbertSR.Series[0][index - 1]))
            {
               // This is the first bar after the support
               return StockOrder.CreateBuyAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(30), amount, false);
            }

            FloatSerie CloseSerie = Serie.GetSerie(StockDataType.CLOSE);
            if (CloseSerie[index - 1] < hilbertSR.Series[0][index - 1] && CloseSerie[index] > hilbertSR.Series[0][index])
            {
               return StockOrder.CreateBuyAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(30), amount, false);
            }
             }
             return null;
        }
        public override StockOrder TryToBuy(StockDailyValue dailyValue, int index, float amount, ref float benchmark)
        {
            benchmark = dailyValue.CLOSE;

             if (this.SRIndicator == null)
             { return null; }

             #region Create Buy

             if (this.SupportShortSelling)
             {
            // If higher Low Detected
            if (this.SRIndicator.Events[lowerHightEventIndex][index])
            {
               return StockOrder.CreateBuyAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(30), amount, true);
            }
             }
             // If higher Low Detected
             if (this.SRIndicator.Events[higherLowEventIndex][index])
             {
            return StockOrder.CreateBuyAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(30), amount, false);
             }

             #endregion
             return null;
        }
        public override StockOrder TryToBuy(StockDailyValue dailyValue, int index, float amount, ref float benchmark)
        {
            benchmark = dailyValue.CLOSE;

             if (this.trailStop == null)
             { return null; }

             #region Create Buy Order
             if (this.SupportShortSelling)
             {
            if (movingAverage.Series[0][index] > dailyValue.CLOSE) // Check if long term in down trend
            {
               if (trailStop.Events[5][index])
               {
                  return StockOrder.CreateBuyAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(30), amount, true);
               }
            }
             }
             if (movingAverage.Series[0][index] < dailyValue.CLOSE) // Check if long term in up trend
             {
            if (trailStop.Events[4][index])
            {
               return StockOrder.CreateBuyAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(30), amount, false);
            }
             }
             #endregion
             return null;
        }
        public override StockOrder TryToSell(StockDailyValue dailyValue, int index, int number, ref float benchmark)
        {
            benchmark = dailyValue.CLOSE;

             if (this.TriggerIndicator == null) { return null; }

             if (LastBuyOrder.IsShortOrder)
             {
            if (float.IsNaN(hilbertSR.Series[0][index - 1]) && !float.IsNaN(hilbertSR.Series[0][index]))
            {
               return StockOrder.CreateSellAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(30), number, true);
            }
             }
             else
             {
            // If we have a resistance
            if (!float.IsNaN(hilbertSR.Series[1][index]))
            {
               if (float.IsNaN(hilbertSR.Series[1][index - 1]))
               {
                  return StockOrder.CreateSellAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(30), number, false);
               }
            }
            // If we have a support
            if (!float.IsNaN(hilbertSR.Series[0][index]))
            {
               FloatSerie CloseSerie = Serie.GetSerie(StockDataType.CLOSE);
               if (CloseSerie[index - 1] > hilbertSR.Series[0][index - 1] && CloseSerie[index] < hilbertSR.Series[0][index])
               {
                  return StockOrder.CreateSellAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(30), number, false);
               }
            }
             }
             return null;
        }
Esempio n. 7
0
        public override StockOrder TryToSell(StockDailyValue dailyValue, int index, int number, ref float benchmark)
        {
            benchmark = dailyValue.CLOSE;

             #region Create Sell Order
             // Review buy limit according to indicators
             if (LastBuyOrder.IsShortOrder)
             {
            //if (float.IsNaN(trailStop.Series[0][index - 1])&& !float.IsNaN(trailStop.Series[0][index]))
            //{
            //    return StockOrder.CreateSellAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(30), number, true);
            //}
             }
             else
             {
            // Sell in case of Resistance detected
            if (this.SRIndicator.Events[resistanceEventIndex][index])
            {
               return StockOrder.CreateSellAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE,
                   dailyValue.DATE.AddDays(30), number, false);
            }
             }
             #endregion
             return null;
        }
        public override StockOrder TryToSell(StockDailyValue dailyValue, int index, int number, ref float benchmark)
        {
            benchmark = dailyValue.CLOSE;

             float gapInPoints = atr.Series[0][index] * 2;
             StockOrder stockOrder = StockOrder.CreateSellTrailingStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(5), number, dailyValue.CLOSE, gapInPoints, dailyValue);

             return stockOrder;
        }
        public override StockOrder TryToBuy(StockDailyValue dailyValue, int index, float amount, ref float benchmark)
        {
            benchmark = dailyValue.CLOSE;

             if (this.TriggerIndicator == null) { return null; }

             if (this.oscSerie == null) this.oscSerie = (this.TriggerIndicator as IStockIndicator).Series[0];

             if (this.oscSerie[index - 1] < 0 && this.oscSerie[index] > 0)
             {
            trailActivated = false;
            return StockOrder.CreateBuyAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(30), amount, false);
             }
             return null;
        }
        public override StockOrder TryToSell(StockDailyValue dailyValue, int index, int number, ref float benchmark)
        {
            StockDailyValue previousValue = this.Serie.Values.ElementAt(index - 1);
             benchmark = dailyValue.CLOSE;

             #region Create Sell Order
             StockOrder stockOrder = null;

             if (dailyValue.CLOSE < previousValue.CLOSE)
             {
            stockOrder = StockOrder.CreateSellAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(30), number, false);
             }
             #endregion
             return stockOrder;
        }
        public override StockOrder TryToBuy(StockDailyValue dailyValue, int index, float amount, ref float benchmark)
        {
            StockDailyValue previousValue = this.Serie.Values.ElementAt(index - 1);
             benchmark = dailyValue.CLOSE;

             #region Create Buy Order
             StockOrder stockOrder = null;
             if (dailyValue.CLOSE > previousValue.CLOSE)
             {
            stockOrder = StockOrder.CreateBuyAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(30), amount, false);
            LastBuyOrder = stockOrder;
             }
             #endregion
             return stockOrder;
        }
        public override StockOrder TryToBuy(StockDailyValue dailyValue, int index, float amount, ref float benchmark)
        {
            benchmark = dailyValue.CLOSE;
             if (index >= this.Serie.Count - 1)
             {
            return null;
             }

             StockDailyValue tomorrowValue = this.Serie.Values.ElementAt(index + 1);
             if (tomorrowValue.DATE.Month == dailyValue.DATE.Month)
             {
            return null;
             }

             return StockOrder.CreateBuyAtMarketCloseStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(30), amount, false);
        }
        public override StockOrder TryToBuy(StockDailyValue dailyValue, int index, float amount, ref float benchmark)
        {
            benchmark = dailyValue.CLOSE;
             if (!this.Serie.HasVolume)
             {
            return null;
             }

             IStockDecorator momex = this.Serie.GetDecorator("DIV(2)", indicatorName);

             if (momex.Events[1][index - 1] || momex.Events[3][index - 1])
             {
            return StockOrder.CreateBuyAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(30), amount, false);
             }
             return null;
        }
        public override StockOrder TryToSell(StockDailyValue dailyValue, int index, int number, ref float benchmark)
        {
            benchmark = dailyValue.CLOSE;

             if (this.TriggerIndicator == null) { return null; }

             trailActivated = trailActivated ? true : !float.IsNaN(trailStop.Series[0][index]);

             if (!trailActivated && this.oscSerie[index - 1] < this.oscSerie[index]) return null; // Don't sell as long as it's growing up.

             if (trailActivated && float.IsNaN(trailStop.Series[0][index])) // Stop has been triggered
             {
            return StockOrder.CreateSellAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(30), number, false);
             }
             return null;
        }
        public override StockOrder TryToBuy(StockDailyValue dailyValue, int index, float amount, ref float benchmark)
        {
            benchmark = dailyValue.CLOSE;

             if (this.TriggerIndicator == null) { return null; }

             if (this.SupportShortSelling)
             {
            if (float.IsNaN(hilbertSR.Series[1][index - 1]) && !float.IsNaN(hilbertSR.Series[1][index]))
            {
               return StockOrder.CreateBuyAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(30), amount, true);
            }
             }
             if (float.IsNaN(hilbertSR.Series[0][index - 1]) && !float.IsNaN(hilbertSR.Series[0][index]))
             {
            return StockOrder.CreateBuyAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(30), amount, false);
             }
             return null;
        }
        public override StockOrder TryToBuy(StockDailyValue dailyValue, int index, float amount, ref float benchmark)
        {
            benchmark = dailyValue.CLOSE;

             if (this.TriggerIndicator == null) { return null; }

             if (this.SupportShortSelling)
             {
            if (SAR.Events[sarBrokenDownEventIndex][index])
            {
               return StockOrder.CreateBuyAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(30), amount, true);
            }
             }
             if (SAR.Events[sarBrokenUpEventIndex][index])
             {
            return StockOrder.CreateBuyAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(30), amount, false);
             }
             return null;
        }
Esempio n. 17
0
        public override StockOrder TryToSell(StockDailyValue dailyValue, int index, int number, ref float benchmark)
        {
            benchmark = dailyValue.CLOSE;

             #region Create Sell Order
             StockOrder stockOrder = null;
             if (StockDictionary.StockDictionarySingleton.ContainsKey("PCR.EQUITY"))
             {
            FloatSerie pcRatioEMA6 = this.Serie.GetIndicator("EMA(6)").Series[0];
            FloatSerie pcRatioEMA12 = this.Serie.GetIndicator("EMA(12)").Series[0];

            // Review sell limit according to indicators
            if (pcRatioEMA12[index] > pcRatioEMA6[index])
            {
               stockOrder = StockOrder.CreateSellAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(5), number, false);
            }
             }
             #endregion
             return stockOrder;
        }
Esempio n. 18
0
        public override StockOrder TryToBuy(StockDailyValue dailyValue, int index, float amount, ref float benchmark)
        {
            benchmark = dailyValue.CLOSE;

             #region Create Buy Order
             if (this.SupportShortSelling)
             {
            //if (float.IsNaN(trailStop.Series[1][index - 1]) && !float.IsNaN(trailStop.Series[1][index]))
            //{
            //    return StockOrder.CreateBuyAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(30), amount, true);
            //}
             }
             if (this.SRIndicator.Events[supportEventIndex][index] && this.SRIndicator.Series[0][index] < bbBand.Series[1][index])
             {
            return StockOrder.CreateBuyAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(30), amount, false);
             }

             #endregion
             return null;
        }
        public override StockOrder TryToSell(StockDailyValue dailyValue, int index, int number, ref float benchmark)
        {
            benchmark = dailyValue.CLOSE;

             if (this.TriggerIndicator == null) { return null; }

             if (LastBuyOrder.IsShortOrder)
             {
            if (SAR.Events[sarBrokenUpEventIndex][index])
            {
               return StockOrder.CreateSellAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(30), number, true);
            }
             }
             else
             {
            if (SAR.Events[sarBrokenDownEventIndex][index])
            {
               return StockOrder.CreateSellAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(30), number, false);
            }
             }
             return null;
        }
        public override StockOrder TryToBuy(StockDailyValue dailyValue, int index, float amount, ref float benchmark)
        {
            benchmark = dailyValue.CLOSE;

             if (this.OSCSerie == null)
             { return null; }

             #region Create Buy Order
             if (this.SupportShortSelling)
             {
            if (OSCSerie[index - 1] > 0 && OSCSerie[index] <= 0)
            {
               return StockOrder.CreateBuyAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(30), amount, true);
            }
             }
             if (OSCSerie[index - 1] <= 0 && OSCSerie[index] > 0)
             {
            return StockOrder.CreateBuyAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(30), amount, false);
             }
             return null;
             #endregion
        }
        public override StockOrder TryToSell(StockDailyValue dailyValue, int index, int number, ref float benchmark)
        {
            benchmark = dailyValue.CLOSE;

             if (this.TriggerIndicator == null) { return null; }

             if (LastBuyOrder.IsShortOrder)
             {
            if (float.IsNaN(hilbertSR.Series[0][index - 1]) && !float.IsNaN(hilbertSR.Series[0][index]))
            {
               return StockOrder.CreateSellAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(30), number, true);
            }
             }
             else
             {
            if (float.IsNaN(hilbertSR.Series[1][index - 1]) && !float.IsNaN(hilbertSR.Series[1][index]))
            {
               return StockOrder.CreateSellAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(30), number, false);
            }
             }
             return null;
        }
Esempio n. 22
0
        public override StockOrder TryToBuy(StockDailyValue dailyValue, int index, float amount, ref float benchmark)
        {
            benchmark = dailyValue.CLOSE;

             #region Create Buy

             if (this.SupportShortSelling)
             {
            if (highSerie[index] < middleDownBandSerie[index])
            {
               return StockOrder.CreateBuyAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE,
                   dailyValue.DATE.AddDays(30), amount, true);
            }
             }
             // If higher Low Detected
             if (lowSerie[index] > middleUpBandSerie[index])
             {
            return StockOrder.CreateBuyAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(30), amount, false);
             }

             #endregion
             return null;
        }
Esempio n. 23
0
        public override StockOrder TryToBuy(StockDailyValue dailyValue, int index, float amount, ref float benchmark)
        {
            benchmark = dailyValue.CLOSE;

             if (this.trailStop == null)
             { return null; }

             #region Create Buy Order
             if (this.SupportShortSelling)
             {
            if (float.IsNaN(trailStop.Series[1][index - 1]) && !float.IsNaN(trailStop.Series[1][index]))
            {
               return StockOrder.CreateBuyAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(30), amount, true);
            }
             }
             if (float.IsNaN(trailStop.Series[0][index - 1]) && !float.IsNaN(trailStop.Series[0][index]))
             {
            return StockOrder.CreateBuyAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(30), amount, false);
             }

             #endregion
             return null;
        }
Esempio n. 24
0
        public override StockOrder TryToSell(StockDailyValue dailyValue, int index, int number, ref float benchmark)
        {
            benchmark = dailyValue.CLOSE;

             #region Create Sell Order
             // Review buy limit according to indicators
             if (LastBuyOrder.IsShortOrder)
             {
            if (float.IsNaN(trailStop.Series[0][index - 1]) && !float.IsNaN(trailStop.Series[0][index]))
            {
               return StockOrder.CreateSellAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(30), number, true);
            }
             }
             else
             {
            if (float.IsNaN(trailStop.Series[1][index - 1]) && !float.IsNaN(trailStop.Series[1][index]))
            {
               return StockOrder.CreateSellAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(30), number, false);
            }
             }
             #endregion
             return null;
        }
        public override StockOrder TryToSell(StockDailyValue dailyValue, int index, int number, ref float benchmark)
        {
            benchmark = dailyValue.CLOSE;

             #region Create Sell Order
             StockOrder stockOrder = null;
             // Review buy limit according to indicators
             if (LastBuyOrder.IsShortOrder)
             {
            if (OSCSerie[index - 1] <= 0 && OSCSerie[index] > 0)
            {
               stockOrder = StockOrder.CreateSellAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(30), number, true);
            }
             }
             else
             {
            if (OSCSerie[index - 1] > 0 && OSCSerie[index] <= 0)
            {
               stockOrder = StockOrder.CreateSellAtMarketOpenStockOrder(dailyValue.NAME, dailyValue.DATE, dailyValue.DATE.AddDays(30), number, false);
            }
             }
             #endregion
             return stockOrder;
        }
        private void startButton_Click(object sender, EventArgs e)
        {
            if (started)
            {
                replaySerie = null;
                started = false;
                startButton.Text = "Start";
                startButton.Focus();
                nextButton.Enabled = false;
                moveButton.Enabled = false;

                this.Position.Number = 0;
                this.Position.OpenValue = 0;
                this.totalValue = 0;

                this.buyButton.Enabled = false;
                this.sellButton.Enabled = false;
                this.shortButton.Enabled = false;
                this.coverButton.Enabled = false;

                string msg = "Replay serie was:\t" + refSerie.StockName + Environment.NewLine +
                             "Start date:\t\t" + startDate.ToShortDateString() + Environment.NewLine +
                             "NbTrades:\t\t\t" + nbTrade + Environment.NewLine +
                             "NbWinTrades:\t\t" + nbWinTrade + Environment.NewLine +
                             "NbLostTrades:\t\t" + nbLostTrade + Environment.NewLine +
                             "AvgGain:\t\t\t" + (tradeGains.Sum() / nbTrade).ToString("P2");

                MessageBox.Show(msg);
            }
            else
            {
                Cursor cursor = this.Cursor;
                this.Cursor = Cursors.WaitCursor;

                try
                {
                    // Initialise stats
                    nbTrade = 0;
                    nbWinTrade = 0;
                    nbLostTrade = 0;
                    tradeGains.Clear();

                    // Create Portfolio
                    StockAnalyzerForm.MainFrame.CurrentPortofolio = portfolio;

                    portfolio.Clear();
                    replaySerie = new StockSerie("Replay", "Replay", StockSerie.Groups.ALL, StockDataProvider.Replay);

                    // Random pick

                    Random rand = new Random(DateTime.Now.Millisecond);
                    var series =
                       StockDictionary.StockDictionarySingleton.Values.Where(s => !s.IsPortofolioSerie && s.BelongsToGroup(StockSerie.Groups.COUNTRY))
                          .Select(s => s.StockName);

                    StockSerie serie = null;
                    do
                    {
                        string stockName = series.ElementAt(rand.Next(0, series.Count()));

                        serie = StockDictionary.StockDictionarySingleton[stockName];
                        serie.Initialise();
                        serie.BarDuration = StockSerie.StockBarDuration.Daily;
                    }
                    while (serie.Count < 400);

                    DateTime currentDate = DateTime.Today;
                    refSerie = new StockSerie(serie.StockName, serie.ShortName, serie.StockGroup, StockDataProvider.Replay);
                    foreach (StockDailyValue dailyVal in serie.Values)
                    {
                        StockDailyValue newValue = new StockDailyValue(serie.StockName, dailyVal.OPEN, dailyVal.HIGH, dailyVal.LOW, dailyVal.CLOSE, dailyVal.VOLUME, currentDate);
                        refSerie.Add(currentDate, newValue);
                        currentDate = currentDate.AddDays(1);
                    }

                    currentDate = DateTime.Today;
                    int nbInitBars = rand.Next(200, refSerie.Count - 200);

                    for (index = 0; index < nbInitBars; index++)
                    {
                        replaySerie.Add(currentDate, refSerie.ValueArray[index]);
                        currentDate = currentDate.AddDays(1);
                    }

                    dailyValue = serie.Values.Last();
                    startDate = dailyValue.DATE;

                    startButton.Text = "Stop";
                    nextButton.Enabled = true;
                    moveButton.Enabled = true;
                    nextButton.Focus();

                    OnPositionClosed();

                    this.Position.Number = 0;
                    this.Position.OpenValue = 0;
                    this.Position.CurrentValue = replaySerie.Values.Last().CLOSE;
                    this.totalValue = 0;

                    started = true;

                    refSerie.BarDuration = StockAnalyzerForm.MainFrame.BarDuration;
                    replaySerie.BarDuration = StockAnalyzerForm.MainFrame.BarDuration;
                    StockAnalyzerForm.MainFrame.CurrentStockSerie = replaySerie;

                    StockAnalyzerForm.MainFrame.Activate();
                }
                catch
                {
                }
                finally
                {
                    this.Cursor = cursor;
                }
            }
        }
        private void PerformSell(StockDailyValue dailyValue, int qty, float value)
        {
            this.Position.Close();

            // Statistics
            //nbTrade++;
            //if (AddedValue > 0)
            //{
            //    nbWinTrade++;
            //}
            //else
            //{
            //    nbLostTrade++;
            //}
            //tradeGains.Add(this.CalculateAddedValuePercent(value));

            //this.totalValue += 1000f * this.CalculateAddedValuePercent(value);
            //OnPropertyChanged("TotalValue");

            StockOrder stockOrder = StockOrder.CreateExecutedOrder(replaySerie.StockName, StockOrder.OrderType.SellAtMarketClose, (bool)(this.Position.Number < 0), dailyValue.DATE, dailyValue.DATE, 1, value, 0);
            this.portfolio.OrderList.Add(stockOrder);

            nextButton.Focus();

            this.HalfPosition = false;
            this.Stop = 0;
            this.Target = 0;
        }
        private void NextStep()
        {
            index++;
            DateTime currentDate = DateTime.Today;
            refSerie.BarDuration = StockSerie.StockBarDuration.Daily;
            if (index < refSerie.Count)
            {
                replaySerie.IsInitialised = false;
                replaySerie.ClearBarDurationCache();
                replaySerie.BarDuration = StockSerie.StockBarDuration.Daily;
                StockDailyValue dailyVal = null;
                for (int i = 0; i < index; i++)
                {
                    dailyVal = refSerie.ValueArray[i];
                    replaySerie.Add(currentDate, dailyVal);
                    currentDate = currentDate.AddDays(1);
                }
                replaySerie.Initialise();
                dailyValue = dailyVal;

                this.Position.CurrentValue = dailyValue.CLOSE;
                this.Variation = dailyValue.VARIATION;

                this.Position.ValidatePosition();

                replaySerie.BarDuration = StockAnalyzerForm.MainFrame.BarDuration;
                StockAnalyzerForm.MainFrame.CurrentStockSerie = replaySerie;
            }
            else
            {
                MessageBox.Show("Replay finished !!!");
            }
        }
Esempio n. 29
0
 public bool LowerOrEquals(StockDataType dataType, StockDailyValue dailyValue, float accuracyPercent)
 {
     float thisValue = this.GetStockData(dataType);
      float otherValue = dailyValue.GetStockData(dataType);
      float accuracy = thisValue * accuracyPercent;
      if (((thisValue - accuracy) <= otherValue))
      {
     return true;
      }
      else
      {
     return false;
      }
 }
Esempio n. 30
0
 public static StockDailyValue ReadMarketDataFromCSVStream(StreamReader sr, string stockName, bool useAdjusted)
 {
     StockDailyValue stockValue = null;
      try
      {
     // File format
     // Date,Open,High,Low,Close,Volume,Adj Close (UpVolume, Tick, Uptick)
     // 2010-06-18,10435.00,10513.75,10379.60,10450.64,4555360000,10450.64
     string[] row = sr.ReadLine().Split(',');
     if (row.Length == 7)
     {
        if (useAdjusted || row[4] != row[6])
        {
           float close = float.Parse(row[4], usCulture);
           float adjClose = float.Parse(row[6], usCulture);
           float adjRatio = adjClose / close;
           stockValue = new StockDailyValue(
               stockName,
               float.Parse(row[1], usCulture) * adjRatio,
               float.Parse(row[2], usCulture) * adjRatio,
               float.Parse(row[3], usCulture) * adjRatio,
               adjClose,
               long.Parse(row[5], usCulture),
               DateTime.Parse(row[0], usCulture));
        }
        else
        {
           stockValue = new StockDailyValue(
                   stockName,
                   float.Parse(row[1], usCulture),
                   float.Parse(row[2], usCulture),
                   float.Parse(row[3], usCulture),
                   float.Parse(row[4], usCulture),
                   long.Parse(row[5], usCulture),
                   DateTime.Parse(row[0], usCulture));
        }
     }
     else if (row.Length == 10)
     {
        stockValue = new StockDailyValue(
                    stockName,
                    float.Parse(row[1], usCulture),
                    float.Parse(row[2], usCulture),
                    float.Parse(row[3], usCulture),
                    float.Parse(row[4], usCulture),
                    long.Parse(row[5], usCulture),
                    long.Parse(row[7], usCulture),
                    int.Parse(row[8], usCulture),
                    int.Parse(row[9], usCulture),
                    DateTime.Parse(row[0], usCulture));
     }
      }
      catch (System.Exception)
      {
     // Assume input is right, Ignore invalid lines
      }
      return stockValue;
 }