예제 #1
0
        protected override void BtnShowAccountInfo_Click(object sender, EventArgs e)
        {
            if (!Data.IsConnected)
            {
                SetBarDataText("   " + Language.T("Not Connected"));
                return;
            }

            MT4Bridge.AccountInfo ai = bridge.GetAccountInfo();
            if (ai == null)
            {
                SetBarDataText("   " + Language.T("Cannot receive account information!"));
                return;
            }

            string[] asParams = new string[] {
                "Name",
                "Number",
                "Company",
                "Server",
                "Currency",
                "Leverage",
                "Balance",
                "Equity",
                "Profit",
                "Credit",
                "Margin",
                "Free margin mode",
                "Free margin",
                "Stop out mode",
                "Stop out level",
                "Is demo account"
            };

            string[] asValues = new string[] {
                ai.Name,
                ai.Number.ToString(),
                ai.Company,
                ai.Server,
                ai.Currency,
                ai.Leverage.ToString(),
                ai.Balance.ToString(),
                ai.Equity.ToString(),
                ai.Profit.ToString(),
                ai.Credit.ToString(),
                ai.Margin.ToString(),
                ai.FreeMarginMode.ToString(),
                ai.FreeMargin.ToString(),
                ai.StopOutMode.ToString(),
                ai.StopOutLevel.ToString(),
                ai.IsDemo ? "Yes" : "No"
            };

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            for (int i = 0; i < asParams.Length; i++)
            {
                sb.AppendLine(string.Format("      {0,-25} {1}", asParams[i], asValues[i]));
            }
            SetBarDataText(sb.ToString());

            return;
        }
예제 #2
0
        /// <summary>
        /// Sets the instrument's properties after connecting;
        /// </summary>
        bool UpdateDataFeedInfo(DateTime time, string symbol, DataPeriods period)
        {
            lock (lockerDataFeed)
            {
                Data.ResetBidAsk();
                Data.ResetAccountStats();
                Data.ResetPositionStats();
                Data.ResetBarStats();
                Data.ResetTicks();

                // Reads market info from the chart
                MT4Bridge.MarketInfo marketInfo = bridge.GetMarketInfoAll(symbol);
                if (marketInfo == null)
                {
                    if (JournalShowSystemMessages)
                    {
                        JournalMessage jmsgsys = new JournalMessage(JournalIcons.System, DateTime.Now,
                                                                    symbol + " " + (MT4Bridge.PeriodType)(int) period + " " + Language.T("Cannot update market info."));
                        AppendJournalMessage(jmsgsys);
                    }
                    return(false);
                }

                // Sets instrument properties
                Data.Period = period;
                Data.InstrProperties.Symbol         = symbol;
                Data.InstrProperties.LotSize        = (int)marketInfo.ModeLotSize;
                Data.InstrProperties.MinLot         = marketInfo.ModeMinLot;
                Data.InstrProperties.MaxLot         = marketInfo.ModeMaxLot;
                Data.InstrProperties.LotStep        = marketInfo.ModeLotStep;
                Data.InstrProperties.Digits         = (int)marketInfo.ModeDigits;
                Data.InstrProperties.Spread         = marketInfo.ModeSpread;
                Data.InstrProperties.SwapLong       = marketInfo.ModeSwapLong;
                Data.InstrProperties.SwapShort      = marketInfo.ModeSwapShort;
                Data.InstrProperties.TickValue      = marketInfo.ModeTickValue;
                Data.InstrProperties.StopLevel      = marketInfo.ModeStopLevel;
                Data.InstrProperties.MarginRequired = marketInfo.ModeMarginRequired;

                SetNumUpDownLots(marketInfo.ModeMinLot, marketInfo.ModeLotStep, marketInfo.ModeMaxLot);

                // Sets Market Info
                string[] values = new string[] {
                    symbol,
                    Data.DataPeriodToString(period),
                    marketInfo.ModeLotSize.ToString(),
                    marketInfo.ModePoint.ToString("F" + marketInfo.ModeDigits.ToString()),
                    marketInfo.ModeSpread.ToString(),
                    marketInfo.ModeSwapLong.ToString(),
                    marketInfo.ModeSwapShort.ToString()
                };
                UpdateStatusPageMarketInfo(values);

                MT4Bridge.Bars bars = bridge.GetBars(symbol, (MT4Bridge.PeriodType)(int) period);
                if (bars == null)
                {
                    if (JournalShowSystemMessages)
                    {
                        Data.SoundError.Play();
                        JournalMessage jmsgsys = new JournalMessage(JournalIcons.System, DateTime.Now,
                                                                    symbol + " " + (MT4Bridge.PeriodType)(int) period + " " + Language.T("Cannot receive bars!"));
                        AppendJournalMessage(jmsgsys);
                    }
                    return(false);
                }
                if (bars.Count < MaxBarsCount((int)period))
                {
                    if (JournalShowSystemMessages)
                    {
                        Data.SoundError.Play();
                        JournalMessage jmsg = new JournalMessage(JournalIcons.Error, DateTime.Now,
                                                                 symbol + " " + (MT4Bridge.PeriodType)(int) period + " " + Language.T("Cannot receive enough bars!"));
                        AppendJournalMessage(jmsg);
                    }
                    return(false);
                }
                if (JournalShowSystemMessages)
                {
                    JournalMessage jmsgsys = new JournalMessage(JournalIcons.System, DateTime.Now,
                                                                symbol + " " + (MT4Bridge.PeriodType)(int) period + " " + Language.T("Market data updated, bars downloaded."));
                    AppendJournalMessage(jmsgsys);
                }

                // Account Information.
                MT4Bridge.AccountInfo account = bridge.GetAccountInfo();
                if (account == null)
                {
                    if (JournalShowSystemMessages)
                    {
                        Data.SoundError.Play();
                        JournalMessage jmsg = new JournalMessage(JournalIcons.Error, DateTime.Now,
                                                                 symbol + " " + (MT4Bridge.PeriodType)(int) period + " " + Language.T("Cannot receive account information!"));
                        AppendJournalMessage(jmsg);
                    }
                    return(false);
                }
                if (JournalShowSystemMessages)
                {
                    JournalMessage jmsgsys = new JournalMessage(JournalIcons.System, DateTime.Now,
                                                                symbol + " " + (MT4Bridge.PeriodType)(int) period + " " + Language.T("Account information received."));
                    AppendJournalMessage(jmsgsys);
                }
                Data.AccountName     = account.Name;
                Data.IsDemoAccount   = account.IsDemo;
                Data.AccountCurrency = account.Currency;
                Data.SetCurrentAccount(time, account.Balance, account.Equity, account.Profit, account.FreeMargin);
                UpdateBalanceChart(Data.BalanceData, Data.BalanceDataPoints);

                SetTradeStrip();
                SetLblSymbolText(symbol);
            }

            return(true);
        }