Пример #1
0
        private void ProcessSellTrailingOrder(StockDailyValue dailyValue)
        {
            // Deal with stock market open fix
             if (dailyValue.OPEN <= TargetLimit)
             {
            this.Value = dailyValue.OPEN;
            Fee = CalculateFee(this.Number, this.Value);
            this.ExecutionDate = dailyValue.DATE;
            this.State = OrderStatus.Executed;
             }
             else
             {
            switch (dailyValue.getOHLCType())
            {
               // The up trend indicates the stock reaches its low before reaching its high
               case OHLCType.UpTrend:
               case OHLCType.BottomUpTrend:
               case OHLCType.TopUpTrend:
                  if (dailyValue.OPEN <= TargetLimit)
                  {
                     this.Value = dailyValue.OPEN;
                     Fee = CalculateFee(this.Number, this.Value);
                     this.ExecutionDate = dailyValue.DATE;
                     this.State = OrderStatus.Executed;
                  }
                  else
                  {
                     if (dailyValue.LOW <= TargetLimit)
                     {
                        this.Value = TargetLimit;
                        Fee = CalculateFee(this.Number, this.Value);
                        this.ExecutionDate = dailyValue.DATE;
                        this.State = OrderStatus.Executed;
                     }
                     else
                     {
                        // The stock reaches its high before it closes so update the benchmark
                        Benchmark = Math.Max(dailyValue.HIGH, Benchmark);

                        // Check is close is lower than target
                        if (dailyValue.CLOSE <= TargetLimit)
                        {
                           // Create new sell order
                           this.Value = TargetLimit;
                           Fee = CalculateFee(this.Number, this.Value);
                           this.ExecutionDate = dailyValue.DATE;
                           this.State = OrderStatus.Executed;
                        }
                     }
                  }
                  break;
               // The down trend indicates the stock reaches its high before reaching its low
               case OHLCType.TopDownTrend:
               case OHLCType.BottomDownTrend:
               case OHLCType.DownTrend:
                  Benchmark = Math.Max(dailyValue.HIGH, Benchmark);

                  if (dailyValue.LOW <= TargetLimit)
                  {
                     this.Value = TargetLimit;
                     Fee = CalculateFee(this.Number, this.Value);
                     this.ExecutionDate = dailyValue.DATE;
                     this.State = OrderStatus.Executed;
                  }
                  break;
               default:
                  break;
            }
             }
        }
Пример #2
0
        private void ProcessBuyTrailingOrder(StockDailyValue dailyValue)
        {
            // Deal with stock market open fix
             if (dailyValue.OPEN >= this.TargetLimit) // Buy at open open price. It reallity it could buy lower before the market opens during fix.
             {
            // Execute Order
            this.Value = dailyValue.OPEN;
            CalculateNumberAndFeeFromAmount();
            this.ExecutionDate = dailyValue.DATE;
            this.State = OrderStatus.Executed;
            this.ExecutionDate = dailyValue.DATE;
             }
             else
             {
            // Detect wether buy order has to be executed according to the daily value trend
            switch (dailyValue.getOHLCType())
            {
               // The up trend indicates the stock reaches its low before reaching its high
               case OHLCType.UpTrend:
               case OHLCType.BottomUpTrend:
               case OHLCType.TopUpTrend:
                  // Update the benchmark with the new low value if lower than previous benchmark
                  Benchmark = Math.Min(dailyValue.LOW, Benchmark);

                  if (dailyValue.HIGH >= TargetLimit)
                  {
                     // Execute Order
                     this.Value = TargetLimit;
                     CalculateNumberAndFeeFromAmount();
                     this.ExecutionDate = dailyValue.DATE;
                     this.State = OrderStatus.Executed;
                     this.ExecutionDate = dailyValue.DATE;
                  }
                  break;
               // The down trend indicates the stock reaches its high before reaching its low
               case OHLCType.TopDownTrend:
               case OHLCType.BottomDownTrend:
               case OHLCType.DownTrend:

                  if (dailyValue.HIGH >= TargetLimit)  // Target limit was between Open and High
                  {
                     // Execute Order
                     this.Value = TargetLimit;
                     CalculateNumberAndFeeFromAmount();
                     this.ExecutionDate = dailyValue.DATE;
                     this.State = OrderStatus.Executed;
                     this.ExecutionDate = dailyValue.DATE;
                  }
                  else
                  {   // Update the benchmark with the new low value if lower than previous benchmark
                     Benchmark = Math.Min(dailyValue.LOW, Benchmark);

                     if (dailyValue.CLOSE >= TargetLimit)    // Check if close is higher than target
                     {
                        // Execute Order
                        this.Value = TargetLimit;
                        CalculateNumberAndFeeFromAmount();
                        this.ExecutionDate = dailyValue.DATE;
                        this.State = OrderStatus.Executed;
                        this.ExecutionDate = dailyValue.DATE;
                     }
                  }
                  break;
               default:
                  break;
            }
             }
        }