示例#1
0
 protected override void Initialize()
 {
     diff = CreateDataSeries();
     wma1 = Indicators.WeightedMovingAverage(MarketSeries.Close, (int)Period / 2);
     wma2 = Indicators.WeightedMovingAverage(MarketSeries.Close, Period);
     wma3 = Indicators.WeightedMovingAverage(diff, (int)Math.Sqrt(Period));
 }
示例#2
0
文件: HMA.cs 项目: Mikai47/cAlgoBot
 protected override void Initialize()
 {
     diff = CreateDataSeries();
     wma1 = Indicators.WeightedMovingAverage(MarketSeries.Close, (int)Period / 2);
     wma2 = Indicators.WeightedMovingAverage(MarketSeries.Close, Period);
     wma3 = Indicators.WeightedMovingAverage(diff, (int)Math.Sqrt(Period));
 }
示例#3
0
 protected override void Initialize()
 {
     macd        = Indicators.MacdCrossOver(MarketSeries.Close, 26, 12, 9);
     wma300      = Indicators.WeightedMovingAverage(MarketSeries.Close, 300);
     wma150      = Indicators.WeightedMovingAverage(MarketSeries.Close, 150);
     arrowOffset = Symbol.PipSize * 15;
 }
示例#4
0
        public void Example5()
        {
            var stats = new WeightedMovingAverage(new double[] { 2, 2, 5, 7 });

            Assert.Equal(4, stats.Count);
            Assert.Equal(4.9, stats.Average, 15);
        }
示例#5
0
        /// <summary>
        /// Add a result to the weighted rolling average history.
        /// </summary>
        /// <param name="ipAndPort">IP:Port string to identify where the results go</param>
        /// <param name="result">The result to add to the history. This result becomes the current result.</param>
        public void AddResult(string ipAndPort, QosResult result)
        {
            if (result.PacketLoss + Mathf.Epsilon < 0.0f || result.PacketLoss - Mathf.Epsilon > 1.0f)
            {
                throw new ArgumentOutOfRangeException(nameof(result), "PacketLoss must be in the range [0.0..1.0]");
            }

            m_ResultsLock.EnterWriteLock();
            try
            {
                WeightedMovingAverage wma = null;
                if (!m_Results.TryGetValue(ipAndPort, out wma))
                {
                    // Tracking new server
                    wma = new WeightedMovingAverage(m_NumResults, m_Weight);
                }

                wma.AddResult(new QosStatsResult((int)result.AverageLatencyMs, result.PacketLoss));
                m_Results[ipAndPort] = wma;
            }
            finally
            {
                m_ResultsLock.ExitWriteLock();
            }
        }
示例#6
0
        public void NoValue()
        {
            var stats = new WeightedMovingAverage();

            Assert.Equal(0, stats.Count);
            Assert.Equal(double.NaN, stats.Average);
        }
示例#7
0
        public void Example6()
        {
            var stats = new WeightedMovingAverage();

            stats.AddRange(new double[] { 2, 4, 4, 4, 5, 5, 7, 9 });
            Assert.Equal(8, stats.Count);
            Assert.Equal(5.944444444444445, stats.Average, 15);
        }
示例#8
0
        public void Example9()
        {
            var stats = new WeightedMovingAverage();

            stats.AddRange(new double[] { -5, -3, -1, 1, 3 });
            Assert.Equal(5, stats.Count);
            Assert.Equal(0.333333333333333, stats.Average, 15);
        }
示例#9
0
        public void Example8()
        {
            var stats = new WeightedMovingAverage();

            stats.AddRange(new double[] { 51.3, 55.6, 49.9, 52.0 });
            Assert.Equal(4, stats.Count);
            Assert.Equal(52.02, stats.Average, 15);
        }
示例#10
0
        public void Example7()
        {
            var stats = new WeightedMovingAverage();

            stats.AddRange(new double[] { 9, 2, 5, 4, 12, 7, 8, 11, 9, 3, 7, 4, 12, 5, 4, 10, 9, 6, 9, 4 });
            Assert.Equal(20, stats.Count);
            Assert.Equal(6.963636363636364, stats.Average, 15);
        }
示例#11
0
 protected override void Initialize()
 {
     closePrice = CreateDataSeries();
     macd       = CreateDataSeries();
     emaSlow    = Indicators.WeightedMovingAverage(closePrice, periodSlow);
     emaFast    = Indicators.WeightedMovingAverage(closePrice, periodFast);
     emaSignal  = Indicators.WeightedMovingAverage(macd, periodSignal);
 }
示例#12
0
        public void OneValue()
        {
            var stats = new WeightedMovingAverage();

            stats.Add(1);
            Assert.Equal(1, stats.Count);
            Assert.Equal(1, stats.Average);
        }
示例#13
0
        public void Example20()
        {
            var stats = new WeightedMovingAverage(3);

            stats.AddRange(new double[] { -1, 0, 1 });
            Assert.Equal(3, stats.Count);
            Assert.Equal(0.333333333333333, stats.Average, 15);
        }
示例#14
0
 public void NoCountOutOfRange()
 {
     Assert.Throws <ArgumentOutOfRangeException>(delegate {
         var stats = new WeightedMovingAverage(0);
     });
     Assert.Throws <ArgumentOutOfRangeException>(delegate {
         var stats = new WeightedMovingAverage(0, new double[] { 0 });
     });
 }
示例#15
0
 protected override void OnStart()
 {
     startingBalance = Account.Balance;
     startDate       = this.Time;
     positionSize    = (int)Symbol.NormalizeVolume(Account.Balance * (positionSizePercent / 100), RoundingMode.ToNearest);
     // Put your initialization logic here
     wma       = Indicators.WeightedMovingAverage(MarketSeries.Close, wmaNum);
     tradeTime = Server.Time;
 }
示例#16
0
        protected override void Initialize()
        {
            //wma(2*wma(close,period/2)-wma(close,period), sqrt(Period))
            _iSeries = CreateDataSeries();

            _wma = Indicators.WeightedMovingAverage(Source, Period / 2);
            _wma2 = Indicators.WeightedMovingAverage(Source, Period);
            _wma3 = Indicators.WeightedMovingAverage(_iSeries, (int)Math.Sqrt(Period));
        }
        protected override void Initialize()
        {
            //wma(2*wma(close,period/2)-wma(close,period), sqrt(Period))
            _iSeries = CreateDataSeries();

            _wma  = Indicators.WeightedMovingAverage(Source, Period / 2);
            _wma2 = Indicators.WeightedMovingAverage(Source, Period);
            _wma3 = Indicators.WeightedMovingAverage(_iSeries, (int)Math.Sqrt(Period));
        }
示例#18
0
        public void Calculate_10PointsAllOnesWithSameWeights_1()
        {
            var calc    = new WeightedMovingAverage();
            var points  = Enumerable.Repeat(1d, 10).ToList();
            var weights = Enumerable.Repeat(0.1, 10).ToList();

            var result = calc.Calculate(points, weights);

            Assert.AreEqual(1, result);
        }
示例#19
0
 protected override void OnStart()
 {
     // Put your initialization logic here
     wma          = Indicators.WeightedMovingAverage(MarketSeries.Close, wmaNum);
     positionSize = (int)Symbol.NormalizeVolume(positionSize, RoundingMode.ToNearest);
     startTime    = this.Time;
     Print(startTime.Year);
     startingBalance = Account.Balance;
     checkTime       = startTime.AddMonths(1);
 }
示例#20
0
 //public int multiWait = 0;
 protected override void OnStart()
 {
     OGpositionSize = (int)(Account.Balance * (positionSizePercent / 100));
     positionSize   = OGpositionSize;
     pipsProfit     = OGpipsProfit;
     longWMA        = Indicators.WeightedMovingAverage(MarketSeries.Close, longWMAnum);
     shortWMA       = Indicators.WeightedMovingAverage(MarketSeries.Close, shortWMAnum);
     startBalance   = Account.Balance;
     maxLossPercent = maxLossPercentOG;
 }
示例#21
0
        public void Example4()
        {
            var stats = new WeightedMovingAverage();

            stats.Add(6);
            stats.Add(2);
            stats.Add(3);
            stats.Add(1);
            Assert.Equal(4, stats.Count);
            Assert.Equal(2.3, stats.Average, 15);
        }
示例#22
0
        public void Example3()
        {
            var stats = new WeightedMovingAverage();

            stats.Add(1000000004);
            stats.Add(1000000007);
            stats.Add(1000000013);
            stats.Add(1000000016);
            Assert.Equal(4, stats.Count);
            Assert.Equal(1000000012.1000001, stats.Average, 15);
        }
示例#23
0
        public void Example1()
        {
            var stats = new WeightedMovingAverage();

            stats.Add(4);
            stats.Add(7);
            stats.Add(13);
            stats.Add(16);
            Assert.Equal(4, stats.Count);
            Assert.Equal(12.1, stats.Average, 15);
        }
示例#24
0
        protected override void OnStart()
        {
            bars = Source.Count;
            macd = Indicators.GetIndicator <ZeroLagMacd>(26, 12, 9);

            mm8   = Indicators.ExponentialMovingAverage(Source, 8);
            mm50  = Indicators.WeightedMovingAverage(Source, 50);
            mm150 = Indicators.WeightedMovingAverage(Source, 150);
            mm300 = Indicators.WeightedMovingAverage(Source, 300);

            Positions.Closed += PositionsOnClosed;
        }
示例#25
0
        protected override void Initialize()
        {
            longWMA       = Indicators.WeightedMovingAverage(MarketSeries.Close, longWMAnum);
            shortWMA      = Indicators.WeightedMovingAverage(MarketSeries.Close, shortWMAnum);
            arrayIndex    = 0;
            success       = new bool[MarketSeries.Close.Count];
            previousBreak = int.MaxValue;

            for (int i = 1; i < MarketSeries.Close.Count; i++)
            {
                if (shortWMA.Result[i] > longWMA.Result[i] && shortWMA.Result[i - 1] < longWMA.Result[i - 1])
                {
                    for (int j = 0; j + i < MarketSeries.Close.Count; j++)
                    {
                        if ((MarketSeries.Close[i + j] - MarketSeries.Open[i]) / Symbol.PipSize >= pipTarget)
                        {
                            success[arrayIndex] = true;
                            arrayIndex++;
                            Print("Top cross at " + MarketSeries.OpenTime[i] + " Successful at " + MarketSeries.OpenTime[i + j]);
                            break;
                        }
                        else if (shortWMA.Result[i + j] < longWMA.Result[i + j])
                        {
                            success[arrayIndex] = false;
                            arrayIndex++;
                            Print("Top cross at " + MarketSeries.OpenTime[i] + " Unsuccessful at " + MarketSeries.OpenTime[i + j]);
                            break;
                        }
                    }
                }
                if (shortWMA.Result[i] < longWMA.Result[i] && shortWMA.Result[i - 1] > longWMA.Result[i - 1])
                {
                    for (int j = 0; j + i < MarketSeries.Close.Count; j++)
                    {
                        if ((MarketSeries.Open[i] - MarketSeries.Close[i + j]) / Symbol.PipSize >= pipTarget)
                        {
                            Print("Bottom cross at " + MarketSeries.OpenTime[i] + " Successful at " + MarketSeries.OpenTime[i + j]);
                            success[arrayIndex] = true;
                            arrayIndex++;
                            break;
                        }
                        else if (shortWMA.Result[i + j] > longWMA.Result[i + j])
                        {
                            Print("Bottom cross at " + MarketSeries.OpenTime[i] + " Unsuccessful at " + MarketSeries.OpenTime[i + j]);
                            success[arrayIndex] = false;
                            arrayIndex++;
                            break;
                        }
                    }
                }
            }
        }
示例#26
0
 public void NoNullCollection()
 {
     Assert.Throws <ArgumentNullException>(delegate {
         var stats = new WeightedMovingAverage(null);
     });
     Assert.Throws <ArgumentNullException>(delegate {
         var stats = new WeightedMovingAverage(10, null);
     });
     Assert.Throws <ArgumentNullException>(delegate {
         var stats = new WeightedMovingAverage();
         stats.AddRange(null);
     });
 }
示例#27
0
        public void Calculate_PointsIsNull_ArgumentExceptionThrown()
        {
            var calc = new WeightedMovingAverage();

            try
            {
                calc.Calculate(null, null);
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(ArgumentException));
            }
        }
示例#28
0
        protected override void Initialize()
        {
            var index = MarketSeries.Close.Count - 1;

            diff = CreateDataSeries();
            wma1 = Indicators.WeightedMovingAverage(MarketSeries.Close, (int)Period / 2);
            wma2 = Indicators.WeightedMovingAverage(MarketSeries.Close, Period);
            wma3 = Indicators.WeightedMovingAverage(diff, (int)Math.Sqrt(Period));

            var1 = 2 * wma1.Result[index];
            var2 = wma2.Result[index];

            diff[index] = var1 - var2;
        }
示例#29
0
        public void NoInfinity()
        {
            var stats = new WeightedMovingAverage();

            Assert.Throws <ArgumentOutOfRangeException>(delegate {
                stats.Add(double.NegativeInfinity);
            });
            Assert.Throws <ArgumentOutOfRangeException>(delegate {
                stats.Add(double.PositiveInfinity);
            });
            Assert.Throws <ArgumentOutOfRangeException>(delegate {
                stats.Add(double.NaN);
            });
        }
示例#30
0
        private bool IsTrendUp(MarketSeries series, WeightedMovingAverage wma)
        {
            var close = series.Close.LastValue;
            var value = wma.Result.LastValue;

            if (value < close)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#31
0
 protected override void OnStart()
 {
     Positions.Closed += OnPositionClosed;
     Positions.Opened += OnPositionOpened;
     startingBalance   = Account.Balance;
     streakTrades      = 0;
     startTime         = Server.Time;
     avgTimes          = new List <int>();
     avgTrades         = new List <int>();
     longWMA           = Indicators.WeightedMovingAverage(MarketData.GetSeries(WMAtimeframe).Close, longWMANum);
     shortWMA          = Indicators.WeightedMovingAverage(MarketData.GetSeries(WMAtimeframe).Close, shortWMANum);
     channelWMA        = Indicators.WeightedMovingAverage(MarketSeries.Close, maPeriod);
     brokenTop         = false;
     brokenBottom      = false;
 }
示例#32
0
        protected override void Initialize()
        {
            unsmBuffer = new double[1];
            unsmoothed = CreateDataSeries();
            _wma = Indicators.WeightedMovingAverage(unsmoothed, SmoothingPeriod);
            _ema = Indicators.ExponentialMovingAverage(_wma.Result, TriggerPeriod);

            ol = new double[4];
            pol = new double[4];
            hl = new double[4];
            phl = new double[4];
            ll = new double[4];
            pll = new double[4];
            cl = new double[4];
            pcl = new double[4];
        }
示例#33
0
        protected override void Initialize()
        {
            unsmBuffer = new double[1];
            unsmoothed = CreateDataSeries();
            _wma       = Indicators.WeightedMovingAverage(unsmoothed, SmoothingPeriod);
            _ema       = Indicators.ExponentialMovingAverage(_wma.Result, TriggerPeriod);

            ol  = new double[4];
            pol = new double[4];
            hl  = new double[4];
            phl = new double[4];
            ll  = new double[4];
            pll = new double[4];
            cl  = new double[4];
            pcl = new double[4];
        }
示例#34
0
 protected override void Initialize()
 {
     _weightedMovingAverage = Indicators.WeightedMovingAverage(MarketSeries.Close, 21);
     _averageTrueRange = Indicators.GetIndicator<AverageTrueRange>(100);
     _relativeStrengthIndex = Indicators.RelativeStrengthIndex(TMA, rsiPeriod);
 }
示例#35
0
 protected override void Initialize()
 {
     _weightedMovingAverage = Indicators.WeightedMovingAverage(MarketSeries.Close, 21);
     _averageTrueRange = Indicators.GetIndicator<AverageTrueRange>(100);
     _simpleMovingAverage = Indicators.SimpleMovingAverage(TMA, smaPeriod);
 }