private bool EvaluteWave(List <Wave> Waves, int WaveIndexToEvalute, ElliottWave ElliotWaveToUse)
        {
            bool isElliotWaveDef;

            if (!ElliotWaveToUse.Momentum.Equals(Waves[WaveIndexToEvalute].Momentum))
            {
                return(false);
            }
            if (ElliotWaveToUse.RatioToWave != null && ElliotWaveToUse.RatioToWave.Count() > 0)
            {
                bool bRatioPassed = false;
                foreach (Tuple <int, double> WaveDef in ElliotWaveToUse.RatioToWave)
                {
                    if (WaveIndexToEvalute - ElliotWaveToUse.WaveNumber - WaveDef.Item1 < 0)
                    {
                        return(false);
                    }
                    Wave ToCompare = Waves[WaveIndexToEvalute - ElliotWaveToUse.WaveNumber - WaveDef.Item1];
                    if (IsWaveElliot(ToCompare.Length, Waves[WaveIndexToEvalute].Length, new double[] { WaveDef.Item2 }))
                    {
                        bRatioPassed = true;
                        break;
                    }
                }
                isElliotWaveDef = bRatioPassed;
            }
            else
            {
                isElliotWaveDef = true;
            }
            return(isElliotWaveDef);
        }
示例#2
0
        private TradingRecommendation GetTradingRecommendationFromWaves(List <ConfirmedElliottWave> ConfirmedWaves, DateTime Start, DateTime End)
        {
            //only calc on 4 and up
            int MaxConfirmedWave = ConfirmedWaves.Max(c => c.WaveNumber);
            //titta på senaste index som har confirmed wave > 3
            int MaxIndex = ConfirmedWaves.Where(cf => cf.WaveNumber > 3).Max(c => c.Wave.SourceIndex);

            if (Start.AddDays((int)(MaxIndex / 4)).Date < DateTime.Now.Date.AddDays(-2)) //just to test...
            {
                return(new TradingRecommendation());
            }

            int WaveNumber = ConfirmedWaves.Where(cf => cf.Wave.SourceIndex.Equals(MaxIndex)).First().WaveNumber;

            if (MaxConfirmedWave > WaveNumber)
            {
                MaxConfirmedWave = WaveNumber;
            }

            if (MaxConfirmedWave < 4 || MaxConfirmedWave.Equals(m_oED.ElliotWaveDefinitions.Select(e => e.WaveNumber).Max()))
            {
                ConfirmedElliottWave MaxConfirmedWaveObject = ConfirmedWaves.Where(f => f.Wave.SourceIndex.Equals(
                                                                                       ConfirmedWaves.Where(cw => cw.WaveNumber.Equals(MaxConfirmedWave)).Select(e => e.Wave.SourceIndex).Max()
                                                                                       )).First();
                double x = MaxConfirmedWaveObject.Wave.SourceIndex / 4;
                //DateTime ActionDateToTrade = Start.AddDays((int)x);
                //Last wave for buy!
                return(new TradingRecommendation(
                           Instrument,
                           ImperaturGlobal.GetMoney(Convert.ToDecimal(MaxConfirmedWaveObject.Wave.End), Instrument.CurrencyCode),
                           ImperaturGlobal.GetMoney(0, Instrument.CurrencyCode),
                           Start.AddDays((int)x),
                           Start.AddDays((int)x),
                           TradingForecastMethod.Elliott
                           ));
            }



            ElliottWave oE = m_oED.ElliotWaveDefinitions.Where(ed => ed.WaveNumber.Equals(MaxConfirmedWave + 1)).First();

            List <Wave> ToCompare = new List <Wave>();

            foreach (var oCW in ConfirmedWaves.Where(c => c.WaveNumber.Equals(MaxConfirmedWave)))
            {
                foreach (var t in oE.RatioToWave)
                {
                    ToCompare.AddRange(ConfirmedWaves.Where(c => c.WaveNumber.Equals(t.Item1) && m_oED.IsWaveElliot(Convert.ToDouble(c.Wave.Length), Convert.ToDouble(oCW.Wave.Length), new double[] { t.Item2 })).Select(g => g.Wave).ToList());
                }
            }

            //loop through the max waves detected(ToCompare) and get the new point according to oE
            //just to be on the safe side, pick the smallest value, largets value if we are excepting a raise
            double PredictedLenght = 0;

            if (oE.Momentum.Equals(Momentum.Negative))
            {
                PredictedLenght = ToCompare.Select(s => s.Length * oE.RatioToWave.Select(t => t.Item2).Min()).Min();
            }
            else
            {
                PredictedLenght = ToCompare.Select(s => s.Length * oE.RatioToWave.Select(t => t.Item2).Min()).Max();
            }

            //nu måste vi interpola vilket värde som det skulle kunna vara, tror att vi kan räkna med samma lutning som den vi jämför med.
            //räkna ut slope baserat på alla värden i tocompare
            // double SlopeAvg = ToCompare.Select(x => Fit.Line(Enumerable.Range(0, (int)x.Length - 1).Select(y=>Convert.ToDouble(y)).ToArray(), new double[] { x.Start, x.End }).Item2).Average();
            double SlopeAvg = ToCompare.Select(x => Fit.Line(new double[] { 0, 1 }, new double[] { x.Start, x.End }).Item2 / x.Length).Average();

            //every day consists of four values (open low high close)
            //List<double> oPriceData = GetRangeOfDataAsDoubleIncludingLowHigh(Start, End);
            double   XWaveIndex        = (ToCompare.Select(x => x.SourceIndex).Max() + PredictedLenght) / 4;
            DateTime ActionDateToTrade = Start.AddDays((int)XWaveIndex);

            return(new TradingRecommendation(Instrument,
                                             ImperaturGlobal.GetMoney(
                                                 oE.Momentum.Equals(Momentum.Negative) ? Convert.ToDecimal(ConfirmedWaves.Where(c => c.WaveNumber.Equals(MaxConfirmedWave)).Last().Wave.End + (PredictedLenght * SlopeAvg)) : 0, Instrument.CurrencyCode),
                                             ImperaturGlobal.GetMoney(
                                                 oE.Momentum.Equals(Momentum.Positive) ? Convert.ToDecimal(ConfirmedWaves.Where(c => c.WaveNumber.Equals(MaxConfirmedWave)).Last().Wave.End + (PredictedLenght * SlopeAvg)) : 0, Instrument.CurrencyCode),
                                             ActionDateToTrade,
                                             ActionDateToTrade,
                                             TradingForecastMethod.Elliott
                                             ));
        }