コード例 #1
0
        /// <summary>
        /// Bridge OnTick
        /// </summary>
        void Bridge_OnTick(object source, MT4Bridge.TickEventArgs tea)
        {
            lock (lockerTickPing)
            {
                if (pingAttempt > 0 && JournalShowSystemMessages)
                {
                    JournalMessage jmsgsys = new JournalMessage(JournalIcons.System, DateTime.Now,
                                                                tea.Symbol + " " + tea.Period.ToString() + " " + Language.T("Tick received after an unsuccessful ping."));
                    AppendJournalMessage(jmsgsys);
                }
                pingAttempt = 0;

                if (!Data.IsConnected)
                {
                    return;
                }

                tickLocalTime  = DateTime.Now;
                tickServerTime = tea.Time;
                if (IsChartChangeged(tea.Symbol, (DataPeriods)(int)tea.Period))
                {
                    StopTrade();
                    Data.IsConnected = false;
                    SetFormText();

                    if (Configs.PlaySounds)
                    {
                        Data.SoundDisconnect.Play();
                    }

                    JournalMessage jmsg = new JournalMessage(JournalIcons.Warning, DateTime.Now,
                                                             tea.Symbol + " " + tea.Period.ToString() + " " + Language.T("Tick received from a different chart!"));
                    AppendJournalMessage(jmsg);

                    return;
                }

                bool bNewPrice = Math.Abs(Data.Bid - tea.Bid) > Data.InstrProperties.Point / 2;

                Data.Bid = tea.Bid;
                Data.Ask = tea.Ask;
                Data.InstrProperties.Spread    = tea.Spread;
                Data.InstrProperties.TickValue = tea.TickValue;

                Data.ServerTime = tea.Time;

                Data.SetTick(tea.Bid);

                bool isAccChanged = Data.SetCurrentAccount(tea.Time, tea.AccountBalance, tea.AccountEquity, tea.AccountProfit, tea.AccountFreeMargin);
                bool isPosChanged = Data.SetCurrentPosition(tea.PositionTicket, tea.PositionType, tea.PositionLots, tea.PositionOpenPrice, tea.PositionOpenTime,
                                                            tea.PositionStopLoss, tea.PositionTakeProfit, tea.PositionProfit, tea.PositionComment);

                bool updateData = true;
                SetDataAndCalculate(tea.Symbol, tea.Period, tea.Time, bNewPrice, updateData);

                string bidText = tea.Bid.ToString(Data.FF);
                string askText = tea.Ask.ToString(Data.FF);
                SetLblBidAskText(bidText + " / " + askText);

                // Tick data label
                if (JournalShowTicks)
                {
                    string         tickInfo = string.Format("{0} {1} {2} {3} / {4}", tea.Symbol, tea.Period, tea.Time.ToString("HH:mm:ss"), bidText, askText);
                    JournalMessage jmsg     = new JournalMessage(JournalIcons.Globe, DateTime.Now, tickInfo);
                    AppendJournalMessage(jmsg);
                }

                UpdateTickChart(Data.InstrProperties.Point, Data.ListTicks.ToArray());
                SetEquityInfoText(string.Format("{0:F2} {1}", tea.AccountEquity, Data.AccountCurrency));
                ShowCurrentPosition(isPosChanged);

                if (isAccChanged)
                {
                    JournalMessage jmsg = new JournalMessage(JournalIcons.Currency, DateTime.Now,
                                                             string.Format(Language.T("Account Balance") + " {0:F2}, " + Language.T("Equity") + " {1:F2}, " + Language.T("Profit") + ", {2:F2}, " + Language.T("Free Margin") + " {3:F2}",
                                                                           tea.AccountBalance, tea.AccountEquity, tea.AccountProfit, tea.AccountFreeMargin));
                    AppendJournalMessage(jmsg);
                }

                if (Data.IsBalanceDataChganged)
                {
                    UpdateBalanceChart(Data.BalanceData, Data.BalanceDataPoints);
                }

                SetTickInfoText(string.Format("{0} {1} / {2}", tea.Time.ToString("HH:mm:ss"), bidText, askText));
                SetConnIcon(2);

                // Sends OrderModify on SL/TP errors
                if (IsWrongStopsExecution())
                {
                    ResendWrongStops();
                }
            }

            return;
        }