Example #1
0
        public static void Show(string text, string secAndClass, bool sendSignal = false)
        {
            if (form.IsNull() || form.IsDisposed)
            {
                form = new Form_MessageSignal();
            }
            form.TopMost         = true;
            form.FormBorderStyle = FormBorderStyle.FixedToolWindow;

            if (sendSignal)
            {
                SignalView.GSMSignaler.SendSignalCall();
            }
            listSignals.Insert(0, new RowSignal()
            {
                Signal = text, SecAndClass = secAndClass
            });

            form.CenterToScreen();
            form.Show();
        }
Example #2
0
        private void EventStrategy()
        {
            if (checkBoxFGActivate.Checked)
            {
                if (threadStrategy.IsNull() || threadStrategy.ThreadState == ThreadState.Stopped)
                {
                    if (DataTrading.Collection.Count() == 0)
                    {
                        return;
                    }
                    if (FastGapSettings.StepTime == 0)
                    {
                        return;
                    }
                    threadStrategy = MThread.InitThread(() =>
                    {
                        var allStocks = DataTrading.Collection.ToArray();
                        foreach (var elem in allStocks)
                        {
                            if (elem.ListStrategy.Count > 0)
                            {
                                foreach (var stg in elem.ListStrategy)
                                {
                                    if (stg is Strategy.Strategy)
                                    {
                                        var strategy = (Strategy.Strategy)stg;

                                        strategy.StepTime         = FastGapSettings.StepTime;
                                        strategy.TimeFrame        = FastGapSettings.TimeFrame;
                                        strategy.IndexStartCandle = FastGapSettings.IndexStartCandle;
                                        strategy.Option_1         = FastGapSettings.Option_1;
                                        strategy.Option_2         = FastGapSettings.Option_2;
                                        strategy.Option_3         = FastGapSettings.Option_3;

                                        var now = DateTime.Now;
                                        if (strategy.TimeLastAction < now.AddSeconds(strategy.StepTime * -1))
                                        {
                                            var tf            = elem.StorageTF.GetTimeFrame(strategy.TimeFrame);
                                            strategy.Security = elem.Security;
                                            strategy.BeforeAction(() =>
                                            {
                                            });
                                            var log = strategy.ActionCollection(tf.Candles.Collection);
                                            strategy.TimeLastAction = now;
                                            if (!log.Empty())
                                            {
                                                showLog         = true;
                                                this.FastGapLog = log + this.FastGapLog;
                                            }
                                        }
                                    }
                                    Thread.Sleep(1);
                                }
                            }
                        }
                        threadStrategy = null;
                    });
                    if (showLog)
                    {
                        showLog = false;
                        Form_MessageSignal.Show(this.FastGapLog, null);
                        textBoxFGLog.Text = this.FastGapLog;
                    }
                }
            }
        }
Example #3
0
        /// <summary>
        /// Проверка выполнения сигналов
        /// </summary>
        public void CheckAllSignals()
        {
            if (!SignalView.GSMSignaler.IsInit())
            {
                return;
            }
            Qlog.CatchException(() =>
            {
                foreach (var sig in SignalView.GSMSignaler.ToArray())
                {
                    switch (sig.Type)
                    {
                    case SignalMarket.TypeSignal.ByVolume:
                        if (!sig.SecClass.Empty() && sig.Volume > 0)
                        {
                            var date = sig.TimeAntiRepeat.GetDateTime();
                            if (date <= DateTime.Now)
                            {
                                var sec = GetSecCodeAndClass(sig.SecClass);
                                if (sec.NotIsNull())
                                {
                                    var trElem = DataTrading.Collection.FirstOrDefault(c => c.Security == sec);
                                    if (trElem.NotIsNull())
                                    {
                                        var timeFrameCol = trElem.StorageTF.GetTimeFrame(sig.TimeFrame);
                                        if (timeFrameCol.NotIsNull())
                                        {
                                            var candleCur = timeFrameCol.Candles.FirstCandle;
                                            if (candleCur.NotIsNull())
                                            {
                                                if (candleCur.Volume >= sig.Volume && sig.TimeAntiRepeat.GetDateTime() < DateTime.Now)
                                                {
                                                    sig.TimeAntiRepeat.SetDateTime(DateTime.Now.AddMinutes(sig.TimeFrame));
                                                    SignalView.GSMSignaler.SendSignalCall();
                                                    if (!sig.Infinity)
                                                    {
                                                        SignalView.GSMSignaler.RemoveSignal(sig);
                                                    }
                                                    textBoxLogSign.Text = "[" + DateTime.Now.ToLongTimeString() + "] " +
                                                                          sec.ToString() + " Volume: " + " > " + sig.Volume.ToString() +
                                                                          " tf:" + sig.TimeFrame + " (" + sig.Comment + ")" +
                                                                          "\r\n-------------------------------\r\n" +
                                                                          textBoxLogSign.Text;
                                                    Form_MessageSignal.Show(textBoxLogSign.Text, sec.ToString());
                                                    Thread.Sleep(1);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        break;

                    case SignalMarket.TypeSignal.ByTime:
                        if (sig.DateTime.NotIsNull())
                        {
                            if (sig.Condition == SignalMarket.CondSignal.Equals)
                            {
                                var dateSign = sig.DateTime.GetDateTime();
                                var d1       = DateTime.Now.AddSeconds(-1);
                                var d2       = d1.AddSeconds(2);
                                if (dateSign.Hour == d1.Hour && dateSign.Minute == d1.Minute &&
                                    dateSign.Second > d1.Second && dateSign.Second < d2.Second)
                                {
                                    if (!sig.Infinity)
                                    {
                                        SignalView.GSMSignaler.RemoveSignal(sig);
                                    }
                                    string msg = "Time: " + sig.DateTime.GetDateTime().ToShortTimeString() + " (" + sig.Comment + ")" +
                                                 "\r\n-------------------------------\r\n";
                                    textBoxLogSign.Text = msg + textBoxLogSign.Text;
                                    Form_MessageSignal.Show(msg, "", true);
                                    Thread.Sleep(1);
                                }
                            }
                        }
                        break;

                    case SignalMarket.TypeSignal.ByPrice:
                        if (!sig.SecClass.Empty())
                        {
                            var sec = GetSecCodeAndClass(sig.SecClass);

                            if (sec.NotIsNull() && sec.LastTrade.NotIsNull())
                            {
                                bool signal   = false;
                                string cond   = "";
                                decimal price = sec.LastPrice;
                                if (sec.LastTrade.NotIsNull())
                                {
                                    if (sec.LastTrade.DateTrade.GetDateTime() > DateTime.Now.AddMinutes(-3))
                                    {
                                        price = sec.LastTrade.Price;
                                    }
                                }
                                switch (sig.Condition)
                                {
                                case SignalMarket.CondSignal.MoreOrEquals:
                                    if (price >= sig.Price)
                                    {
                                        SignalView.GSMSignaler.SendSignalCall();
                                        signal = true;
                                        cond   = ">=";
                                    }
                                    break;

                                case SignalMarket.CondSignal.More:
                                    if (price > sig.Price)
                                    {
                                        SignalView.GSMSignaler.SendSignalCall();
                                        signal = true;
                                        cond   = ">";
                                    }
                                    break;

                                case SignalMarket.CondSignal.LessOrEquals:
                                    if (price <= sig.Price)
                                    {
                                        SignalView.GSMSignaler.SendSignalCall();
                                        signal = true;
                                        cond   = "<=";
                                    }
                                    break;

                                case SignalMarket.CondSignal.Less:
                                    if (price < sig.Price)
                                    {
                                        SignalView.GSMSignaler.SendSignalCall();
                                        signal = true;
                                        cond   = "<";
                                    }
                                    break;

                                case SignalMarket.CondSignal.Equals:
                                    if (price < sig.Price)
                                    {
                                        SignalView.GSMSignaler.SendSignalCall();
                                        signal = true;
                                        cond   = "==";
                                    }
                                    break;
                                }
                                if (signal)
                                {
                                    var msg = "[" + DateTime.Now.ToLongTimeString() + "] " +
                                              sec.Shortname + " " +
                                              cond + " " + sig.Price.ToString() + "(" + sig.Comment + ")" +
                                              "\r\n";
                                    textBoxLogSign.Text = msg + textBoxLogSign.Text;
                                    Form_MessageSignal.Show(msg, sec.ToString());
                                    SignalView.GSMSignaler.RemoveSignal(sig);
                                    Thread.Sleep(1);
                                }
                            }
                        }
                        break;
                    }
                }
            });
        }