示例#1
0
        public override void OnTick(params Tick[] t)
        {
            foreach (var indicator in indicatorList)
            {
                indicator.Value.HandleNextTick(t[0]);
            }

            if (!IsLive)
            {
                return;
            }


            for (int i = 0; i < t.Count(); i++)
            {
                if (indicatorList["AC" + i][0] < 0)
                {
                    if (IAccountManager.ExistsLongPositionForSymbol(t[i].Symbol))
                    {
                        IAccountManager.ClosePosition(t[i].Symbol);
                    }
                }

                if (indicatorList["AC" + i][0] > 0)
                {
                    if (IAccountManager.ExistsShortPositionForSymbol(t[i].Symbol))
                    {
                        IAccountManager.ClosePosition(t[i].Symbol);
                    }
                }


                if (!(t[i].AskClose - t[i].BidClose < .0003))
                {
                    return;
                }


                if (indicatorList["AC" + i][0] > 0 && indicatorList["AC" + i][1] < 0 && t[0].BidClose > indicatorList["SMA"][0])
                {
                    if (!IAccountManager.ExistsPositionForSymbol(t[i].Symbol))
                    {
                        IAccountManager.PlaceMarketOrder(t[1].Symbol, 10000, Position.PositionSide.Long, .01);
                    }
                }

                if (indicatorList["AC" + i][0] < 0 && indicatorList["AC" + i][1] > 0 && t[0].BidClose < indicatorList["SMA"][0])
                {
                    if (!IAccountManager.ExistsPositionForSymbol(t[i].Symbol))
                    {
                        IAccountManager.PlaceMarketOrder(t[1].Symbol, 10000, Position.PositionSide.Short, .01);
                    }
                }
            }
        }
示例#2
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;
            }
        }
示例#3
0
        public override void OnTick(params Tick[] t)
        {
            channel.HandleNextTick(t[0]);

            foreach (var indicator in indicatorList)
            {
                indicator.Value.HandleNextTick(t[0]);
            }

            if (prevTick != null)
            {
                if (IAccountManager.ExistsLongPositionForSymbol(t[0].Symbol))
                {
                    if (indicatorList["EMA"][0] < channel.LOW(0))
                    {
                        IAccountManager.ClosePosition(t[0].Symbol);
                    }
                }
                if (IAccountManager.ExistsShortPositionForSymbol(t[0].Symbol))
                {
                    if (indicatorList["EMA"][0] > channel.HI(0))
                    {
                        IAccountManager.ClosePosition(t[0].Symbol);
                    }
                }

                //Volatility high
                if (indicatorList["HVOL"][0] > 40)
                {
                    if (!IAccountManager.ExistsPositionForSymbol(t[0].Symbol))
                    {
                        if (indicatorList["EMA"][0] > channel.HI(0) && indicatorList["EMA"][1] < channel.HI(1))
                        {
                            IAccountManager.PlaceMarketOrder(t[1].Symbol, 10000, Position.PositionSide.Long, STOPLEVEL);
                        }
                    }

                    if (!IAccountManager.ExistsPositionForSymbol(t[0].Symbol))
                    {
                        if (indicatorList["EMA"][0] < channel.LOW(0) && indicatorList["EMA"][1] > channel.LOW(1))
                        {
                            IAccountManager.PlaceMarketOrder(t[1].Symbol, 10000, Position.PositionSide.Short, STOPLEVEL);
                        }
                    }
                }
            }

            prevTick = t[0];
        }
示例#4
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.");
                }
            }
        }