Today's the day

向软件大牛炫耀我会焊单片机,向硬件大牛炫耀我会写 Rails,向软硬件大牛炫耀我生物,向软硬件生物大牛炫耀我会折腾期货 -_-bbb

从 EasyLanguage 迁移到 MC .NET (一):基本结构
从 EasyLanguage 迁移到 MC .NET (三):常用 EasyLanguage 函数写法

从 EasyLanguage 迁移到 MC .NET (二):发送订单

galeki posted @ 2012年9月04日 22:34 in 交易 with tags MC-NET , 4586 阅读


在 MC .NET 中,发送买卖的订单要比 EL 中麻烦很多,最主要的区别在于,要事先为策略中所有可能会用到的订单建立订单对象,不同类型的订单(例如 Limit、Stop、Market)在创建订单对象的时候要指定不同的参数。


发送开仓订单在 EL 中的写法是这样的:

Buy next bar at 1200.5 limit;  // Limit Order
Buy next bar at 1234.5 stop;   // Stop Order
Buy next bar at market;        // Market Order

在 MC .NET 中就要麻烦一些,步骤如下:

  1. 首先为这个订单声明一个 IOrderPriced(如果是 market 单就是 IOrderMarket) 变量。
  2. 在 Create 函数中,为这个订单创建实例。
  3. 在 CalcBar 函数中发送订单。
namespace PowerLanguage.Strategy {
    public class test2 : SignalObject {
        public test2(object _ctx):base(_ctx){}
        private IOrderPriced buy_limit_order;  // Limit Order
        private IOrderPriced buy_stop_order;   // Stop Order
        private IOrderMarket buy_market_order; // Market Order

        protected override void StartCalc() {
        protected override void CalcBar(){
            // ...
            // ...


平仓单在 EL 中的写法是这样的:

sell next bar at market;
buytocover next bar at market;

在 MC .NET 中,平仓单和上面的开仓单的写法完全一样,区别只在于在 Create 函数中,把参数设置为 EOrderAction.Sell 或 EOrderAction.BuyToCover:

        protected override void Create() {
            // ...
            sell_order =         OrderCreator.MarketNextBar(new SOrderParameters(Contracts.Default, EOrderAction.Sell));
            buytocover_order =   OrderCreator.MarketNextBar(new SOrderParameters(Contracts.Default, EOrderAction.BuyToCover));

Limit 和 Stop 的平仓单同理。



在 EL 中,指定手数(比如买 5 手)的写法如下:

Buy 5 shares next bar at 1234.5 stop;

在 MC .NET 中要:

  1. 在 Create 函数中创建订单对象时,第一个参数要设置为 Contracts.UserSpecified,这样才可以指定手数。
  2. 在发送订单的 Send 函数中指定具体的手数。
	protected override void Create() {
		// ...
		buy_stop_order =   OrderCreator.Stop(new SOrderParameters(Contracts.UserSpecified, EOrderAction.Buy))


	protected override void CalcBar(){
		// ...

		buy_stop_order.Send(1234.5, 5);

		// ...


  • 无匹配
geometry dash 说:
2017年11月11日 14:43

在 Create 函数中,为这个订单创建实例。!

color switch 说:
2017年11月11日 14:52

If any page has quality posts like yours then I will search for information very quickly. Please donate again

usps tracking 说:
2018年3月30日 18:11

Good article and knowledge for me! I found a lot of information here! This article is really good for all newbie here. Thank you for sharing with us!

return man 3 game 说:
2018年5月17日 14:52

Your article is very interesting. I think this article has a lot of information needed, looking forward to your new posts. Get permission to share:

Potty Racers 说:
2018年5月17日 18:00

The article you have shared here very awesome. I really like and appreciated your work. I read deeply your article, the points you have mentioned in this article are useful

Jenry 说:
2018年6月01日 10:05

Very useful post. This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. Really its great article. Keep it up.

ludo king 说:
2018年6月01日 10:06

Very useful post. This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. Really its great article. Keep it up.

homedepot opinion 说:
2018年6月19日 03:04

This survey clearly measures the customer satisfaction. Also, the customers can openly share their views, ideas, and opinions. And, in case if feedback is negative or if customers are not satisfied then the company will make the necessary changes in their products and service offerings.

Hotmail Entrar 说:
2018年6月22日 15:26

Some problems are difficult to solve, but I will try. I have a part time job to cover life. Learning by doing is very tired, but it's my life.

color switch 说:
2018年7月11日 15:06

Although very difficult, but I think to accept the truth. My children it affected a lot, we have moved to a new place and is gradually adapting to it.

登录 *

loading captcha image...
or Ctrl+Enter