Ejemplo n.º 1
0
        internal void Tick(string symbol, PeriodType period, DateTime bartime, DateTime time, double bid, double ask, int spread, double tickvalue,
                           double accountBalance, double accountEquity, double accountProfit, double accountFreeMargin,
                           int positionTicket, int positionType, double positionLots, double positionOpenPrice, DateTime positionOpenTime,
                           double positionStopLoss, double positionTakeProfit, double positionProfit, string positionComment, string parameters)
        {
            if (OnTick != null)
            {
                var tickea = new TickEventArgs(symbol, period, bartime, time, bid, ask, spread, tickvalue,
                                               accountBalance, accountEquity, accountProfit, accountFreeMargin,
                                               positionTicket, positionType, positionLots, positionOpenPrice, positionOpenTime,
                                               positionStopLoss, positionTakeProfit, positionProfit, positionComment, parameters);

                OnTick.BeginInvoke(this, tickea, null, null);
            }
        }
        /// <summary>
        /// Bridge OnTick 
        /// </summary>
        private void Bridge_OnTick(object source, TickEventArgs tea)
        {
            lock (_lockerTickPing)
            {
                if (_pingAttempt > 0 && JournalShowSystemMessages)
                {
                    string msgsys = tea.Symbol + " " + tea.Period + " " + Language.T("Tick received after an unsuccessful ping.");
                    var jmsgsys = new JournalMessage(JournalIcons.System, DateTime.Now, msgsys);
                    AppendJournalMessage(jmsgsys);
                    Log(msgsys);
                }
                _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();

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

                    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);

                ParseAndSetParametrs(tea.Parameters);
                LogActivatedSLTP();

                const 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);
                    var 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)
                {
                    string message = 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);
                    var jmsg = new JournalMessage(JournalIcons.Currency, DateTime.Now, message);
                    AppendJournalMessage(jmsg);
                    Log(message);
                }

                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();

                // Check for failed close order.
                CheckForFailedCloseOrder(tea.PositionLots);
            }
        }
        internal void Tick(string symbol, PeriodType period, DateTime bartime, DateTime time, double bid, double ask, int spread, double tickvalue,
                double accountBalance, double accountEquity, double accountProfit, double accountFreeMargin,
                int positionTicket, int positionType, double positionLots, double positionOpenPrice, DateTime positionOpenTime,
                double positionStopLoss, double positionTakeProfit, double positionProfit, string positionComment)
        {
            if (OnTick != null)
            {
                TickEventArgs tickea = new TickEventArgs(symbol, period, bartime, time, bid, ask, spread, tickvalue,
                    accountBalance, accountEquity, accountProfit, accountFreeMargin,
                    positionTicket, positionType, positionLots, positionOpenPrice, positionOpenTime,
                    positionStopLoss, positionTakeProfit, positionProfit, positionComment);

                OnTick.BeginInvoke(this, tickea, null, null);
            }
        }