Exemplo n.º 1
0
        private void initialSetup()
        {
            if (_StartUp == true)
            {
                _StartUp = false;
                //_instr.SendOrder("BUY", 1, "MKT");
                //_instr.SendOrder("SELL", 1, "MKT");

                double[] m2IS = new double[12];
                m2IS = MassFuncs.mass2(AskPriList, BidPriList, AskSizeList, BidSizeList);

                int percentageChange = Math.Abs(percentDecision(m2IS));

                // Here we place the order

                if (percentageChange > 0)
                {
                    _instr.SendOrder("BUY", 1, "MKT"); //Using Oddlots to preserve
                }
                if (percentageChange < 0)
                {
                    _instr.SendOrder("SELL", 1, "MKT");
                }
                else if (percentageChange == 0)
                {
                    _instr.SendOrder("BUY", 1, "MKT");
                }
            }
        }
Exemplo n.º 2
0
        private void OnTimedEvent(object sender, ElapsedEventArgs e)
        {
            if (_PriceChangeCounter > 52)
            {
                // this is where we make mass1, depending on the MAs calculated above
                double[] m1 = new double[12];
                double[] m2 = new double[12];
                m1 = MassFuncs.mass1(MA100_old, MA100_new, MA200_old, MA200_new, MA500_old, MA500_new);

                //    Bid m2m = new Bid();
                m2 = MassFuncs.mass2(AskPriList, BidPriList, AskSizeList, BidSizeList);

                // now we call the DST fusion. You need to insert the other mass function somewhere
                double[] M = new double[12];

                //  MassFuncs.massFusion Mass = new massFusion();
                M = MassFuncs.massFusionFunc(m1, m2);

                //Timer DSTtime = new Timer();


                // Here we figure out what are position decision will be, i.e. increase/decrease and by what percentage
                //percentageChange = percentDecision(M);
                int percentageChange = percentDecision(M);
                for (int i = 0; i < 12; i++)
                {
                    Debug.WriteLine(M[i]);
                }
                Debug.WriteLine("im working nooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo0000000000w" + _Counter + "  " + percentageChange);
                Debug.WriteLine(percentageChange);
                // Here we place the order
                if (percentageChange > 0)
                {
                    _instr.SendOrder("BUY", (Math.Abs(percentageChange)), "MKT");
                }
                if (percentageChange < 0)
                {
                    _instr.SendOrder("SELL", (Math.Abs(percentageChange)), "MKT");
                }
                orderPlaced++;
            }
        }
        public static double[] mass1(double MA100_old, double MA100_new, double MA200_old, double MA200_new, double MA500_old, double MA500_new)
        {
            double[] EMAs = new double[6];
            EMAs[0] = MA100_old;
            EMAs[1] = MA100_new;
            EMAs[2] = MA200_old;
            EMAs[3] = MA200_new;
            EMAs[4] = MA500_old;
            EMAs[5] = MA500_new;

            double[] m1         = new double[12];
            int      cross_bull = 0;
            int      cross_bear = 0;
            // checking for crossover types
            double cross_100_200_prev = Math.Sign(EMAs[0] - EMAs[2]);
            double cross_100_200_now  = Math.Sign(EMAs[1] - EMAs[3]);
            double cross_200_500_prev = Math.Sign(EMAs[2] - EMAs[4]);
            double cross_200_500_now  = Math.Sign(EMAs[3] - EMAs[5]);
            double cross_100_500_prev = Math.Sign(EMAs[0] - EMAs[4]);
            double cross_100_500_now  = Math.Sign(EMAs[1] - EMAs[5]);

            // 100-200 crossovers

            if (cross_100_200_prev < cross_100_200_now)
            {
                cross_bull++;
            }
            else if (cross_100_200_prev > cross_100_200_now)
            {
                cross_bear++;
            }
            // 200-500 crossovers;
            if (cross_200_500_prev < cross_200_500_now)
            {
                cross_bull++;
            }
            else if (cross_200_500_prev > cross_200_500_now)
            {
                cross_bear++;
            }
            // 100-500 crossovers;
            if (cross_100_500_prev < cross_100_500_now)
            {
                cross_bull++;
            }
            else if (cross_100_500_prev > cross_100_500_now)
            {
                cross_bear++;
            }

            // now we check the possible scenarios
            if (cross_bull == 0 && cross_bear == 0)
            {
                double diff_now_100_200  = EMAs[1] - EMAs[3];
                double diff_prev_100_200 = EMAs[0] - EMAs[2];
                double diff_now_200_500  = EMAs[3] - EMAs[5];
                double diff_prev_200_500 = EMAs[2] - EMAs[4];
                double diff_now_100_500  = EMAs[1] - EMAs[5];
                double diff_prev_100_500 = EMAs[0] - EMAs[4];

                // looking at the interval lenghts
                double shrinks = Math.Sign(diff_prev_100_200 - diff_now_100_200)
                                 + Math.Sign(diff_prev_200_500 - diff_now_200_500)
                                 + Math.Sign(diff_prev_100_500 - diff_now_100_500);
                if (diff_now_100_200 > 0)
                {
                    if (shrinks == 3)
                    {
                        m1 = MassFuncs.massAssignFunc(3, 7.5, -7, 0);
                    }
                    else if (shrinks == 2)
                    {
                        m1 = MassFuncs.massAssignFunc(3, 5, -5, 0);
                    }
                    else if (shrinks == 1)
                    {
                        m1 = MassFuncs.massAssignFunc(3, 5, -4, 0);
                    }
                    else
                    {
                        m1 = MassFuncs.massAssignFunc(3, 3, -2, 0);
                    }
                }
                else if (diff_now_100_200 < 0)
                {
                    if (shrinks == 3)
                    {
                        m1 = MassFuncs.massAssignFunc(3, 7.5, -7, 1);
                    }
                    else if (shrinks == 2)
                    {
                        m1 = MassFuncs.massAssignFunc(3, 5, -5, 1);
                    }
                    else if (shrinks == 1)
                    {
                        m1 = MassFuncs.massAssignFunc(3, 5, -4, 1);
                    }
                    else
                    {
                        m1 = MassFuncs.massAssignFunc(3, 3, -2, 1);
                    }
                }
            }
            else if (cross_bull == 1 && cross_bear == 0) // one bullish
            {
                m1 = MassFuncs.massAssignFunc(3, 5, -4.5, 0);
            }
            else if (cross_bull == 2 && cross_bear == 0) // two bullish
            {
                m1 = MassFuncs.massAssignFunc(3, 2, -2.5, 0);
            }
            else if (cross_bull == 3 && cross_bear == 0) // three bullish, as good as life gets
            {
                m1 = MassFuncs.massAssignFunc(2, 4, -2, 0);
            }
            else if (cross_bull == 0 && cross_bear == 1) // one bear
            {
                m1 = MassFuncs.massAssignFunc(3, 5, -4.5, 1);
            }
            else if (cross_bull == 0 && cross_bear == 2) // two bear
            {
                m1 = MassFuncs.massAssignFunc(3, 2, -2.5, 1);
            }
            else if (cross_bull == 0 && cross_bear == 3) // three bear, the worst!
            {
                m1 = MassFuncs.massAssignFunc(2, 4, -2, 1);
            }
            else if (cross_bull == 1 && cross_bear == 1)
            {
                m1 = MassFuncs.massAssignFunc(8, 18, -18, 0);
            }
            else if (cross_bull == 2 && cross_bear == 1)
            {
                m1 = MassFuncs.massAssignFunc(1, 1, -2, 0);
            }
            else if (cross_bull == 1 && cross_bear == 2)
            {
                m1 = MassFuncs.massAssignFunc(1, 1, -2, 1);
            }

            Debug.WriteLine("m1 bull: " + cross_bull + "m1 bear: " + cross_bear);
            return(m1);
        }