Exemple #1
0
        protected virtual void ProcessError(double error)
        {
            double filteredError;

            if (Options.ErrorFilterSize > 0)
            {
                if (_mav == null)
                {
                    _mav = new MAV(Options.ErrorFilterSize);
                }
                else if (_mav.Order != Options.ErrorFilterSize)
                {
                    _mav.Order = Options.ErrorFilterSize;
                }

                filteredError = _mav.Filter(error);
            }
            else
            {
                if (_mav != null)
                {
                    _mav = null;
                }

                filteredError = error;
            }

            Session.AddError(filteredError, error);

            _dErr      = filteredError - _lastError;
            _lastError = filteredError;
        }
Exemple #2
0
        protected override void InitTraining()
        {
            base.InitTraining();

            if (TrainingSet == null)
            {
                throw new InvalidOperationException("Training set is not set!");
            }

            if (Options.RunTests?.IsEnabled == true && TestSet == null)
            {
                throw new InvalidOperationException("Tests are enabled, but test set is not set!");
            }

            _mav       = Options.ErrorFilterSize > 0 ? new MAV(Options.ErrorFilterSize) : null;
            _lastError = 0;

            Session.IterationsPerEpoch = TrainingSet.SampleCount / Options.SequenceLength;

            Options.ProgressWriter?.Message($"Sequence length: {Options.SequenceLength}");
            Options.ProgressWriter?.Message($"Using network with total param count {_network.TotalParamCount}");
        }
        /// <summary>
        /// Double MA
        /// </summary>
        /// <returns></returns>
        public Indicator.DoubleMA DoubleMA(Data.IDataSeries input, double angle, int arrowDisplacement, Color barColorDown, Color barColorNeutral, Color barColorUp, int mA1Period, MAV.MAType mA1Type, int mA2Period, MAV.MAType mA2Type, bool paintBar, bool showArrows, bool soundOn, string wavLongFileName, string wavShortFileName)
        {
            if (InInitialize && input == null)
                throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");

            return _indicator.DoubleMA(input, angle, arrowDisplacement, barColorDown, barColorNeutral, barColorUp, mA1Period, mA1Type, mA2Period, mA2Type, paintBar, showArrows, soundOn, wavLongFileName, wavShortFileName);
        }
 public Indicator.DoubleMA DoubleMA(double angle, int arrowDisplacement, Color barColorDown, Color barColorNeutral, Color barColorUp, int mA1Period, MAV.MAType mA1Type, int mA2Period, MAV.MAType mA2Type, bool paintBar, bool showArrows, bool soundOn, string wavLongFileName, string wavShortFileName)
 {
     return _indicator.DoubleMA(Input, angle, arrowDisplacement, barColorDown, barColorNeutral, barColorUp, mA1Period, mA1Type, mA2Period, mA2Type, paintBar, showArrows, soundOn, wavLongFileName, wavShortFileName);
 }
        /// <summary>
        /// Double MA
        /// </summary>
        /// <returns></returns>
        public DoubleMA DoubleMA(Data.IDataSeries input, double angle, int arrowDisplacement, Color barColorDown, Color barColorNeutral, Color barColorUp, int mA1Period, MAV.MAType mA1Type, int mA2Period, MAV.MAType mA2Type, bool paintBar, bool showArrows, bool soundOn, string wavLongFileName, string wavShortFileName)
        {
            if (cacheDoubleMA != null)
                for (int idx = 0; idx < cacheDoubleMA.Length; idx++)
                    if (Math.Abs(cacheDoubleMA[idx].Angle - angle) <= double.Epsilon && cacheDoubleMA[idx].ArrowDisplacement == arrowDisplacement && cacheDoubleMA[idx].BarColorDown == barColorDown && cacheDoubleMA[idx].BarColorNeutral == barColorNeutral && cacheDoubleMA[idx].BarColorUp == barColorUp && cacheDoubleMA[idx].MA1Period == mA1Period && cacheDoubleMA[idx].MA1Type == mA1Type && cacheDoubleMA[idx].MA2Period == mA2Period && cacheDoubleMA[idx].MA2Type == mA2Type && cacheDoubleMA[idx].PaintBar == paintBar && cacheDoubleMA[idx].ShowArrows == showArrows && cacheDoubleMA[idx].SoundOn == soundOn && cacheDoubleMA[idx].WavLongFileName == wavLongFileName && cacheDoubleMA[idx].WavShortFileName == wavShortFileName && cacheDoubleMA[idx].EqualsInput(input))
                        return cacheDoubleMA[idx];

            lock (checkDoubleMA)
            {
                checkDoubleMA.Angle = angle;
                angle = checkDoubleMA.Angle;
                checkDoubleMA.ArrowDisplacement = arrowDisplacement;
                arrowDisplacement = checkDoubleMA.ArrowDisplacement;
                checkDoubleMA.BarColorDown = barColorDown;
                barColorDown = checkDoubleMA.BarColorDown;
                checkDoubleMA.BarColorNeutral = barColorNeutral;
                barColorNeutral = checkDoubleMA.BarColorNeutral;
                checkDoubleMA.BarColorUp = barColorUp;
                barColorUp = checkDoubleMA.BarColorUp;
                checkDoubleMA.MA1Period = mA1Period;
                mA1Period = checkDoubleMA.MA1Period;
                checkDoubleMA.MA1Type = mA1Type;
                mA1Type = checkDoubleMA.MA1Type;
                checkDoubleMA.MA2Period = mA2Period;
                mA2Period = checkDoubleMA.MA2Period;
                checkDoubleMA.MA2Type = mA2Type;
                mA2Type = checkDoubleMA.MA2Type;
                checkDoubleMA.PaintBar = paintBar;
                paintBar = checkDoubleMA.PaintBar;
                checkDoubleMA.ShowArrows = showArrows;
                showArrows = checkDoubleMA.ShowArrows;
                checkDoubleMA.SoundOn = soundOn;
                soundOn = checkDoubleMA.SoundOn;
                checkDoubleMA.WavLongFileName = wavLongFileName;
                wavLongFileName = checkDoubleMA.WavLongFileName;
                checkDoubleMA.WavShortFileName = wavShortFileName;
                wavShortFileName = checkDoubleMA.WavShortFileName;

                if (cacheDoubleMA != null)
                    for (int idx = 0; idx < cacheDoubleMA.Length; idx++)
                        if (Math.Abs(cacheDoubleMA[idx].Angle - angle) <= double.Epsilon && cacheDoubleMA[idx].ArrowDisplacement == arrowDisplacement && cacheDoubleMA[idx].BarColorDown == barColorDown && cacheDoubleMA[idx].BarColorNeutral == barColorNeutral && cacheDoubleMA[idx].BarColorUp == barColorUp && cacheDoubleMA[idx].MA1Period == mA1Period && cacheDoubleMA[idx].MA1Type == mA1Type && cacheDoubleMA[idx].MA2Period == mA2Period && cacheDoubleMA[idx].MA2Type == mA2Type && cacheDoubleMA[idx].PaintBar == paintBar && cacheDoubleMA[idx].ShowArrows == showArrows && cacheDoubleMA[idx].SoundOn == soundOn && cacheDoubleMA[idx].WavLongFileName == wavLongFileName && cacheDoubleMA[idx].WavShortFileName == wavShortFileName && cacheDoubleMA[idx].EqualsInput(input))
                            return cacheDoubleMA[idx];

                DoubleMA indicator = new DoubleMA();
                indicator.BarsRequired = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
            #if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack = MaximumBarsLookBack;
            #endif
                indicator.Input = input;
                indicator.Angle = angle;
                indicator.ArrowDisplacement = arrowDisplacement;
                indicator.BarColorDown = barColorDown;
                indicator.BarColorNeutral = barColorNeutral;
                indicator.BarColorUp = barColorUp;
                indicator.MA1Period = mA1Period;
                indicator.MA1Type = mA1Type;
                indicator.MA2Period = mA2Period;
                indicator.MA2Type = mA2Type;
                indicator.PaintBar = paintBar;
                indicator.ShowArrows = showArrows;
                indicator.SoundOn = soundOn;
                indicator.WavLongFileName = wavLongFileName;
                indicator.WavShortFileName = wavShortFileName;
                Indicators.Add(indicator);
                indicator.SetUp();

                DoubleMA[] tmp = new DoubleMA[cacheDoubleMA == null ? 1 : cacheDoubleMA.Length + 1];
                if (cacheDoubleMA != null)
                    cacheDoubleMA.CopyTo(tmp, 0);
                tmp[tmp.Length - 1] = indicator;
                cacheDoubleMA = tmp;
                return indicator;
            }
        }
Exemple #6
0
        /// <summary>
        /// Variable moving average
        /// </summary>
        /// <returns></returns>
        public MAV MAV(Data.IDataSeries input, int mAPeriod, int typeInt)
        {
            if (cacheMAV != null)
                for (int idx = 0; idx < cacheMAV.Length; idx++)
                    if (cacheMAV[idx].MAPeriod == mAPeriod && cacheMAV[idx].TypeInt == typeInt && cacheMAV[idx].EqualsInput(input))
                        return cacheMAV[idx];

            lock (checkMAV)
            {
                checkMAV.MAPeriod = mAPeriod;
                mAPeriod = checkMAV.MAPeriod;
                checkMAV.TypeInt = typeInt;
                typeInt = checkMAV.TypeInt;

                if (cacheMAV != null)
                    for (int idx = 0; idx < cacheMAV.Length; idx++)
                        if (cacheMAV[idx].MAPeriod == mAPeriod && cacheMAV[idx].TypeInt == typeInt && cacheMAV[idx].EqualsInput(input))
                            return cacheMAV[idx];

                MAV indicator = new MAV();
                indicator.BarsRequired = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
            #if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack = MaximumBarsLookBack;
            #endif
                indicator.Input = input;
                indicator.MAPeriod = mAPeriod;
                indicator.TypeInt = typeInt;
                Indicators.Add(indicator);
                indicator.SetUp();

                MAV[] tmp = new MAV[cacheMAV == null ? 1 : cacheMAV.Length + 1];
                if (cacheMAV != null)
                    cacheMAV.CopyTo(tmp, 0);
                tmp[tmp.Length - 1] = indicator;
                cacheMAV = tmp;
                return indicator;
            }
        }