使用 C# 将股票数据添加到 amibroker

发布于 2024-09-03 16:54:48 字数 919 浏览 5 评论 0原文

我很难得到并回答这个问题,我真的非常感谢对此的一些帮助。

我已经这样做了两个多星期了,毫无进展。

我想使用 C# 将一行股票数据添加到 amibroker,但我找不到关于如何在 C# 中实例化它的明确响应。

在 VB 中,我会这样做;

Dim AmiBroker = CreateObject("Broker.Application")                
sSymbol = ArrayRow(0).ToUpper
Stock = AmiBroker.Stocks.Add(sSymbol)
iDate = ArrayRow(1).ToLower
quote = Stock.Quotations.Add(iDate)
quote.Open = CSng(ArrayRow(2))
quote.High = CSng(ArrayRow(3))
quote.Low = CSng(ArrayRow(4))
quote.Close = CSng(ArrayRow(5))
quote.Volume = CLng(ArrayRow(6))

问题是在此实例中 CreateObject 在 C# 中不起作用。

我在网上找到了下面的代码,但我似乎无法理解如何实现上述目标。

Type objClassType; 
objClassType = Type.GetTypeFromProgID("Broker.Application");
// Instantiate AmiBroker
objApp = Activator.CreateInstance(objClassType);
objStocks = objApp.GetType().InvokeMember("Stocks", BindingFlags.GetProperty,null, objApp, null); 

有人可以帮我吗?

谢谢

I have had a hard time getting and answer to this and i would really , really appreciate some help on this.

i have been on this for over 2 weeks without headway.

i want to use c# to add a line of stock data to amibroker but i just cant find a CLEAR response on how to instantiate it in C#.

In VB , I would do it something like;

Dim AmiBroker = CreateObject("Broker.Application")                
sSymbol = ArrayRow(0).ToUpper
Stock = AmiBroker.Stocks.Add(sSymbol)
iDate = ArrayRow(1).ToLower
quote = Stock.Quotations.Add(iDate)
quote.Open = CSng(ArrayRow(2))
quote.High = CSng(ArrayRow(3))
quote.Low = CSng(ArrayRow(4))
quote.Close = CSng(ArrayRow(5))
quote.Volume = CLng(ArrayRow(6))

The problem is that CreateObject will not work in C# in this instance.

I found the code below somewhere online but i cant seem to understand how to achieve the above.

Type objClassType; 
objClassType = Type.GetTypeFromProgID("Broker.Application");
// Instantiate AmiBroker
objApp = Activator.CreateInstance(objClassType);
objStocks = objApp.GetType().InvokeMember("Stocks", BindingFlags.GetProperty,null, objApp, null); 

Can anyone help me here?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初见你 2024-09-10 16:54:48

VB 代码使用一种称为针对“COM IDispatch”兼容组件的后期绑定的方法。 C# 不支持后期绑定(直到 C# 版本 3)。 C# 编译器仅编译它知道如何绑定的代码(称为早期绑定)。

要执行您想做的操作,通过 Visual Studio 生成代理 dll 会更容易 - 在项目上选择添加引用,然后选择选项卡COM,然后在列表中搜索该 ami 代理组件。这将生成一个代理 dll,您可以使用与您为 VB 展示的类似代码对其进行编程。

在 C# 3.0 中,您会发现有时必须使用 Type.Missing 并且必须执行一些额外的显式转换,即使您认为这看起来不合逻辑。

C# 4.0 有一个名为 dynamic 的功能,它允许您在访问 COM 组件时编写更简洁的代码。

The VB code uses something called late binding against a "COM IDispatch" compatible component. Late binding is not supported by C# (up to C# version 3). The C# compiler only compiles code it knows how bind to (called early bind).

To do what you want to do, it would be easier to generate a proxy dll via Visual Studio - select add reference on a project, then select the tab COM, and then search for that ami broker component in the list. This will generate a proxy dll which you can program against using similar code as the one you have showed for VB.

In C# 3.0, you'll discover that you sometimes have to use Type.Missing and that you have to do some additional explicit casting, even though you'd think that it doesn't seem logical.

C# 4.0 has something called dynamic, which allows you to write much cleaner code when accessing COM components.

迷你仙 2024-09-10 16:54:48

请参阅我的答案此处的代码:

https://stackoverflow.com/a/20101274/1581495

我实际上使用这种方法现在。我从 MetaTrader 保存文本文件,然后将它们实时导入 AmiBroker。这样做本质上就像使用 ASCII 导入导入引号一样,因此您需要确保准备好导入格式文件。对我来说,一行示例数据如下所示:

EURAUD,20170607,00:00:00.4885,1.50174,1.50231,1 //Symbol, Date, Time (HH:MM:SS.tttt), Bid, Ask, Volume

我使用 default.format 文件,该文件如下所示:

$FORMAT TICKER,DATE_YMD,TIME,CLOSE,AUX1,VOLUME
$SEPARATOR ,
$AUTOADD 0
$BREAKONERR 0
$SKIPLINES 0 

在此处查找有关导入和格式的指南和一些示例:

https://www.amibroker.com/guide/d_ascii.html

编辑:这也可能有助于导入

http://www.amibroker.com /kb/2016/01/23/如何为-ascii-导入器创建自定义导入定义/

See my answer here for the code:

https://stackoverflow.com/a/20101274/1581495

I actually use this method now. I save text files from MetaTrader then import them realtime into AmiBroker. Doing it this way is essentially like importing quotes using the ASCII import, so you'll need to make sure that you prepare your import format file. For me, a line of sample data looks like this:

EURAUD,20170607,00:00:00.4885,1.50174,1.50231,1 //Symbol, Date, Time (HH:MM:SS.tttt), Bid, Ask, Volume

I use the default.format file, which looks like this:

$FORMAT TICKER,DATE_YMD,TIME,CLOSE,AUX1,VOLUME
$SEPARATOR ,
$AUTOADD 0
$BREAKONERR 0
$SKIPLINES 0 

Find the guide and some examples here on importing and formats:

https://www.amibroker.com/guide/d_ascii.html

EDIT: this might also help with importing

http://www.amibroker.com/kb/2016/01/23/how-to-create-custom-import-definition-for-ascii-importer/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文