Esempio n. 1
0
        /// <param name="series"> a time series </param>
        /// <returns> a 2-period RSI strategy </returns>
        public static Strategy BuildStrategy(TimeSeries series)
        {
            if (series == null)
            {
                throw new ArgumentException("Series cannot be null");
            }

            var closePrice = new ClosePriceIndicator(series);
            var shortSma   = new SMAIndicator(closePrice, 5);
            var longSma    = new SMAIndicator(closePrice, 200);

            // We use a 2-period RSI indicator to identify buying
            // or selling opportunities within the bigger trend.
            var rsi = new RSIIndicator(closePrice, 2);

            // Entry rule
            // The long-term trend is up when a security is above its 200-period SMA.
            var entryRule = (new OverIndicatorRule(shortSma, longSma)).And(new CrossedDownIndicatorRule(rsi, Decimal.ValueOf(5))).And(new OverIndicatorRule(shortSma, closePrice));             // Signal 2 -  Signal 1 -  Trend

            // Exit rule
            // The long-term trend is down when a security is below its 200-period SMA.
            var exitRule = (new UnderIndicatorRule(shortSma, longSma)).And(new CrossedUpIndicatorRule(rsi, Decimal.ValueOf(95))).And(new UnderIndicatorRule(shortSma, closePrice));             // Signal 2 -  Signal 1 -  Trend

            return(new Strategy(entryRule, exitRule));
        }
        void labelDisplayMode_SelectedIndexChanged(object sender, EventArgs e)
        {
            animationPickerLabel.Text = animationPicker.Items[animationPicker.SelectedIndex];

            NumericalAxis numericalAxis = new NumericalAxis();

            numericalAxis.OpposedPosition    = true;
            numericalAxis.ShowMajorGridLines = false;
            if (Device.RuntimePlatform == Device.UWP)
            {
                numericalAxis.LabelStyle.LabelFormat = "'$'0.00";
            }
            else
            {
                numericalAxis.LabelStyle.LabelFormat = "'$'##.##";
            }
            switch (animationPicker.SelectedIndex)
            {
            case 0:
                Chart.TechnicalIndicators.RemoveAt(0);
                AccumulationDistributionIndicator sma = new AccumulationDistributionIndicator();
                sma.SeriesName = "Series";
                sma.YAxis      = numericalAxis;
                Chart.TechnicalIndicators.Add(sma);
                break;

            case 1:
                Chart.TechnicalIndicators.RemoveAt(0);
                AverageTrueIndicator sma1 = new AverageTrueIndicator();
                sma1.SeriesName = "Series";
                sma1.Period     = 14;
                sma1.YAxis      = numericalAxis;
                Chart.TechnicalIndicators.Add(sma1);
                break;

            case 2:
                Chart.TechnicalIndicators.RemoveAt(0);
                ExponentialMovingAverageIndicator sma2 = new ExponentialMovingAverageIndicator();
                sma2.SeriesName = "Series";
                sma2.Period     = 14;
                sma2.YAxis      = numericalAxis;
                Chart.TechnicalIndicators.Add(sma2);
                break;

            case 3:
                Chart.TechnicalIndicators.RemoveAt(0);
                MomentumIndicator sma3 = new MomentumIndicator();
                sma3.SeriesName = "Series";
                sma3.Period     = 14;
                sma3.YAxis      = numericalAxis;
                Chart.TechnicalIndicators.Add(sma3);
                break;

            case 4:
                if (Chart.TechnicalIndicators.Count > 0)
                {
                    Chart.TechnicalIndicators.RemoveAt(0);
                }
                SimpleMovingAverageIndicator sma4 = new SimpleMovingAverageIndicator();
                sma4.YAxis      = numericalAxis;
                sma4.SeriesName = "Series";
                sma4.Period     = 14;
                Chart.TechnicalIndicators.Add(sma4);
                break;

            case 5:
                Chart.TechnicalIndicators.RemoveAt(0);
                RSIIndicator sma5 = new RSIIndicator();
                sma5.SeriesName = "Series";
                sma5.Period     = 14;
                sma5.YAxis      = numericalAxis;
                Chart.TechnicalIndicators.Add(sma5);
                break;

            case 6:
                Chart.TechnicalIndicators.RemoveAt(0);
                TriangularMovingAverageIndicator sma6 = new TriangularMovingAverageIndicator();
                sma6.SeriesName = "Series";
                sma6.Period     = 14;
                sma6.YAxis      = numericalAxis;
                Chart.TechnicalIndicators.Add(sma6);
                break;

            case 7:
                Chart.TechnicalIndicators.RemoveAt(0);
                MACDIndicator sma7 = new MACDIndicator();
                sma7.ItemsSource = (Chart.BindingContext as TechnicalIndicatorViewModel).TechnicalIndicatorData;
                sma7.SeriesName  = "Series";
                sma7.LongPeriod  = 10;
                sma7.ShortPeriod = 2;
                sma7.Trigger     = 14;
                sma7.YAxis       = numericalAxis;
                Chart.TechnicalIndicators.Add(sma7);
                break;

            case 8:
                Chart.TechnicalIndicators.RemoveAt(0);
                StochasticIndicator sma8 = new StochasticIndicator();
                sma8.SeriesName = "Series";
                sma8.Period     = 14;
                sma8.KPeriod    = 5;
                sma8.DPeriod    = 6;
                sma8.YAxis      = numericalAxis;
                Chart.TechnicalIndicators.Add(sma8);
                break;

            case 9:
                Chart.TechnicalIndicators.RemoveAt(0);
                BollingerBandIndicator sma9 = new BollingerBandIndicator();
                sma9.Period     = 14;
                sma9.SeriesName = "Series";
                sma9.YAxis      = numericalAxis;
                Chart.TechnicalIndicators.Add(sma9);
                break;
            }
        }
        void labelDisplayMode_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (animationPicker.SelectedIndex)
            {
            case 0:
                Chart.TechnicalIndicators.RemoveAt(0);
                AccumulationDistributionIndicator sma = new AccumulationDistributionIndicator();
                sma.SeriesName = "Series";
                NumericalAxis numericalAxis = new NumericalAxis();
                numericalAxis.OpposedPosition    = true;
                numericalAxis.ShowMajorGridLines = false;
                sma.YAxis = numericalAxis;
                Chart.TechnicalIndicators.Add(sma);
                break;

            case 1:
                Chart.TechnicalIndicators.RemoveAt(0);
                AverageTrueIndicator sma1 = new AverageTrueIndicator();
                sma1.SeriesName = "Series";
                sma1.Period     = 14;
                NumericalAxis numericalAxis1 = new NumericalAxis();
                numericalAxis1.OpposedPosition    = true;
                numericalAxis1.ShowMajorGridLines = false;
                sma1.YAxis = numericalAxis1;
                Chart.TechnicalIndicators.Add(sma1);
                break;

            case 2:
                Chart.TechnicalIndicators.RemoveAt(0);
                ExponentialMovingAverageIndicator sma2 = new ExponentialMovingAverageIndicator();
                sma2.SeriesName = "Series";
                sma2.Period     = 14;
                NumericalAxis numericalAxis2 = new NumericalAxis();
                numericalAxis2.OpposedPosition    = true;
                numericalAxis2.ShowMajorGridLines = false;
                sma2.YAxis = numericalAxis2;
                Chart.TechnicalIndicators.Add(sma2);
                break;

            case 3:
                Chart.TechnicalIndicators.RemoveAt(0);
                MomentumIndicator sma3 = new MomentumIndicator();
                sma3.SeriesName = "Series";
                sma3.Period     = 14;
                NumericalAxis numericalAxis3 = new NumericalAxis();
                numericalAxis3.OpposedPosition    = true;
                numericalAxis3.ShowMajorGridLines = false;
                sma3.YAxis = numericalAxis3;
                Chart.TechnicalIndicators.Add(sma3);
                break;

            case 4:
                if (Chart.TechnicalIndicators.Count > 0)
                {
                    Chart.TechnicalIndicators.RemoveAt(0);
                }
                SimpleMovingAverageIndicator sma4 = new SimpleMovingAverageIndicator();
                NumericalAxis numericalAxis4      = new NumericalAxis();
                numericalAxis4.OpposedPosition    = true;
                numericalAxis4.ShowMajorGridLines = false;
                sma4.YAxis      = numericalAxis4;
                sma4.SeriesName = "Series";
                sma4.Period     = 14;
                Chart.TechnicalIndicators.Add(sma4);
                break;

            case 5:
                Chart.TechnicalIndicators.RemoveAt(0);
                RSIIndicator sma5 = new RSIIndicator();
                sma5.SeriesName = "Series";
                sma5.Period     = 14;
                NumericalAxis numericalAxis5 = new NumericalAxis();
                numericalAxis5.OpposedPosition    = true;
                numericalAxis5.ShowMajorGridLines = false;
                sma5.YAxis = numericalAxis5;
                Chart.TechnicalIndicators.Add(sma5);
                break;

            case 6:
                Chart.TechnicalIndicators.RemoveAt(0);
                TriangularMovingAverageIndicator sma6 = new TriangularMovingAverageIndicator();
                sma6.SeriesName = "Series";
                sma6.Period     = 14;
                NumericalAxis numericalAxis6 = new NumericalAxis();
                numericalAxis6.OpposedPosition    = true;
                numericalAxis6.ShowMajorGridLines = false;
                sma6.YAxis = numericalAxis6;
                Chart.TechnicalIndicators.Add(sma6);
                break;

            case 7:
                Chart.TechnicalIndicators.RemoveAt(0);
                MACDIndicator sma7 = new MACDIndicator();
                sma7.ItemsSource = (this.BindingContext as ViewModel).TechnicalIndicatorData;
                sma7.SeriesName  = "Series";
                sma7.LongPeriod  = 10;
                sma7.ShortPeriod = 2;
                sma7.Trigger     = 14;
                NumericalAxis numericalAxis7 = new NumericalAxis();
                numericalAxis7.OpposedPosition    = true;
                numericalAxis7.ShowMajorGridLines = false;
                sma7.YAxis = numericalAxis7;
                Chart.TechnicalIndicators.Add(sma7);
                break;

            case 8:
                Chart.TechnicalIndicators.RemoveAt(0);
                StochasticIndicator sma8 = new StochasticIndicator();
                sma8.SeriesName = "Series";
                sma8.Period     = 14;
                sma8.KPeriod    = 5;
                sma8.DPeriod    = 6;
                NumericalAxis numericalAxis8 = new NumericalAxis();
                numericalAxis8.OpposedPosition    = true;
                numericalAxis8.ShowMajorGridLines = false;
                sma8.YAxis = numericalAxis8;
                Chart.TechnicalIndicators.Add(sma8);
                break;

            case 9:
                Chart.TechnicalIndicators.RemoveAt(0);
                BollingerBandIndicator sma9 = new BollingerBandIndicator();
                sma9.Period     = 14;
                sma9.SeriesName = "Series";
                NumericalAxis numericalAxis9 = new NumericalAxis();
                numericalAxis9.OpposedPosition    = true;
                numericalAxis9.ShowMajorGridLines = false;
                sma9.YAxis = numericalAxis9;
                Chart.TechnicalIndicators.Add(sma9);
                break;
            }
        }
        private void SelectLabelMode_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e)
        {
            String selectedItem = adapter[e.Position];

            if (selectedItem.Equals("Accumulation Distribution Indicator"))
            {
                chart.TechnicalIndicators.RemoveAt(0);
                AccumulationDistributionIndicator accumulationDistribution = new AccumulationDistributionIndicator();
                NumericalAxis numericalAxis = new NumericalAxis();
                numericalAxis.OpposedPosition         = true;
                numericalAxis.ShowMajorGridLines      = false;
                accumulationDistribution.YAxis        = numericalAxis;
                accumulationDistribution.SeriesName   = "Series";
                accumulationDistribution.XBindingPath = "XValue";
                accumulationDistribution.Open         = "Open";
                accumulationDistribution.Close        = "Close";
                accumulationDistribution.High         = "High";
                accumulationDistribution.Low          = "Low";
                chart.TechnicalIndicators.Add(accumulationDistribution);
            }
            else if (selectedItem.Equals("Average True Indicator"))
            {
                chart.TechnicalIndicators.RemoveAt(0);
                AverageTrueIndicator aTR           = new AverageTrueIndicator();
                NumericalAxis        numericalAxis = new NumericalAxis();
                numericalAxis.OpposedPosition    = true;
                numericalAxis.ShowMajorGridLines = false;
                aTR.YAxis        = numericalAxis;
                aTR.Period       = 14;
                aTR.SeriesName   = "Series";
                aTR.XBindingPath = "XValue";
                aTR.Open         = "Open";
                aTR.Close        = "Close";
                aTR.High         = "High";
                aTR.Low          = "Low";
                chart.TechnicalIndicators.Add(aTR);
            }
            else if (selectedItem.Equals("Exponential Moving Averge Indicator"))
            {
                chart.TechnicalIndicators.RemoveAt(0);
                ExponentialMovingAverageIndicator eMA = new ExponentialMovingAverageIndicator();
                NumericalAxis numericalAxis           = new NumericalAxis();
                numericalAxis.OpposedPosition    = true;
                numericalAxis.ShowMajorGridLines = false;
                eMA.YAxis        = numericalAxis;
                eMA.Period       = 14;
                eMA.SeriesName   = "Series";
                eMA.XBindingPath = "XValue";
                eMA.Open         = "Open";
                eMA.Close        = "Close";
                eMA.High         = "High";
                eMA.Low          = "Low";
                chart.TechnicalIndicators.Add(eMA);
            }
            else if (selectedItem.Equals("Momentum Indicator"))
            {
                chart.TechnicalIndicators.RemoveAt(0);
                MomentumIndicator momentum      = new MomentumIndicator();
                NumericalAxis     numericalAxis = new NumericalAxis();
                numericalAxis.OpposedPosition    = true;
                numericalAxis.ShowMajorGridLines = false;
                momentum.YAxis        = numericalAxis;
                momentum.SeriesName   = "Series";
                momentum.XBindingPath = "XValue";
                momentum.Open         = "Open";
                momentum.Close        = "Close";
                momentum.High         = "High";
                momentum.Low          = "Low";
                momentum.Period       = 14;
                chart.TechnicalIndicators.Add(momentum);
            }
            else if (selectedItem.Equals("Simple Moving Average Indicator"))
            {
                chart.TechnicalIndicators.RemoveAt(0);
                SimpleMovingAverageIndicator sMA = new SimpleMovingAverageIndicator();
                sMA.SeriesName   = "Series";
                sMA.XBindingPath = "XValue";
                sMA.Open         = "Open";
                sMA.Close        = "Close";
                sMA.High         = "High";
                sMA.Low          = "Low";
                sMA.Period       = 14;
                chart.TechnicalIndicators.Add(sMA);
            }
            else if (selectedItem.Equals("RSI Indicator"))
            {
                chart.TechnicalIndicators.RemoveAt(0);
                RSIIndicator  rSI           = new RSIIndicator();
                NumericalAxis numericalAxis = new NumericalAxis();
                numericalAxis.OpposedPosition    = true;
                numericalAxis.ShowMajorGridLines = false;
                rSI.YAxis        = numericalAxis;
                rSI.Period       = 14;
                rSI.SeriesName   = "Series";
                rSI.XBindingPath = "XValue";
                rSI.Open         = "Open";
                rSI.Close        = "Close";
                rSI.High         = "High";
                rSI.Low          = "Low";
                chart.TechnicalIndicators.Add(rSI);
            }
            else if (selectedItem.Equals("Triangular Moving Average Indicator"))
            {
                chart.TechnicalIndicators.RemoveAt(0);
                TriangularMovingAverageIndicator tMA = new TriangularMovingAverageIndicator();
                NumericalAxis numericalAxis          = new NumericalAxis();
                numericalAxis.OpposedPosition    = true;
                numericalAxis.ShowMajorGridLines = false;
                tMA.YAxis        = numericalAxis;
                tMA.Period       = 14;
                tMA.SeriesName   = "Series";
                tMA.XBindingPath = "XValue";
                tMA.Open         = "Open";
                tMA.Close        = "Close";
                tMA.High         = "High";
                tMA.Low          = "Low";
                chart.TechnicalIndicators.Add(tMA);
            }
            else if (selectedItem.Equals("MACD Indicator"))
            {
                chart.TechnicalIndicators.RemoveAt(0);
                MACDIndicator mACD          = new MACDIndicator();
                NumericalAxis numericalAxis = new NumericalAxis();
                numericalAxis.OpposedPosition    = true;
                numericalAxis.ShowMajorGridLines = false;
                mACD.YAxis        = numericalAxis;
                mACD.SeriesName   = "Series";
                mACD.XBindingPath = "XValue";
                mACD.Open         = "Open";
                mACD.Close        = "Close";
                mACD.High         = "High";
                mACD.Low          = "Low";
                mACD.ShortPeriod  = 2;
                mACD.LongPeriod   = 10;
                mACD.Trigger      = 14;
                chart.TechnicalIndicators.Add(mACD);
            }
            else if (selectedItem.Equals("Stochastic Indicator"))
            {
                chart.TechnicalIndicators.RemoveAt(0);
                StochasticIndicator stochastic    = new StochasticIndicator();
                NumericalAxis       numericalAxis = new NumericalAxis();
                numericalAxis.OpposedPosition    = true;
                numericalAxis.ShowMajorGridLines = false;
                stochastic.YAxis        = numericalAxis;
                stochastic.SeriesName   = "Series";
                stochastic.XBindingPath = "XValue";
                stochastic.Open         = "Open";
                stochastic.Close        = "Close";
                stochastic.High         = "High";
                stochastic.Low          = "Low";
                stochastic.Period       = 14;
                stochastic.KPeriod      = 5;
                stochastic.DPeriod      = 6;
                chart.TechnicalIndicators.Add(stochastic);
            }
            else if (selectedItem.Equals("Bollinger Band Indicator"))
            {
                chart.TechnicalIndicators.RemoveAt(0);
                BollingerBandIndicator bB = new BollingerBandIndicator();
                bB.Period = 14;
                NumericalAxis numericalAxis = new NumericalAxis();
                numericalAxis.OpposedPosition    = true;
                numericalAxis.ShowMajorGridLines = false;
                //bB.YAxis = numericalAxis;
                bB.SeriesName   = "Series";
                bB.XBindingPath = "XValue";
                bB.Open         = "Open";
                bB.Close        = "Close";
                bB.High         = "High";
                bB.Low          = "Low";
                chart.TechnicalIndicators.Add(bB);
            }
        }
        /// <summary>
        /// Initialization method
        /// </summary>
        public override void OnInitialize()
        {
            log.Debug("DaenerysStrategy onInitialize()");

            // Adding an RSI indicator to strategy
            // (see http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:relative_strength_index_rsi)
            rsiIndicator = new RSIIndicator(Bars.Close, (int)this.GetInputParameter("RSI Period"), (int)this.GetInputParameter("RSI Sell signal trigger level"), (int)this.GetInputParameter("RSI Buy signal trigger level"));
            this.AddIndicator("RSI indicator", rsiIndicator);
        }
Esempio n. 6
0
        public static WalkerIndicator getRandomIndicator()
        {
            WalkerIndicator theIndicator = null;

            long timeframeOne   = z.Next(1, 2880) * 60 * 1000;
            long timeframeTwo   = z.Next(1, 2880) * 60 * 1000;
            long timeFrameThree = z.Next(1, 2880) * 60 * 1000;

            long timeFrameSmaller = z.Next(1, 2880) * 60 * 1000;

            switch (z.Next(0, 18)) //Todo: set max value for choosing the indicator
            {
            case 0:
                theIndicator = new BolingerBandsIndicator(timeframeOne, getRanDouble(1d, 5d));
                break;

            case 1:
                theIndicator = new MACDContinousIndicator(timeframeOne, timeframeTwo, timeFrameSmaller);
                break;

            case 2:
                theIndicator = new MACDIndicator(timeframeOne, timeframeTwo, timeFrameSmaller);
                break;

            case 3:
                theIndicator = new MovingAveragePriceSubtractionIndicator(timeframeOne);
                break;

            case 4:
                theIndicator = new MovingAverageSubtractionCrossoverIndicator(timeframeOne, timeframeTwo);
                break;

            case 5:
                theIndicator = new MovingAverageSubtractionIndicator(timeframeOne, timeframeTwo);
                break;

            case 6:
                theIndicator = new RangeIndicator(timeframeOne);
                break;

            case 7:
                theIndicator = new RSIBorderCrossoverIndicator(timeframeOne, getRanDouble(0.1, 0.4));
                break;

            case 8:
                theIndicator = new RSIBorderIndicator(timeframeOne, getRanDouble(0.1, 0.4));
                break;

            case 9:
                theIndicator = new RSIIndicator(timeframeOne);
                break;

            case 10:
                theIndicator = new RSIMACrossoverContinousIndicator(timeframeOne, timeFrameSmaller);
                break;

            case 11:
                theIndicator = new RSIMACrossoverIndicator(timeframeOne, timeFrameSmaller);
                break;

            case 12:
                theIndicator = new StandartDeviationIndicator(timeframeOne);
                break;

            case 13:
                theIndicator = new StochBorderCrossoverIndicator(timeframeOne, getRanDouble(0.1, 0.4));
                break;

            case 14:
                theIndicator = new StochBorderIndicator(timeframeOne, getRanDouble(0.1, 0.4));
                break;

            case 15:
                theIndicator = new StochIndicator(timeframeOne);
                break;

            case 16:
                theIndicator = new VolumeAtPriceIndicator(timeframeOne, getRanDouble(0.0003, 0.002), z.Next(1000 * 30, 1000 * 60 * 10));
                break;     //Not sure about stepsize todo

            case 17:
                theIndicator = new TimeOfDayIndicator();     //Only once?
                break;

            case 18:
                theIndicator = new TimeDayOfWeekIndicator();     //Todo: Only once?
                break;

            default:
                throw new Exception("Fired a unexpected random value");
            }

            return(theIndicator);
        }
        public static WalkerIndicator getIndicatorByString(string input)
        {
            string[] args;

            if (input.Contains("_") == false)
            {
                args = new string[] { input }
            }
            ;
            else
            {
                args = input.Split('_');
            }

            WalkerIndicator selected = null;

            if (args[0] == BolingerBandsIndicator.Name)
            {
                selected = new BolingerBandsIndicator(long.Parse(args[1]), double.Parse(args[2]));
            }

            if (args[0] == MACDContinousIndicator.Name)
            {
                selected = new MACDContinousIndicator(long.Parse(args[1]), long.Parse(args[2]), long.Parse(args[3]));
            }

            if (args[0] == MACDIndicator.Name)
            {
                selected = new MACDIndicator(long.Parse(args[1]), long.Parse(args[2]), long.Parse(args[3]));
            }

            if (args[0] == MovingAverageIndicator.Name)
            {
                selected = new MovingAverageIndicator(long.Parse(args[1]));
            }

            if (args[0] == MovingAveragePriceSubtractionIndicator.Name)
            {
                selected = new MovingAveragePriceSubtractionIndicator(long.Parse(args[1]));
            }

            if (args[0] == MovingAverageSubtractionIndicator.Name)
            {
                selected = new MovingAverageSubtractionIndicator(long.Parse(args[1]), long.Parse(args[2]));
            }

            if (args[0] == MovingAverageSubtractionCrossoverIndicator.Name)
            {
                selected = new MovingAverageSubtractionCrossoverIndicator(long.Parse(args[1]), long.Parse(args[2]));
            }

            if (args[0] == RangeIndicator.Name)
            {
                selected = new RangeIndicator(long.Parse(args[1]));
            }

            if (args[0] == RSIBorderCrossoverIndicator.Name)
            {
                selected = new RSIBorderCrossoverIndicator(long.Parse(args[1]), double.Parse(args[2]));
            }

            if (args[0] == RSIBorderIndicator.Name)
            {
                selected = new RSIBorderIndicator(long.Parse(args[1]), double.Parse(args[2]));
            }

            if (args[0] == RSIIndicator.Name)
            {
                selected = new RSIIndicator(long.Parse(args[1]));
            }

            if (args[0] == RSIMACrossoverContinousIndicator.Name)
            {
                selected = new RSIMACrossoverContinousIndicator(long.Parse(args[1]), long.Parse(args[2]));
            }

            if (args[0] == RSIMACrossoverIndicator.Name)
            {
                selected = new RSIMACrossoverIndicator(long.Parse(args[1]), long.Parse(args[2]));
            }

            if (args[0] == StandartDeviationIndicator.Name)
            {
                selected = new StandartDeviationIndicator(long.Parse(args[1]));
            }

            if (args[0] == StochBorderCrossoverIndicator.Name)
            {
                selected = new StochBorderCrossoverIndicator(long.Parse(args[1]), double.Parse(args[2]));
            }

            if (args[0] == StochBorderIndicator.Name)
            {
                selected = new StochBorderIndicator(long.Parse(args[1]), double.Parse(args[2]));
            }

            if (args[0] == StochIndicator.Name)
            {
                selected = new StochIndicator(long.Parse(args[1]));
            }

            if (args[0] == TestIndicator.Name)
            {
                selected = new TestIndicator();
            }

            if (args[0] == TimeDayOfWeekIndicator.Name)
            {
                selected = new TimeDayOfWeekIndicator();
            }

            if (args[0] == TimeOfDayIndicator.Name)
            {
                selected = new TimeOfDayIndicator();
            }

            if (args[0] == TimeOpeningHoursIndicator.Name)
            {
                selected = new TimeOpeningHoursIndicator();
            }

            if (args[0] == VolumeAtPriceIndicator.Name)
            {
                selected = new VolumeAtPriceIndicator(long.Parse(args[1]), double.Parse(args[2]), long.Parse(args[3]));
            }

            if (selected == null)
            {
                throw new Exception("Name not found: " + args[0]);
            }

            if (selected.getName() != input)
            {
                throw new Exception(input + " != " + selected.getName());
            }

            return(selected);
        }
Esempio n. 8
0
        public static void Main(string[] args)
        {
            /// <summary>
            /// Getting time series
            /// </summary>
            TimeSeries series = CsvTradesLoader.loadBitstampSeries();

            /// <summary>
            /// Creating indicators
            /// </summary>
            // Close price
            ClosePriceIndicator closePrice = new ClosePriceIndicator(series);
            // Typical price
            TypicalPriceIndicator typicalPrice = new TypicalPriceIndicator(series);
            // Price variation
            PriceVariationIndicator priceVariation = new PriceVariationIndicator(series);
            // Simple moving averages
            SMAIndicator shortSma = new SMAIndicator(closePrice, 8);
            SMAIndicator longSma  = new SMAIndicator(closePrice, 20);
            // Exponential moving averages
            EMAIndicator shortEma = new EMAIndicator(closePrice, 8);
            EMAIndicator longEma  = new EMAIndicator(closePrice, 20);
            // Percentage price oscillator
            PPOIndicator ppo = new PPOIndicator(closePrice, 12, 26);
            // Rate of change
            ROCIndicator roc = new ROCIndicator(closePrice, 100);
            // Relative strength index
            RSIIndicator rsi = new RSIIndicator(closePrice, 14);
            // Williams %R
            WilliamsRIndicator williamsR = new WilliamsRIndicator(series, 20);
            // Average true range
            AverageTrueRangeIndicator atr = new AverageTrueRangeIndicator(series, 20);
            // Standard deviation
            StandardDeviationIndicator sd = new StandardDeviationIndicator(closePrice, 14);

            /// <summary>
            /// Building header
            /// </summary>
            StringBuilder sb = new StringBuilder("timestamp,close,typical,variation,sma8,sma20,ema8,ema20,ppo,roc,rsi,williamsr,atr,sd\n");

            /// <summary>
            /// Adding indicators values
            /// </summary>
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int nbTicks = series.getTickCount();
            int nbTicks = series.TickCount;

            for (int i = 0; i < nbTicks; i++)
            {
                sb.Append(series.getTick(i).EndTime.Millis / 1000d).Append(',').Append(closePrice.getValue(i)).Append(',').Append(typicalPrice.getValue(i)).Append(',').Append(priceVariation.getValue(i)).Append(',').Append(shortSma.getValue(i)).Append(',').Append(longSma.getValue(i)).Append(',').Append(shortEma.getValue(i)).Append(',').Append(longEma.getValue(i)).Append(',').Append(ppo.getValue(i)).Append(',').Append(roc.getValue(i)).Append(',').Append(rsi.getValue(i)).Append(',').Append(williamsR.getValue(i)).Append(',').Append(atr.getValue(i)).Append(',').Append(sd.getValue(i)).Append('\n');
            }

            /// <summary>
            /// Writing CSV file
            /// </summary>
            System.IO.StreamWriter writer = null;
            try
            {
                writer = new System.IO.StreamWriter("indicators.csv");
                writer.Write(sb.ToString());
            } catch (IOException ioe)
            {
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                Logger.getLogger(typeof(IndicatorsToCsv).FullName).log(Level.SEVERE, "Unable to write CSV file", ioe);
            } finally
            {
                try
                {
                    if (writer != null)
                    {
                        writer.Close();
                    }
                } catch (IOException)
                {
                }
            }
        }