예제 #1
0
        public override double HandleNextTick(Tick t)
        {
            double ATR = double.NaN;

            if (prevTick != null)
            {
                double m1 = t.BidHigh - t.BidLow;
                double m2 = Math.Abs(t.BidHigh - prevTick.BidClose);
                double m3 = Math.Abs(t.BidLow - prevTick.BidClose);
                double TR = Math.Max(m1, Math.Max(m2, m3));
                TrueRange.Enqueue(TR);
            }
            else
            {
                TrueRange.Enqueue(t.BidHigh - t.BidLow);
            }

            counter++;
            if (counter.Equals(Period))
            {
                ATR = TrueRange.ToArray().Average();
            }
            else if (counter > Period)
            {
                ATR = (this[0] * (Period - 1) + TrueRange.ToArray()[Period - 1]) / Period;
            }

            indicatorData.Enqueue(ATR);
            prevTick = t;
            return(ATR);
        }
예제 #2
0
        public override double HandleNextTick(Tick currentTick)
        {
            double value = double.NaN;

            if (previousTick != null)
            {
                if (currentTick.BidClose < previousTick.BidClose)
                {
                    DOWN.Enqueue(previousTick.BidClose - currentTick.BidClose);
                    UP.Enqueue(0);
                }
                else if (currentTick.BidClose > previousTick.BidClose)
                {
                    DOWN.Enqueue(0);
                    UP.Enqueue(currentTick.BidClose - previousTick.BidClose);
                }
            }

            if (DOWN.Count.Equals(DOWN.Capacity))
            {
                AVGUP   = UP.ToArray().Average();
                AVGDOWN = DOWN.ToArray().Average();
            }

            value        = 100 - 100 / (1 + AVGUP / AVGDOWN);
            previousTick = currentTick;

            indicatorData.Enqueue(value);
            return(value);
        }
예제 #3
0
        public override double HandleNextTick(Tick t)
        {
            double value = double.NaN;
            double RWIH  = double.NaN;
            double RWIL  = double.NaN;

            if (prevTick != null)
            {
                double m1 = t.BidHigh - t.BidLow;
                double m2 = Math.Abs(t.BidHigh - prevTick.BidClose);
                double m3 = Math.Abs(t.BidLow - prevTick.BidClose);
                double tr = Math.Max(m1, Math.Max(m2, m3));
                TR.Enqueue(tr);
            }
            else
            {
                TR.Enqueue(t.BidHigh - t.BidLow);
            }

            if (priceData.Count.Equals(priceData.Capacity))
            {
                List <double> maxRWIHI = new List <double>(Period - 1);
                List <double> maxRWILO = new List <double>(Period - 1);

                for (int k = 0; k < Period - 1; k++)
                {
                    double avgTR = 0;
                    for (int i = k; i < Period; i++)
                    {
                        avgTR += TR.ToArray()[i];
                    }
                    avgTR /= (Period - k);

                    double rwiHI = 1 / Math.Sqrt(Period - k) * (t.BidHigh - priceData.ToArray()[k].BidLow) / avgTR;
                    double rwiLO = 1 / Math.Sqrt(Period - k) * (priceData.ToArray()[k].BidHigh - t.BidLow) / avgTR;

                    maxRWIHI.Add(rwiHI);
                    maxRWILO.Add(rwiLO);
                }
                RWIH = maxRWIHI.Max();
                RWIL = maxRWILO.Max();
            }
            ((GenericContainer)subIndicators["RWHI"]).HandleNextTick(RWIH);
            ((GenericContainer)subIndicators["RWLO"]).HandleNextTick(RWIL);

            prevTick = t;
            priceData.Enqueue(t);

            indicatorData.Enqueue(double.NaN);
            return(double.NaN);
        }
예제 #4
0
        public double HandleNextTick(double currentTick)
        {
            double value = double.NaN;

            if (!currentTick.Equals(double.NaN))
            {
                tickdata.Enqueue(currentTick);

                if (tickdata.Count.Equals(tickdata.Capacity))
                {
                    if (indicatorData.Count.Equals(0))
                    {
                        value = tickdata.ToArray().Average();
                    }
                    else
                    {
                        value = currentTick * alpha + this[0] * (1 - alpha);
                    }

                    indicatorData.Enqueue(value);
                }
            }

            return(value);
        }
예제 #5
0
        public double HandleNextTick(double d)
        {
            double value = double.NaN;

            if (!d.Equals(double.NaN))
            {
                priceData.Enqueue(d);

                if (priceData.Count.Equals(priceData.Capacity))
                {
                    double   sum   = 0;
                    double[] array = priceData.ToArray();
                    for (int i = 1; i < array.Length; i++)
                    {
                        sum += Math.Abs(array[i] - array[i - 1]);
                    }
                    double ER = Math.Abs(d - priceData.ToArray()[0]) / sum;

                    double alpha = Math.Pow(ER * 0.6015 + 0.0645, 2);

                    if (indicatorData.Count.Equals(0))
                    {
                        value = priceData.Average();
                    }
                    else
                    {
                        value = alpha * d + (1 - alpha) * this[1];
                    }

                    indicatorData.Enqueue(value);
                }
            }

            return(value);
        }
예제 #6
0
        public override double HandleNextTick(Tick t)
        {
            double value = double.NaN;
            double a1    = BP1.ToArray().Sum() / TR1.ToArray().Sum();
            double a2    = BP2.ToArray().Sum() / TR2.ToArray().Sum();
            double a3    = BP3.ToArray().Sum() / TR3.ToArray().Sum();

            if (BP3.Count == BP3.Capacity)
            {
                value = 100 * ((4 * a1) + (2 * a2) + a3) / (4 + 2 + 1);
            }

            if (prevTick != null)
            {
                double TR = Math.Max(t.BidHigh, prevTick.BidClose) - Math.Min(t.BidLow, prevTick.BidClose);
                double BP = t.BidClose - Math.Min(t.BidLow, prevTick.BidClose);

                BP1.Enqueue(BP);
                BP2.Enqueue(BP);
                BP3.Enqueue(BP);

                TR1.Enqueue(TR);
                TR2.Enqueue(TR);
                TR3.Enqueue(TR);
            }

            prevTick = t;
            indicatorData.Enqueue(value);
            return(value);
        }
예제 #7
0
        public override double HandleNextTick(Tick t)
        {
            Tick hTick = null;

            if (HACandle.Count.Equals(0))
            {
                hTick = t;
            }

            if (prevTick != null)
            {
                double HABidClose = (t.BidOpen + t.BidHigh + t.BidLow + t.BidClose) / 4;
                double HAAskClose = (t.AskOpen + t.AskHigh + t.AskLow + t.AskClose) / 4;

                double HABidOpen = (prevTick.BidOpen + prevTick.BidClose) / 2;
                double HAAskOpen = (prevTick.AskOpen + prevTick.AskClose) / 2;

                double HABidHigh = Math.Max(t.BidHigh, Math.Max(HABidOpen, HABidClose));
                double HAAskHigh = Math.Max(t.AskHigh, Math.Max(HAAskOpen, HAAskClose));

                double HABidLow = Math.Min(t.BidLow, Math.Min(HABidOpen, HABidClose));
                double HAAskLow = Math.Min(t.AskLow, Math.Min(HAAskOpen, HAAskClose));

                hTick = new Tick(
                    t.CurrentBid, HABidOpen, HABidHigh, HABidLow, HABidClose,
                    t.CurrentAsk, HAAskOpen, HAAskHigh, HAAskLow, HAAskClose,
                    t.Volume, t.Time
                    );
            }

            HACandle.Enqueue(hTick);
            prevTick = hTick;

            return(hTick.BidClose);
        }
예제 #8
0
        public override void HandleNextTick(Tick t)
        {
            double emaVal = EMA.HandleNextTick(t);

            LRValues.Enqueue(emaVal);

            double[] Y = LRValues.ToArray();

            double stdErr = 0;

            if (Y.Count() == X.Length)
            {
                Vector x_data = new Vector(X);
                Vector y_data = new Vector(LRValues.ToArray());

                var poly = new PolynomialRegression(x_data, y_data, 2);
                for (int i = 0; i < Period; i++)
                {
                    double x = (i);
                    double y = poly.Fit(x);
                    stdErr += Math.Pow(LRValues.ToArray()[i] - y, 2);
                }

                stdErr = Math.Sqrt(stdErr);
            }

            HighData.Enqueue(EMA[0] + STDEV * stdErr);
            MiddleData.Enqueue(EMA[0]);
            LowData.Enqueue(EMA[0] - STDEV * stdErr);
        }
예제 #9
0
        public override double HandleNextTick(Tick t)
        {
            returnsData.Enqueue((t.BidClose - prevTick) / prevTick);
            double value = returnsData.ToArray().StandardDeviation();

            indicatorData.Enqueue(value);

            prevTick = t.BidClose;
            return(value);
        }
예제 #10
0
        public override void OnTick(params Tick[] t)
        {
            foreach (var indicator in indicatorList)
            {
                indicator.Value.HandleNextTick(t[0]);
            }

            if (!indicatorList["IND"][0].Equals(double.NaN))
            {
                dataList.Enqueue(indicatorList["IND"][0]);
            }

            if (dataList.Count == dataList.Capacity)
            {
                double nextIndicatorTick = NeuralNetwork.PredictNext(dataList.ToArray());

                //order fire logic
                if (nextIndicatorTick > 0 && nextIndicatorTick > prevIndicatorTick && prevIndicatorTick < 0)
                {
                    if (!IAccountManager.ExistsPositionForSymbol(t[0].Symbol))
                    {
                        IAccountManager.PlaceMarketOrder(t[0].Symbol, 10000, Position.PositionSide.Long, .001);
                    }
                }

                //order fire logic
                if (nextIndicatorTick < prevIndicatorTick)
                {
                    if (IAccountManager.ExistsLongPositionForSymbol(t[0].Symbol))
                    {
                        IAccountManager.ClosePosition(t[0].Symbol);
                    }
                }

                if (nextIndicatorTick < 0 && nextIndicatorTick < prevIndicatorTick && prevIndicatorTick > 0)
                {
                    if (!IAccountManager.ExistsPositionForSymbol(t[0].Symbol))
                    {
                        IAccountManager.PlaceMarketOrder(t[0].Symbol, 10000, Position.PositionSide.Short, .001);
                    }
                }

                if (nextIndicatorTick > prevIndicatorTick)
                {
                    if (IAccountManager.ExistsShortPositionForSymbol(t[0].Symbol))
                    {
                        IAccountManager.ClosePosition(t[0].Symbol);
                    }
                }

                prevIndicatorTick = nextIndicatorTick;
            }
        }
예제 #11
0
        public double HandleNextTick(double d)
        {
            double value = double.NaN;

            tickData.Enqueue(d);
            if (tickData.Count >= Period)
            {
                value = (d - tickData.ToArray()[1]) / tickData.ToArray()[1];
            }

            indicatorData.Enqueue(value);
            return(value);
        }
예제 #12
0
        public override double HandleNextTick(Tick t)
        {
            double value = double.NaN;

            _highData.Enqueue(t.BidHigh);
            _lowData.Enqueue(t.BidLow);
            value = (_highData.ToArray().Max() - t.BidClose) /
                    (_highData.ToArray().Max() - _lowData.ToArray().Min()) * -100;

            indicatorData.Enqueue(value);

            return(value);
        }
예제 #13
0
        public override double HandleNextTick(Tick t)
        {
            priceData.Enqueue(t.BidClose);

            double value = double.NaN;

            if (priceData.Count.Equals(priceData.Capacity))
            {
                value = HurstEstimation.CalculateHurstEstimate(priceData.ToArray());
            }
            indicatorData.Enqueue(value);
            return(value);
        }
예제 #14
0
파일: DWT.cs 프로젝트: yuxi214/QuantSys
        public double HandleNextTick(double d)
        {
            double returnValue = double.NaN;

            priceData.Enqueue(d);

            if (priceData.Count.Equals(priceData.Capacity))
            {
                returnValue = st.Run(priceData.ToArray(), detailLevel);
                indicatorData.Enqueue(returnValue);
            }

            return(returnValue);
        }
예제 #15
0
        public double HandleNextTick(double d)
        {
            double value = double.NaN;

            X.Enqueue(d);

            if (X.Count.Equals(X.Capacity))
            {
                double cov = StatisticsExtension.Covariance(new DenseVector(X.ToArray()), Y);
                value = cov / (X.ToArray().Variance() * Y.Variance());
            }

            indicatorData.Enqueue(value);
            return(value);
        }
예제 #16
0
파일: ZLEMA.cs 프로젝트: valmac/QuantSys
        public double HandleNextTick(double d)
        {
            priceData.Enqueue(d);

            double value = double.NaN;

            if (priceData.Count.Equals(priceData.Capacity))
            {
                value = d + (d - priceData.ToArray()[0]);
            }
            double returnValue = EMA.HandleNextTick(value);

            indicatorData.Enqueue(returnValue);
            return(returnValue);
        }
예제 #17
0
파일: SMA.cs 프로젝트: yuxi214/QuantSys
        public double HandleNextTick(double currentTick)
        {
            if (!currentTick.Equals(double.NaN))
            {
                double value = double.NaN;

                tickdata.Enqueue(currentTick);
                value = tickdata.ToArray().Average();
                indicatorData.Enqueue(value);

                return(value);
            }

            return(double.NaN);
        }
예제 #18
0
        public override void HandleNextTick(Tick t)
        {
            double emaVal = EMA.HandleNextTick(t);

            LRValues.Enqueue(emaVal);

            double[] Y = LRValues.ToArray();

            LinearRegression l = new LinearRegression();

            l.Model(Y);

            HighData.Enqueue(EMA[0] + STDEV * l.STDERR);
            MiddleData.Enqueue(EMA[0]);
            LowData.Enqueue(EMA[0] - STDEV * l.STDERR);
        }
예제 #19
0
        public override double HandleNextTick(Tick t)
        {
            double value = double.NaN;

            double typicalPrice = (t.BidClose + t.BidHigh + t.BidLow) / 3;

            priceData.Enqueue(typicalPrice);
            SMA.HandleNextTick(typicalPrice);

            if (priceData.Capacity.Equals(priceData.Count))
            {
                value = (1 / constant) * (typicalPrice - SMA[0]) / priceData.ToArray().StandardDeviation();
            }

            indicatorData.Enqueue(value);
            return(value);
        }
예제 #20
0
        public double HandleNextTick(double tick)
        {
            double Rankvalue = double.NaN;

            if (tick != double.NaN)
            {
                data.Enqueue(tick);


                if (indicatorData.Capacity == indicatorData.Count)
                {
                    Rankvalue  = 100 * (data.Data.Count(x => x < tick) + 0.5 * data.Data.Count(x => x.Equals(tick)));
                    Rankvalue /= Period;
                }
            }

            indicatorData.Enqueue(Rankvalue);
            return(Rankvalue);
        }
예제 #21
0
파일: MFI.cs 프로젝트: yuxi214/QuantSys
        public override double HandleNextTick(Tick t)
        {
            double MFITick = double.NaN;

            if (PositiveMF.Count == Period)
            {
                double MFR = PositiveMF.ToArray().Sum() / NegativeMF.ToArray().Sum();
                MFITick = 100 - 100 / (1 + MFR);
            }

            double tPrice       = (t.BidHigh + t.BidLow + t.BidClose) / 3;
            double rawMoneyFlow = t.Volume * tPrice;

            PositiveMF.Enqueue((t.BidClose >= t.BidOpen) ? rawMoneyFlow : 0);
            NegativeMF.Enqueue((t.BidClose < t.BidOpen) ? rawMoneyFlow : 0);

            indicatorData.Enqueue(MFITick);
            return(MFITick);
        }
예제 #22
0
        public double HandleNextTick(double currentTick)
        {
            if (!currentTick.Equals(double.NaN))
            {
                double value = double.NaN;
                tickdata.Enqueue(currentTick);

                if (tickdata.Capacity.Equals(tickdata.Count))
                {
                    Vector x_data = new Vector(X);
                    Vector y_data = new Vector(tickdata.ToArray());

                    var poly = new PolynomialRegression(x_data, y_data, 2);
                    value = poly.Fit(Period);
                }
                indicatorData.Enqueue(value);
                return(value);
            }

            return(double.NaN);
        }
예제 #23
0
파일: PFE.cs 프로젝트: yuxi214/QuantSys
        public override double HandleNextTick(Tick t)
        {
            double value = double.NaN;

            priceData.Enqueue(t.BidClose);

            if (priceData.Count.Equals(priceData.Capacity))
            {
                double[] pArray = priceData.ToArray();
                double   pN     = pArray[0];
                double   sign   = (t.BidClose > pN) ? 1 : -1;
                double   hypot  = Hypot(Period - 1, pChange(t.BidClose, pN));

                double sumHypot = 0;
                for (int i = 0; i < priceData.Count - 1; i++)
                {
                    sumHypot += Hypot((double)i + 1, pChange(pArray[i], pArray[i + 1]));
                }
                value = 100 * (sign * hypot) / sumHypot;
            }

            indicatorData.Enqueue(value);
            return(value);
        }
예제 #24
0
        public override void OnTick(params Tick[] t)
        {
            data1.Enqueue(t[0].BidClose);
            data2.Enqueue(t[1].BidClose);

            double STOP = 1.005;

            if (counter++ >= n)
            {
                var d1 = new DenseVector(data1.ToArray().NormalizeZScore());
                var d2 = new DenseVector(data2.ToArray().NormalizeZScore());

                double spread;
                //spread= (d1 - d2).ToArray().NormalizeZScore()[d1.Count - 1];


                List <double[]> mat = new List <double[]>();
                mat.Add(d1.ToArray());
                mat.Add(d2.ToArray());
                List <MaxEigenData> maxEigen = new List <MaxEigenData>();
                double[]            maxEigenValues;
                double[,] eigenMatrix;

                JohansenHelper.DoMaxEigenValueTest(mat, 5, out maxEigen, out maxEigenValues, out eigenMatrix);

                spread = (maxEigenValues[0] * d1 - maxEigenValues[1] * d2).ToArray().NormalizeZScore()[d1.Count - 1];


                TEMA.HandleNextTick(spread);

                ((GenericContainer)indicatorList["Container"]).HandleNextTick(spread);

                /*
                 * //t[0] hit stop / limit
                 * if ( (IAccountManager.ExistsShortPositionForSymbol(t[1].Symbol) &&
                 *  !IAccountManager.ExistsLongPositionForSymbol(t[0].Symbol))
                 ||
                 || (IAccountManager.ExistsLongPositionForSymbol(t[1].Symbol) &&
                 || !IAccountManager.ExistsShortPositionForSymbol(t[0].Symbol))
                 || )
                 ||{
                 || if(!IAccountManager.GetStopOrder(t[1].Symbol).Trailing)
                 ||     IAccountManager.ModifyTrailingStop(t[1], STOP/2);
                 ||}
                 ||
                 ||//t[1] positiong hit stop/limit
                 ||if ((IAccountManager.ExistsShortPositionForSymbol(t[0].Symbol) &&
                 || !IAccountManager.ExistsLongPositionForSymbol(t[1].Symbol))
                 ||
                 || (IAccountManager.ExistsLongPositionForSymbol(t[0].Symbol) &&
                 || !IAccountManager.ExistsShortPositionForSymbol(t[1].Symbol))
                 || )
                 ||{
                 || if (!IAccountManager.GetStopOrder(t[0].Symbol).Trailing)
                 ||     IAccountManager.ModifyTrailingStop(t[0], STOP/2);
                 ||}
                 */

                if (spread < -1 && IAccountManager.ExistsShortPositionForSymbol(t[0].Symbol) &&
                    IAccountManager.ExistsLongPositionForSymbol(t[1].Symbol))
                {
                    IAccountManager.ClosePosition(t[0].Symbol);
                    IAccountManager.ClosePosition(t[1].Symbol);


                    Console.WriteLine("Closed Pair Trade.");
                }
                if (spread > 1 && IAccountManager.ExistsLongPositionForSymbol(t[0].Symbol) &&
                    IAccountManager.ExistsShortPositionForSymbol(t[1].Symbol))
                {
                    IAccountManager.ClosePosition(t[0].Symbol);
                    IAccountManager.ClosePosition(t[1].Symbol);


                    Console.WriteLine("Closed Pair Trade.");
                }


                //short d1, long d2 if spread > 2.0
                if (TEMA[0] < 3 && TEMA[1] > 3 && !IAccountManager.ExistsPositionForSymbol(t[0].Symbol) &&
                    !IAccountManager.ExistsPositionForSymbol(t[1].Symbol))
                {
                    IAccountManager.PlaceMarketOrder(t[0].Symbol, 10000, Position.PositionSide.Short, STOP);
                    IAccountManager.PlaceMarketOrder(t[1].Symbol, 10000, Position.PositionSide.Long, STOP);


                    Console.WriteLine("Placed Pair Trade.");
                }

                if (TEMA[0] > -3 && TEMA[1] < -3 && !IAccountManager.ExistsPositionForSymbol(t[0].Symbol) &&
                    !IAccountManager.ExistsPositionForSymbol(t[1].Symbol))
                {
                    IAccountManager.PlaceMarketOrder(t[0].Symbol, 10000, Position.PositionSide.Long, STOP);
                    IAccountManager.PlaceMarketOrder(t[1].Symbol, 10000, Position.PositionSide.Short, STOP);


                    Console.WriteLine("Placed Pair Trade.");
                }
            }
        }