Пример #1
0
        public void addTestData(DataClass data)
        {
            priceList.Add(data);

            stockDataStorage.Get(IdentifierConstants.PRICE_LIST).Add(new StockData(data.closingPrice, data.date));

            Calculators.ForEach(c => c.Calculate());

            MarketAnalyzer.signal signal        = MarketAnalyzer.analyzeRSI(stockDataStorage.Get(IdentifierConstants.RSI));
            MarketAnalyzer.signal squeezeSignal = MarketAnalyzer.analyzeSqueeze(stockDataStorage.Get(IdentifierConstants.SQUEEZEPOINTS), stockDataStorage.Get(IdentifierConstants.SQUEEZE));

            Collection <StockData> Ma100 = stockDataStorage.Get(IdentifierConstants.SIMPLE_MOVING_AVERAGE, 100);

            //if (signal == MarketAnalyzer.signal.SELLSIGNAL)
            //{
            //    trader.sellStock(1, data);
            //    MarketAnalyzer.ClearStopLoss();
            //}
            //else if (signal == MarketAnalyzer.signal.BUYSIGNAL/* && MarketAnalyzer.analyzeMA(Ma100) != MarketAnalyzer.signal.STOPLOSS*/)
            //{
            //    trader.buyStock(1, data);
            //}
            if (squeezeSignal == MarketAnalyzer.signal.BUYSIGNAL)
            {
                trader.buyStock(1, data);
            }
            else if (squeezeSignal == MarketAnalyzer.signal.SELLSIGNAL)
            {
                trader.sellStock(1, data);
            }
        }
Пример #2
0
        public StockHandler(StockTrader trader, StockDataStorage stockDataStorage)
        {
            priceList = new ObservableCollection<DataClass>();

            this.stockDataStorage = stockDataStorage;

            stockDataStorage.Add(IdentifierConstants.SIMPLE_MOVING_AVERAGE, 20, new ObservableCollection<StockData>());
            stockDataStorage.Add(IdentifierConstants.SIMPLE_MOVING_AVERAGE, 50, new ObservableCollection<StockData>());
            stockDataStorage.Add(IdentifierConstants.SIMPLE_MOVING_AVERAGE, 100, new ObservableCollection<StockData>());
            stockDataStorage.Add(IdentifierConstants.EXPONENTIAL_MOVING_AVERAGE, 20, new ObservableCollection<StockData>());
            stockDataStorage.Add(IdentifierConstants.RSI, new ObservableCollection<StockData>());
            stockDataStorage.Add(IdentifierConstants.PRICE_LIST, new ObservableCollection<StockData>());
            stockDataStorage.Add(IdentifierConstants.UPPERBOLINGER, new ObservableCollection<StockData>());
            stockDataStorage.Add(IdentifierConstants.LOWERBOLINGER, new ObservableCollection<StockData>());
            stockDataStorage.Add(IdentifierConstants.ATR, new ObservableCollection<StockData>());
            stockDataStorage.Add(IdentifierConstants.UPPERKELTNER, new ObservableCollection<StockData>());
            stockDataStorage.Add(IdentifierConstants.LOWERKELTNER, new ObservableCollection<StockData>());
            stockDataStorage.Add(IdentifierConstants.SQUEEZEPOINTS, new ObservableCollection<StockData>());
            stockDataStorage.Add(IdentifierConstants.NOSQUEEZEPOINTS, new ObservableCollection<StockData>());
            stockDataStorage.Add(IdentifierConstants.SQUEEZE, new ObservableCollection<StockData>());

            Calculators = new List<ICalculator>();

            Array.ForEach(new int[] { 20, 50, 100 }, x => Calculators.Add(new CalculateMovingAverage(stockDataStorage.Get(IdentifierConstants.SIMPLE_MOVING_AVERAGE, x), priceList, x)));

            Array.ForEach(new int[] { 20 }, x => Calculators.Add(new CalculateExponentialMovingAvrage(
                stockDataStorage.Get(IdentifierConstants.EXPONENTIAL_MOVING_AVERAGE, x),
                stockDataStorage.Get(IdentifierConstants.SIMPLE_MOVING_AVERAGE, x),
                priceList,
                x)));

            Calculators.Add(new CalculateATR(stockDataStorage.Get(IdentifierConstants.ATR), priceList, 10));

            Calculators.Add(new CalculateRSI(stockDataStorage.Get(IdentifierConstants.RSI), stockDataStorage.Get(IdentifierConstants.PRICE_LIST), 14));

            Calculators.Add(new CalculateBolingerBand(stockDataStorage.Get(IdentifierConstants.UPPERBOLINGER),
                stockDataStorage.Get(IdentifierConstants.LOWERBOLINGER), priceList, stockDataStorage.Get(IdentifierConstants.SIMPLE_MOVING_AVERAGE, 20)));

            Calculators.Add(new CalculateKeltnerBand(stockDataStorage.Get(IdentifierConstants.LOWERKELTNER),
                stockDataStorage.Get(IdentifierConstants.UPPERKELTNER),
                stockDataStorage.Get(IdentifierConstants.ATR),
                stockDataStorage.Get(IdentifierConstants.EXPONENTIAL_MOVING_AVERAGE, 20)));

            Calculators.Add(new CalculateSqueeze(stockDataStorage.Get(IdentifierConstants.SQUEEZE),
                stockDataStorage.Get(IdentifierConstants.SQUEEZEPOINTS),
                stockDataStorage.Get(IdentifierConstants.NOSQUEEZEPOINTS),
                stockDataStorage.Get(IdentifierConstants.LOWERKELTNER),
                stockDataStorage.Get(IdentifierConstants.LOWERBOLINGER),
                stockDataStorage.Get(IdentifierConstants.UPPERKELTNER),
                stockDataStorage.Get(IdentifierConstants.UPPERBOLINGER),
                stockDataStorage.Get(IdentifierConstants.SIMPLE_MOVING_AVERAGE, 20),
                stockDataStorage.Get(IdentifierConstants.EXPONENTIAL_MOVING_AVERAGE, 20),
                priceList, 20
                ));

            this.trader = trader;
        }
Пример #3
0
        public StockHandler(StockTrader trader, StockDataStorage stockDataStorage)
        {
            priceList = new ObservableCollection <DataClass>();

            this.stockDataStorage = stockDataStorage;

            stockDataStorage.Add(IdentifierConstants.SIMPLE_MOVING_AVERAGE, 20, new ObservableCollection <StockData>());
            stockDataStorage.Add(IdentifierConstants.SIMPLE_MOVING_AVERAGE, 50, new ObservableCollection <StockData>());
            stockDataStorage.Add(IdentifierConstants.SIMPLE_MOVING_AVERAGE, 100, new ObservableCollection <StockData>());
            stockDataStorage.Add(IdentifierConstants.EXPONENTIAL_MOVING_AVERAGE, 20, new ObservableCollection <StockData>());
            stockDataStorage.Add(IdentifierConstants.RSI, new ObservableCollection <StockData>());
            stockDataStorage.Add(IdentifierConstants.PRICE_LIST, new ObservableCollection <StockData>());
            stockDataStorage.Add(IdentifierConstants.UPPERBOLINGER, new ObservableCollection <StockData>());
            stockDataStorage.Add(IdentifierConstants.LOWERBOLINGER, new ObservableCollection <StockData>());
            stockDataStorage.Add(IdentifierConstants.ATR, new ObservableCollection <StockData>());
            stockDataStorage.Add(IdentifierConstants.UPPERKELTNER, new ObservableCollection <StockData>());
            stockDataStorage.Add(IdentifierConstants.LOWERKELTNER, new ObservableCollection <StockData>());
            stockDataStorage.Add(IdentifierConstants.SQUEEZEPOINTS, new ObservableCollection <StockData>());
            stockDataStorage.Add(IdentifierConstants.NOSQUEEZEPOINTS, new ObservableCollection <StockData>());
            stockDataStorage.Add(IdentifierConstants.SQUEEZE, new ObservableCollection <StockData>());

            Calculators = new List <ICalculator>();

            Array.ForEach(new int[] { 20, 50, 100 }, x => Calculators.Add(new CalculateMovingAverage(stockDataStorage.Get(IdentifierConstants.SIMPLE_MOVING_AVERAGE, x), priceList, x)));

            Array.ForEach(new int[] { 20 }, x => Calculators.Add(new CalculateExponentialMovingAvrage(
                                                                     stockDataStorage.Get(IdentifierConstants.EXPONENTIAL_MOVING_AVERAGE, x),
                                                                     stockDataStorage.Get(IdentifierConstants.SIMPLE_MOVING_AVERAGE, x),
                                                                     priceList,
                                                                     x)));

            Calculators.Add(new CalculateATR(stockDataStorage.Get(IdentifierConstants.ATR), priceList, 10));

            Calculators.Add(new CalculateRSI(stockDataStorage.Get(IdentifierConstants.RSI), stockDataStorage.Get(IdentifierConstants.PRICE_LIST), 14));

            Calculators.Add(new CalculateBolingerBand(stockDataStorage.Get(IdentifierConstants.UPPERBOLINGER),
                                                      stockDataStorage.Get(IdentifierConstants.LOWERBOLINGER), priceList, stockDataStorage.Get(IdentifierConstants.SIMPLE_MOVING_AVERAGE, 20)));

            Calculators.Add(new CalculateKeltnerBand(stockDataStorage.Get(IdentifierConstants.LOWERKELTNER),
                                                     stockDataStorage.Get(IdentifierConstants.UPPERKELTNER),
                                                     stockDataStorage.Get(IdentifierConstants.ATR),
                                                     stockDataStorage.Get(IdentifierConstants.EXPONENTIAL_MOVING_AVERAGE, 20)));

            Calculators.Add(new CalculateSqueeze(stockDataStorage.Get(IdentifierConstants.SQUEEZE),
                                                 stockDataStorage.Get(IdentifierConstants.SQUEEZEPOINTS),
                                                 stockDataStorage.Get(IdentifierConstants.NOSQUEEZEPOINTS),
                                                 stockDataStorage.Get(IdentifierConstants.LOWERKELTNER),
                                                 stockDataStorage.Get(IdentifierConstants.LOWERBOLINGER),
                                                 stockDataStorage.Get(IdentifierConstants.UPPERKELTNER),
                                                 stockDataStorage.Get(IdentifierConstants.UPPERBOLINGER),
                                                 stockDataStorage.Get(IdentifierConstants.SIMPLE_MOVING_AVERAGE, 20),
                                                 stockDataStorage.Get(IdentifierConstants.EXPONENTIAL_MOVING_AVERAGE, 20),
                                                 priceList, 20
                                                 ));

            this.trader = trader;
        }