Example #1
0
        public override void onTick(Tick <int> currTick)
        {
            try
            {
                spreadAnalyzer.EvaluateSpread(currTick);
                ShowComment(currTick);

                if (currTime.Ticks / TickHistory.tickInOneMinute == currTick.DateTime.Ticks / TickHistory.tickInOneMinute)
                {
                    return;
                }
                currTime = currTick.DateTime;

                ExtremumPoint.Process(Math.Max(currTick.Bid, Meta.High(this.Symbol, 1)), Math.Min(currTick.Bid, Meta.Low(this.Symbol, 1)), currTick.DateTime);
                fluctuationList.Update(ExtremumPoint);

                for (int i = fluctuationList.StartIndex; i < fluctuationList.EndIndex; i++)
                {
                    Meta.ObjectMove(GetHLineName(i), 0, DateTime.Now, fluctuationList[i].AveragePrice);
                }

                if (!strategyTime.IsSystemON(currTick) || newsPeriod.IsNewsTime(currTick.DateTime))
                {
                    OrderOperation.CloseAllOrders();
                    return;
                }

                //open/modify tp
                AddModifyLimitOrder(fluctuationList.GetHighest(param["OpenOrderPercent"]), param["SL"], fluctuationList.GetHighest(param["TPOrderPercent"]) + spreadAnalyzer.AverageSpread, OrderSide.Sell);
                AddModifyLimitOrder(fluctuationList.GetLowest(param["OpenOrderPercent"]) + spreadAnalyzer.AverageSpread, param["SL"], fluctuationList.GetLowest(param["TPOrderPercent"]), OrderSide.Buy);

                ModifyMarketOrders(OrderSide.Buy, fluctuationList.GetLowest(param["TPOrderPercent"]));
                ModifyMarketOrders(OrderSide.Sell, fluctuationList.GetHighest(param["TPOrderPercent"]) + spreadAnalyzer.AverageSpread);

                //close limit orders
                //move tp

                //                    //check condition to close order
                //int sign = fluctuationList.GetSignDistanceFromAverageInPercent(currTick.Bid);
                //if (sign >= 0)
                //    CloseOrders(OrderSide.Buy, marketOrders);
                //if (sign <= 0)
                //    CloseOrders(OrderSide.Sell, marketOrders);


                //int peakDistanceFromAverageMinAbs = fluctuationList.GetMinDistanceFromAverageInPercent(currTick.Bid);
                //if (Math.Abs(peakDistanceFromAverageMinAbs) > param["OpenOrderPercent"])
                //    OpenNewMarketOrder(peakDistanceFromAverageMinAbs < 0 ? OrderSide.Buy : OrderSide.Sell, marketOrders, currTick);
            }
            catch (HistoryNotAvailableExceptions exc)
            {
                return;
            }
        }
Example #2
0
        public override void onTick(Tick <int> currTick)
        {
            Spread = spreadAnalyzer.EvaluateSpread(currTick);

            ExtremumPoint.Process(Math.Max(currTick.Bid, Meta.High(this.Symbol, 1)), Math.Min(currTick.Bid, Meta.Low(this.Symbol, 1)), currTick.DateTime);
            ExtremumPoint2.Process(Math.Max(currTick.Bid, Meta.High(this.Symbol, 1)), Math.Min(currTick.Bid, Meta.Low(this.Symbol, 1)), currTick.DateTime);

            if (currTime.Ticks / TickHistory.tickInOneMinute == currTick.DateTime.Ticks / TickHistory.tickInOneMinute)
            {
                return;
            }
            currTime = currTick.DateTime;

            if (!TestingMode)
            {
                ShowComment();
            }

            try
            {
                int PriceBidHighest = Math.Max(currTick.Bid, Meta.High(this.Symbol, 1));
                int PriceBidLowest  = Math.Min(currTick.Bid, Meta.Low(this.Symbol, 1));
                int PriceAskHighest = PriceBidHighest + Spread;
                int PriceAskLowest  = PriceBidLowest + Spread;

                IEnumerable <Order> marketOrders = this.OrderOperation.GetMarketOrders();
                IEnumerable <Order> limitOrders  = this.OrderOperation.GetLimitOrders();

                foreach (Order currOrder in marketOrders)
                {
                    if (currOrder.Side == OrderSide.Buy)
                    {
                        if (currOrder.TP - PriceAskLowest > param["TP"])
                        {
                            OrderOperation.ModifyMarketOrder(currOrder.ID, currOrder.SL, PriceAskLowest + param["TP"]);
                        }
                    }
                    else
                    {
                        if (PriceBidHighest - currOrder.TP > param["TP"])
                        {
                            OrderOperation.ModifyMarketOrder(currOrder.ID, currOrder.SL, PriceBidHighest - param["TP"]);
                        }
                    }
                }

                foreach (Order currOrder in limitOrders)
                {
                    if (!strategyTime.IsSystemON(currTick))
                    {
                        OrderOperation.CloseOrder(currOrder);
                        break;
                    }

                    if (currOrder.Side == OrderSide.Buy)
                    {
                        if (PriceAskHighest - currOrder.OpenPrice > param["LimitOpen"])
                        {
                            int openPrice = PriceAskHighest - param["LimitOpen"];
                            OrderOperation.ModifyLimitOrder(currOrder.ID, openPrice, openPrice - param["SL"], openPrice + param["TP"]);
                        }
                        if (!ExtremumPoint.FlagUP)
                        {
                            OrderOperation.CloseOrder(currOrder);
                        }
                    }
                    else
                    {
                        if (currOrder.OpenPrice - PriceBidLowest > param["LimitOpen"])
                        {
                            int openPrice = PriceBidLowest + param["LimitOpen"];
                            OrderOperation.ModifyLimitOrder(currOrder.ID, openPrice, openPrice + param["SL"], openPrice - param["TP"]);
                        }
                        if (ExtremumPoint.FlagUP)
                        {
                            OrderOperation.CloseOrder(currOrder);
                        }
                    }
                }

                if (strategyTime.IsSystemON(currTick) && limitOrders.Count() == 0 && marketOrders.Count() == 0)
                {
                    if (ExtremumPoint2.FlagUP == ExtremumPoint.FlagUP)
                    {
                        OrderSide side      = ExtremumPoint.FlagUP ? OrderSide.Buy : OrderSide.Sell;
                        int       openPrice = side == OrderSide.Buy ? PriceAskHighest - param["LimitOpen"] : PriceBidLowest + param["LimitOpen"];

                        OrderOperation.AddOrder(Order.NewLimitOrder(Meta.Symbol(), side, GetVolume(), openPrice, param["SL"], param["TP"]));
                    }
                }
            }
            catch (Exception exc)
            {
                logger.AddMessage(exc.ToString());
            }
        }