【问题标题】:Using WPF to Interact with Indicators in MultiCharts .Net (Trading Program)使用 WPF 与 MultiCharts .Net 中的指标交互(交易程序)
【发布时间】:2017-06-30 06:21:42
【问题描述】:

我正在尝试使用 Visual Studio C# 创建一个 WPF 表单,该表单将与我在 MultiCharts .Net 中为我的交易图表创建的指标交互

我在解决方案中添加了一个 WPF 项目,并为指标添加了命名空间。但是,我不知道如何操作指标对象的输入。非常感谢使用此程序的人提供的任何帮助。

【问题讨论】:

    标签: c# trading


    【解决方案1】:

    你必须创建一个本地网络连接才能完成这项工作——我使用了套接字,但任何类似的方式都可以支持相同的目标:

    像这样制作一个新的 MC 指标:

    public class tests_OwnApp : IndicatorObject {
    
        public tests_OwnApp(object _ctx):base(_ctx)
        {
            PortNumber = 5000;
        }
    
        [Input]
        public int PortNumber { get; set; }
    
        public static string Symbol;
    
        const string ServerIP = "127.0.0.1";
    
    
        IPAddress localAdd;
        TcpListener listener;
        TcpClient client;
        NetworkStream nwStrm;
    
        private IPlotObject plot1;
    
        protected override void Create() {
            // create variable objects, function objects, plot objects etc.
            plot1 = AddPlot(new PlotAttributes("", EPlotShapes.Line, Color.Red));
            localAdd = IPAddress.Parse(ServerIP);
            client = null;
        }
    
        protected override void StartCalc() {
            // assign inputs 
    
            // establish connection
            if (listener == null)
            {
                listener = new TcpListener(localAdd, PortNumber);
    
            }
            listener.Stop();
            Thread.Sleep(100);
            listener.Start();
    
        }
    
        protected override void CalcBar()
        {
            // indicator logic 
            if (Bars.LastBarTime <= Bars.Time[0] + new TimeSpan(2,0,0))
            {
                Symbol = Bars.Info.Name;
    
                if (client == null || !client.Connected)
                    client = listener.AcceptTcpClient();
    
                // create network stream
                nwStrm = client.GetStream();
    
                // send symbol to app:
                Output.WriteLine("sending " + Symbol + " to application");
                byte[] bytesToSend = ASCIIEncoding.ASCII.GetBytes(Symbol);
    
    
                string closingPrice = Convert.ToString(Bars.Close[0]);
                string totalMsg = "Sym," + Symbol +
                    "\nClose[0]," + closingPrice + "\nClose[1]," + Bars.Close[1].ToString();
    
                byte[] bytes2 = ASCIIEncoding.ASCII.GetBytes(totalMsg);
                nwStrm.Write(bytes2, 0, bytes2.Length);
            }
        }
    }
    

    在您的应用中(控制台应用示例,扩展到 WPF):

    static void Main(string[] args)
            {
                const int PortNum = 5000;
                const string ServerIP = "127.0.0.1";
    
                DateTime startTime = DateTime.Now;
    
                TcpClient client = new TcpClient(ServerIP, PortNum);
                NetworkStream nwStream = client.GetStream();
    
                while (true)
                {
                    if (client.ReceiveBufferSize != 0)
                    {
                        nwStream = client.GetStream();
    
                        byte[] bytesToRead = new byte[client.ReceiveBufferSize];
                        int bytesRead = nwStream.Read(bytesToRead, 0, client.ReceiveBufferSize);
    
                        string msg = Encoding.ASCII.GetString(bytesToRead, 0, bytesRead);
    
                        Console.WriteLine("received: " + msg);
    
                        if (DateTime.Now - new TimeSpan(0, 0, 30) > startTime)
                        {
                            break;
                        }
                        Thread.Sleep(100);
                        Console.Write("-ping-");
                    }
                }
    
    
                Console.ReadLine();
            }
    

    同时运行它们,您会发现它们已连接并收到信息。

    我使用这个example 开始,以防我的示例还不够。

    确保包含所有必要的命名空间:

    using System.Net;
    using System.Net.Sockets;
    

    【讨论】:

      【解决方案2】:

      documentation 我相信第三章会告诉你如何使用指标

      【讨论】:

      • 可以,但不会从其他项目访问它们。我认为他们的解决方案是使用 ToolBar,它允许您使用 Forms 做一些事情。
      猜你喜欢
      • 2011-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-18
      • 1970-01-01
      • 2014-11-29
      • 1970-01-01
      相关资源
      最近更新 更多