Exemple #1
0
        private void TestIndicator(IIndicator indicator, SlotTypes slotType, IDataSet dataSet, Random random)
        {
            indicator.Initialize(slotType);

            // List parameters
            foreach (ListParam list in indicator.IndParam.ListParam)
            {
                if (list.Enabled)
                {
                    list.Index = random.Next(list.ItemList.Length);
                    list.Text  = list.ItemList[list.Index];
                }
            }

            // Numeric parameters
            foreach (NumericParam num in indicator.IndParam.NumParam)
            {
                if (num.Enabled)
                {
                    double step    = Math.Pow(10, -num.Point);
                    double minimum = num.Min;
                    double maximum = num.Max;
                    double value   = minimum + step * random.Next((int)((maximum - minimum) / step));
                    num.Value = Math.Round(value, num.Point);
                }
            }

            indicator.Calculate(dataSet);
        }
        public void Pivot_Point_On_Sample_Data_Test()
        {
            var values         = _indicator.Calculate(PpData.HistoricalPrices);
            var expectedValues = PpData.PivotPointValues;

            values.ShouldAllBeEquivalentTo(expectedValues);
        }
Exemple #3
0
        public bool Calculate(IReadOnlyList <Candle> candles, int index)
        {
            var previousDiff = _difference;

            _difference = _indicator.Calculate(candles, index) - _indicator1.Calculate(candles, index);

            return(_difference < 0 && previousDiff >= 0);
        }
Exemple #4
0
        /// <summary>
        /// Runs source data set over specified indicator.
        /// </summary>
        /// <typeparam name="TValue">Input type.</typeparam>
        /// <typeparam name="TResult">Result type.</typeparam>
        /// <param name="indicator">Indicator.</param>
        /// <param name="source">Data.</param>
        public static void Run <TValue, TResult>(this IIndicator <TValue, TResult> indicator, IEnumerable <TValue> source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("indicator");
            }

            foreach (var item in source)
            {
                indicator.Calculate(item);
            }
        }
Exemple #5
0
        internal static IList <Signal> GenerateSignalsForMovingAverages(IIndicator indicator, int term, IList <Price> prices)
        {
            var signals = new List <Signal>();
            var values  = indicator.Calculate(prices);

            for (int i = term; i < prices.Count; i++)
            {
                if (values[i - term].Value <values[i - term + 1].Value && prices[i].ClosePrice> values[i - term + 1].Value)
                {
                    signals.Add(new Signal(SignalAction.Buy)
                    {
                        Date = prices[i].Date
                    });
                }
                else if (values[i - term].Value > values[i - term + 1].Value && prices[i].ClosePrice < values[i - term + 1].Value)
                {
                    signals.Add(new Signal(SignalAction.Sell)
                    {
                        Date = prices[i].Date
                    });
                }
            }
            return(signals);
        }
Exemple #6
0
 public bool Calculate(IReadOnlyList <Candle> candles, int index)
 => _indicator.Calculate(candles, index) > _indicator1.Calculate(candles, index);
Exemple #7
0
 private static IList <CompanyIndicatorValues> ComputeIndicatorValues(IIndicator indicator, IEnumerable <CompanyPricesDto> companyPrices)
 {
     return((companyPrices.Select(company => new { company, values = company.Prices.Count > indicator.RequiredPricesForSignalCount ? indicator.Calculate(company.Prices) : new List <IndicatorValue>() })
             .Select(@t => new CompanyIndicatorValues
     {
         Company = @t.company.Company,
         IndicatorValues = @t.values
     })).ToList());
 }
        private void TestIndicator(IIndicator indicator, SlotTypes slotType, IDataSet dataSet, Random random)
        {
            indicator.Initialize(slotType);

            // List parameters
            foreach (ListParam list in indicator.IndParam.ListParam)
                if (list.Enabled)
                {
                    list.Index = random.Next(list.ItemList.Length);
                    list.Text = list.ItemList[list.Index];
                }

            // Numeric parameters
            foreach (NumericParam num in indicator.IndParam.NumParam)
                if (num.Enabled)
                {
                    double step = Math.Pow(10, -num.Point);
                    double minimum = num.Min;
                    double maximum = num.Max;
                    double value = minimum + step * random.Next((int)((maximum - minimum) / step));
                    num.Value = Math.Round(value, num.Point);
                }

            indicator.Calculate(dataSet);
        }