コード例 #1
0
        /// <summary>
        /// Processes the orders for today.
        /// </summary>
        /// <param name="currentPriceData">The current price data.</param>
        public void ProcessOrdersForToday(PriceData currentPriceData)
        {
            // First, cancel expired orders.
            this.queuedOrders.RemoveAll(order => order.GoodUntil < currentPriceData.IntervalOpenTime);

            // Next, process the pending market orders at the open price for the day.
            var marketOrders = this.queuedOrders.Where(order => order.Type == Order.Types.Market).ToList();
            this.ProcessMarketOrders(marketOrders, currentPriceData.Open);

            // Next, procecess the stop orders based on the high/low for the day.
            var stopOrders = this.queuedOrders.Where(order => order.Type == Order.Types.StopMarket).ToList();
            this.ProcessStopOrders(stopOrders, currentPriceData.Low, currentPriceData.High);

            //// Update the Highest/Lowest account balance metrics.

            if (this.CurrentBalance > this.HighestBalance)
            {
                this.HighestBalance = this.CurrentBalance;
            }

            if (this.CurrentBalance < this.LowestBalance)
            {
                this.LowestBalance = this.CurrentBalance;
            }

            // Remove all orders that have been processes.
            this.queuedOrders.RemoveAll(order => !order.IsPending);
        }
コード例 #2
0
        /// <summary>
        /// Calculates the daily direction of the stock price.
        /// </summary>
        /// <param name="current">The current day's price data.</param>
        /// <param name="previousDayIndex">Index of the previous day.  This allows the method to be used recursively.</param>
        /// <returns>
        /// The daily price direction.
        /// </returns>
        private PriceDirections CalculateDailyDirection(PriceData current, int previousDayIndex)
        {
            var previous = this.priceHistory[previousDayIndex];

            if (previous.Direction == PriceDirections.Inside)
            {
                // Inside days cannot be used for this calculation...skip to the next prior day using a recursive call.
                return this.CalculateDailyDirection(current, previousDayIndex - 1);
            }

            // UP days are days with a higher high and a higher low.
            if (current.High > previous.High && current.Low > previous.Low)
            {
                return PriceDirections.Up;
            }

            // DOWN days are days with a lower high and a lower low.
            if (current.High < previous.High && current.Low < previous.Low)
            {
                return PriceDirections.Down;
            }

            // INSIDE days are inconclusive days with lower highs and higher lows.
            // These days will be omitted from most price comparisons.
            if (current.High <= previous.High && current.Low >= previous.Low)
            {
                return PriceDirections.Inside;
            }

            // OUTSIDE days are inconclusive days with higher highs and lower lows.
            // Unlike INSIDE days, these days are not entirely inconslusive...
            // ...they just require an additional day of data to determine their true direction.
            if (current.High >= previous.High && current.Low <= previous.Low)
            {
                return PriceDirections.Outside;
            }

            // Exception case
            return PriceDirections.Uncalculated;
        }