public override double Calculate(IList <History> history)
        {
            double sumPlus = 0.0;

            PlusDX pdx = new PlusDX();

            pdx.Calculate(history);

            PastValues.Add(0.0);

            // Get first
            for (int i = 1; i <= Period; i++)
            {
                PastValues.Add(pdx.PastValues[i]);
                sumPlus += pdx.PastValues[i];
            }

            // First smoothdx values
            PastValues[Period] = (sumPlus / (double)Period);

            for (int h = Period + 1; h < history.Count; h++)
            {
                PastValues.Add(((PastValues[PastValues.Count - 1] * (Period - 1)) +
                                (pdx.PastValues[h])) / (double)Period);
            }

            Value = PastValues[PastValues.Count - 1];

            return(Value);
        }
        public override double Calculate(IList <History> history)
        {
            double sum = 0.0;

            TrueRange tr = new TrueRange();

            tr.Calculate(history);

            PastValues.Add(0.0);

            // Get first atr
            for (int i = 1; i <= Period; i++)
            {
                PastValues.Add(0.0);
                sum += tr.PastValues[i];
            }

            // First ATR value
            PastValues[Period] = (sum / (double)Period);

            for (int h = Period + 1; h < history.Count; h++)
            {
                PastValues.Add(((PastValues[PastValues.Count - 1] * (Period - 1)) +
                                (tr.PastValues[h])) / (double)Period);
            }

            Value = PastValues[PastValues.Count - 1];

            return(Value);
        }
Exemple #3
0
        public override double Calculate(IList <History> history)
        {
            double hiDiff;
            double loDiff;

            //AverageTrueRange atr = new AverageTrueRange(14);
            //atr.Calculate(history);

            // First dxs are blank. Might have to set to NAN
            PastValues.Add(0.0);

            // Get [period] trs from beginning of history (250 records back)
            for (int i = 1; i < history.Count; i++)
            {
                hiDiff = (double)(history[i].HighPrice - history[i - 1].HighPrice);
                loDiff = (double)(history[i - 1].LowPrice - history[i].LowPrice);

                if ((hiDiff < 0.0 && loDiff < 0.0) || (hiDiff == loDiff))
                {
                    PastValues.Add(0.0);
                }
                else if (hiDiff > loDiff)
                {
                    PastValues.Add(hiDiff);
                }
                else if (hiDiff < loDiff)
                {
                    PastValues.Add(0.0);
                }
            }

            Value = PastValues[PastValues.Count - 1];

            return(Value);
        }
Exemple #4
0
        public override double Calculate(IList <History> history)
        {
            double tr1;
            double tr2;
            double tr3;

            PastValues.Add(0.0);

            // Get [period] trs from beginning of history (250 records back)
            for (int i = 1; i < history.Count; i++)
            {
                tr1 = (double)(history[i].HighPrice - history[i].LowPrice);
                tr2 = (double)(Math.Abs(history[i].HighPrice - history[i - 1].ClosePrice));
                tr3 = (double)(Math.Abs(history[i].LowPrice - history[i - 1].ClosePrice));

                PastValues.Add(Math.Max(tr1, Math.Max(tr2, tr3)));
            }

            Value = PastValues[PastValues.Count - 1];

            return(Value);
        }
Exemple #5
0
        public override double Calculate(IList <History> history)
        {
            PlusDMI  pdmi = new PlusDMI(14);
            MinusDMI mdmi = new MinusDMI(14);

            pdmi.Calculate(history);
            mdmi.Calculate(history);

            for (int i = 0; i < Period; i++)
            {
                PastValues.Add(0.0);
            }

            for (int h = Period; h < history.Count; h++)
            {
                PastValues.Add((Math.Abs(pdmi.PastValues[h] - mdmi.PastValues[h]) /
                                (pdmi.PastValues[h] + mdmi.PastValues[h])) *
                               100);
            }

            Value = PastValues[PastValues.Count - 1];

            return(Value);
        }
Exemple #6
0
        public override double Calculate(IList <History> history)
        {
            MinusSmoothDX msdx = new MinusSmoothDX(14);

            msdx.Calculate(history);

            AverageTrueRange atr = new AverageTrueRange(14);

            atr.Calculate(history);

            for (int i = 0; i < Period; i++)
            {
                PastValues.Add(0.0);
            }

            for (int h = Period; h < history.Count; h++)
            {
                PastValues.Add((msdx.PastValues[h] / atr.PastValues[h]) * 100);
            }

            Value = PastValues[PastValues.Count - 1];

            return(Value);
        }
Exemple #7
0
        public override double Calculate(IList <History> history)
        {
            DX dx = new DX(14);

            dx.Calculate(history);

            double sum = 0.0;

            // filler
            for (int i = 0; i < Period; i++)
            {
                PastValues.Add(0.0);
            }

            var dxObj = new DX(14);
            var dxVal = dxObj.Calculate(history);

            // Get first
            for (int h = Period; h < Period * 2; h++)
            {
                PastValues.Add(0.0);
                sum += 0.0;
            }

            PastValues[Period * 2 - 1] = sum / (double)Period;

            for (int h = Period * 2; h < history.Count; h++)
            {
                PastValues.Add(((PastValues[PastValues.Count - 1] * (Period - 1)) +
                                (dx.PastValues[h])) / (double)Period);
            }

            Value = PastValues[PastValues.Count - 1];

            return(Value);
        }
Exemple #8
0
        public void Trial(string label, Dictionary<string, double> probabilities, string guess)
        {
            if (probabilities == null || !probabilities.ContainsKey(label)) return;
            this.BestGuess = guess;
            this.TrialCounter++;
            if (SuccessRate.ContainsKey(label)) {
                SuccessRate[label].Add(probabilities[label]);
            } else {
                SuccessRate[label] = new PastValues(probabilities[label]);
            }

            if (!LabelSuccess.ContainsKey(label)) {
                LabelSuccess[label] = new PastTrials();
            }
            if (label == BestGuess) {
                Overall.Add(true);
                LabelSuccess[label].Add(true);
            } else {
                Overall.Add(false);
                LabelSuccess[label].Add(false);

                if (BestGuess != null) {
                    if (!LabelSuccess.ContainsKey(BestGuess)) {
                        LabelSuccess[BestGuess] = new PastTrials();
                    }
                    LabelSuccess[BestGuess].Add(false);
                }
            }
            updateOutcomes(label, probabilities, guess);
        }
Exemple #9
0
 private void Train(string label, double? lastEval)
 {
     this.LastEval = lastEval;
     if (LastEval == null) {
         return;
     }
     if (PastEvals.ContainsKey(label)) {
         PastEvals[label].Add(LastEval.Value);
     } else {
         PastEvals[label] = new PastValues(LastEval.Value);
     }
 }
Exemple #10
0
        public void Train(string label, int[][] input)
        {
            if (LastEval == null) {
                return;
            }

            string guess = "";
            if (LabelCertainty.ContainsKey(label)) {
                guess = LabelCertainty.BestGuess();
                this.SuccessRate.Trial(label, LabelCertainty, guess);
            }

            if (guess != label) {
                if (PastEvals.ContainsKey(label) && PastEvals[label].Count < 10) {
                    PastEvals[label].Add(LastEval.Value);
                } else if(!PastEvals.ContainsKey(label)) {
                    PastEvals[label] = new PastValues(LastEval.Value);
                }
            } else {

            }
        }