Exemplo n.º 1
0
        /// <summary>
        /// Returns a TradeRule generated with two indicators and a CompareType
        /// </summary>
        /// <param name="indicator1">The first indicator</param>
        /// <param name="compareType">The comparison type</param>
        /// <param name="indicator2">The last indicator</param>
        /// <returns>Returns a new TradeRule object</returns>
        public static TradeRule GenerateTradeRule(string indicator1, IndicatorCompareType compareType, string indicator2)
        {
            try
            {
                TradeRule tr = null;
                switch (compareType)
                {
                    case IndicatorCompareType.GT:
                    case IndicatorCompareType.LT:
                    case IndicatorCompareType.DOWN_XUNDER:
                    case IndicatorCompareType.UP_XOVER:
                        tr = new SimpleCompareTradeRule(indicator1, compareType, indicator2);
                        break;
                    /// **********************************************
                    /// GDBCup - More compares could be added here
                    /// **********************************************
                    default:
                        tr = null;
                        break;
                }

                return tr;
            }
            catch (TradeRuleException)
            {
                throw;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns a TradeRule generated with two indicators and a CompareType
        /// </summary>
        /// <param name="indicator1">The first indicator</param>
        /// <param name="compareType">The comparison type</param>
        /// <param name="indicator2">The last indicator</param>
        /// <returns>Returns a new TradeRule object</returns>
        public static TradeRule GenerateTradeRule(string indicator1, IndicatorCompareType compareType, string indicator2)
        {
            try
            {
                TradeRule tr = null;
                switch (compareType)
                {
                case IndicatorCompareType.GT:
                case IndicatorCompareType.LT:
                    tr = new SimpleCompareTradeRule(indicator1, compareType, indicator2);
                    break;

                case IndicatorCompareType.crossesAbove:
                case IndicatorCompareType.crossesBelow:
                    tr = new CrossesCompareTradeRule(indicator1, compareType, indicator2);
                    break;

                case IndicatorCompareType.positiveDiverge:
                case IndicatorCompareType.negativeDiverge:
                    tr = new DivergeCompareTradeRule(indicator1, compareType, indicator2);
                    break;

                default:
                    tr = null;
                    break;
                }

                return(tr);
            }
            catch (TradeRuleException)
            {
                throw;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Randomizes the chromosome.
        /// </summary>
        public void Randomize()
        {
            TradeSystemChromosome newChrom = new TradeSystemChromosome(this.ChromosomeValue, this.indicatorHelper, size);
            int    i                    = 1;
            Random rand                 = new Random();
            string indicatorbuy1        = null;
            string indicatorbuy2        = null;
            IndicatorCompareType mixbuy = new IndicatorCompareType();

            this.indicatorHelper.GetRandomIndicators(out indicatorbuy1, out mixbuy, out indicatorbuy2);
            this.ChromosomeValue.BuyCondition.TradeRules.Add(TradeRuleFactory.GenerateTradeRule(indicatorbuy1, mixbuy, indicatorbuy2));

            while (i < size && rand.Next(100) > 40)
            {
                string indicator1        = null;
                string indicator2        = null;
                IndicatorCompareType mix = new IndicatorCompareType();
                this.ChromosomeValue.BuyCondition.RuleJoinTypes.Add(indicatorHelper.GetRandomRuleJoinType());
                indicatorHelper.GetRandomIndicators(out indicator1, out mix, out indicator2);
                this.ChromosomeValue.BuyCondition.TradeRules.Add(TradeRuleFactory.GenerateTradeRule(indicator1, mix, indicator2));

                i++;
            }

            this.Clone();
            this.newID();
        }
Exemplo n.º 4
0
        private double Eval(IndicatorCompareType CompareType, double? indicator1, double? indicator2, double? previousIndicator1, double? previousIndicator2)
        {
            if (indicator1 == null || indicator2 == null)
                return 0D;

            switch (CompareType)
            {
                case IndicatorCompareType.GT:
                    return indicator1 > indicator2 ? 1D : 0D;
                case IndicatorCompareType.LT:
                    return indicator1 < indicator2 ? 1D : 0D;
                case IndicatorCompareType.UP_XOVER:
                    if (previousIndicator1 == null || previousIndicator2 == null)
                        return 0D;
                    return previousIndicator1 < previousIndicator2 && indicator1 > indicator2 ? 1D : 0D;
                case IndicatorCompareType.DOWN_XUNDER:
                    if (previousIndicator1 == null || previousIndicator2 == null)
                        return 0D;
                    return previousIndicator1 > previousIndicator2 && indicator1 < indicator2 ? 1D : 0D;
            }

            return 0D;
        }
 /// <summary>
 /// Initializes a new instance of the SimpleCompareTradeRule class.
 /// </summary>
 /// <param name="indicator1">First indicator.</param>
 /// <param name="compareType">Type of comparison.</param>
 /// <param name="indicator2">Second indicator.</param>
 public DivergeCompareTradeRule(string indicator1, IndicatorCompareType compareType, string indicator2)
     : base(indicator1, compareType, indicator2)
 {
 }
Exemplo n.º 6
0
 /// <summary>
 /// Get a set of 2 random indicators and a compare type.
 /// </summary>
 /// <param name="indicator1">The first random indicator.</param>
 /// <param name="compareType">The compare type for the indicator set.</param>
 /// <param name="indicator2">The second random indicator.</param>
 public void GetRandomIndicators(out string indicator1, out IndicatorCompareType compareType, out string indicator2)
 {
     indicator1 = this.GetRandomIndicator();
     compareType = this.GetRandomCompareType();
     indicator2 = this.GetRandomIndicator(indicator1, compareType);
 }
Exemplo n.º 7
0
        /// <summary>
        /// Gets a second indicator that can be used with the given indicator and compare type.
        /// </summary>
        /// <param name="indicator">Indicator to compare to.</param>
        /// <param name="compareType">Compare type for the indicators.</param>
        /// <returns>A random indicator to caompare with indicator and compareType.</returns>
        private string GetRandomIndicator(string indicator, IndicatorCompareType compareType)
        {
            int num;
            double floatingNum;
            if (indicator.StartsWith("Open", true, null) ||
                indicator.StartsWith("High", true, null) ||
                indicator.StartsWith("Low", true, null) ||
                indicator.StartsWith("Close", true, null) ||
                indicator.StartsWith("EMA", true, null))
            {
                return this.indicatorsGroupA[this.rand.Next(this.indicatorsGroupA.Length)];
            }
            /// *********************************************
            /// GDBCup - Replace SomeIndicatorName with an Indicator name
            /// *********************************************
            else if (indicator.StartsWith("SomeIndicatorName", true, null))
            {
                /// *********************************************
                /// GDBCup - Code is needed here
                /// *********************************************
                return "someString"; /// Revise once coded up
            }
            else if (indicator.StartsWith("AnotherSomeIndicatorName", true, null))
            {
                /// *********************************************
                /// GDBCup - Code is needed here
                /// *********************************************
                return "someString"; /// Revise once coded up
            }
            else if (indicator.StartsWith("AnotherSomeIndicatorName", true, null))
            {
                /// *********************************************
                /// GDBCup - Code is needed here
                /// *********************************************
                return "someString"; /// Revise once coded up
            }
            else if (indicator.StartsWith("AnotherSomeIndicatorName", true, null))
            {
                /// *********************************************
                /// GDBCup - Code is needed here
                /// *********************************************
                return "someString"; /// Revise once coded up
            }
            else if (indicator.StartsWith("AnotherSomeIndicatorName", true, null))
            {

                /// *********************************************
                /// GDBCup - Code is needed here
                /// *********************************************
                return "someString"; /// Revise once coded up
            }
            else if (indicator.StartsWith("AnotherSomeIndicatorName", true, null))
            {
                /// *********************************************
                /// GDBCup - Code is needed here
                /// *********************************************
                return "someString"; /// Revise once coded up
            }
            else if (indicator.StartsWith("AnotherSomeIndicatorName", true, null))
            {
                /// *********************************************
                /// GDBCup - Code is needed here
                /// *********************************************
                return "someString"; /// Revise once coded up
            }
            else
            {
                /// *********************************************
                /// GDBCup - Code is needed here
                /// *********************************************
                return "someString"; /// Revise once coded up
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Get a set of 2 random indicators and a compare type.
 /// </summary>
 /// <param name="indicator1">The first random indicator.</param>
 /// <param name="compareType">The compare type for the indicator set.</param>
 /// <param name="indicator2">The second random indicator.</param>
 public void GetRandomIndicators(out string indicator1, out IndicatorCompareType compareType, out string indicator2)
 {
     indicator1  = this.GetRandomIndicator();
     compareType = this.GetRandomCompareType();
     indicator2  = this.GetRandomIndicator(indicator1, compareType);
 }
Exemplo n.º 9
0
        public string mutateIndicator(string indicator1, IndicatorCompareType compareType)
        {
            string newindicator2 = this.GetRandomIndicator(indicator1, compareType);

            return(newindicator2);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Gets a second indicator that can be used with the given indicator and compare type.
        /// </summary>
        /// <param name="indicator">Indicator to compare to.</param>
        /// <param name="compareType">Compare type for the indicators.</param>
        /// <returns>A random indicator to caompare with indicator and compareType.</returns>
        private string GetRandomIndicator(string indicator, IndicatorCompareType compareType)
        {
            int num;

            num = this.rand.Next(this.indicatorsGroupA.Length);
            while (indicatorsGroupA[num] == indicator)
            {
                num = this.rand.Next(this.indicatorsGroupA.Length);
            }
            return(this.indicatorsGroupA[num]);


            /*
             * else if (indicator.StartsWith("Schaff", true, null) ||
             *      indicator.StartsWith("RSI", true, null) ||
             *      indicator.StartsWith("Stochastics", true, null) ||
             *      indicator.StartsWith("Constant", true, null)||
             *      indicator.StartsWith("Aroon", true, null))
             * {
             *  num = this.rand.Next(this.indicatorsGroupB.Length);
             *  while (indicatorsGroupB[num] == indicator)
             *  {
             *      num = this.rand.Next(this.indicatorsGroupB.Length);
             *  }
             *  return this.indicatorsGroupB[num];
             * }
             * else if (indicator.StartsWith("MACD", true, null))
             * {
             *  num = this.rand.Next(this.indicatorsGroupC.Length);
             *  while (indicatorsGroupC[num] == indicator)
             *  {
             *      num = this.rand.Next(this.indicatorsGroupC.Length);
             *  }
             *  return this.indicatorsGroupC[num];
             * }
             * else if (indicator.StartsWith("Histogram", true, null)||
             *      indicator.StartsWith("Volume", true, null))
             * {
             *  num = this.rand.Next(this.indicatorsGroupD.Length);
             *  while (indicatorsGroupD[num] == indicator)
             *  {
             *      num = this.rand.Next(this.indicatorsGroupD.Length);
             *  }
             *  return this.indicatorsGroupD[num];
             * }
             * else if (indicator.StartsWith("Chaikin", true, null) ||
             *       indicator.StartsWith("Force", true, null))
             * {
             *  num = this.rand.Next(this.indicatorsGroupE.Length);
             *  while (indicatorsGroupE[num] == indicator)
             *  {
             *      num = this.rand.Next(this.indicatorsGroupE.Length);
             *  }
             *  return this.indicatorsGroupE[num];
             * }
             * else //if (indicator.StartsWith("Force", true, null))
             * {
             *  num = this.rand.Next(this.indicatorsGroupF.Length);
             *  while (indicatorsGroupF[num] == indicator)
             *  {
             *      num = this.rand.Next(this.indicatorsGroupF.Length);
             *  }
             *  return this.indicatorsGroupF[num];
             * }*/
        }
 /// <summary>
 /// Initializes a new instance of the SimpleCompareTradeRule class.
 /// </summary>
 /// <param name="indicator1">First indicator.</param>
 /// <param name="compareType">Type of comparison.</param>
 /// <param name="indicator2">Second indicator.</param>
 public SimpleCompareTradeRule(string indicator1, IndicatorCompareType compareType, string indicator2)
     : base(indicator1, compareType, indicator2)
 {
 }
Exemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the TradeRule class.
 /// </summary>
 /// <param name="indicator1">First indicator.</param>
 /// <param name="compareType">Type of comparison.</param>
 /// <param name="indicator2">Second indicator.</param>
 public TradeRule(string indicator1, IndicatorCompareType compareType, string indicator2)
 {
     this.IndicatorName1 = indicator1;
     this.CompareType = compareType;
     this.IndicatorName2 = indicator2;
 }
Exemplo n.º 13
0
 /// <summary>
 /// Initializes a new instance of the SimpleCompareTradeRule class.
 /// </summary>
 /// <param name="indicator1">First indicator.</param>
 /// <param name="compareType">Type of comparison.</param>
 /// <param name="indicator2">Second indicator.</param>
 public CrossesCompareTradeRule(string indicator1, IndicatorCompareType compareType, string indicator2)
     : base(indicator1, compareType, indicator2)
 {
 }
Exemplo n.º 14
0
 /// <summary>
 /// Initializes a new instance of the TradeRule class.
 /// </summary>
 /// <param name="indicator1">First indicator.</param>
 /// <param name="compareType">Type of comparison.</param>
 /// <param name="indicator2">Second indicator.</param>
 public TradeRule(string indicator1, IndicatorCompareType compareType, string indicator2)
 {
     this.IndicatorName1 = indicator1;
     this.CompareType    = compareType;
     this.IndicatorName2 = indicator2;
 }