Today's the day

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

从 EasyLanguage 迁移到 MC .NET (二):发送订单
推特的影响力

从 EasyLanguage 迁移到 MC .NET (三):常用 EasyLanguage 函数写法

galeki posted @ 2012年9月06日 22:28 in 交易 with tags MC-NET , 10432 阅读

常用 EasyLanguage 函数写法

了解了 MC .NET 策略的基本结构,与订单发送的方式之后,理论上就可以写自己想要的策略了,不过要想把原 EL 策略移植过来的话,还要知道 EL 函数在 MC .NET 移植过来的写法才行。

大部分原 EL 函数,都被 MC .NET 打包至类或接口中,名字基本上也没有大变化,在 MC .NET 帮助文件中搜索原函数名称,基本上都能找到大致结果,这里列举一些常用函数的移植写法。

取得图标 K 线信息

在 EL 中,可以通过 Open[x]、Close[x]、High[x]、Low[x] 取得当前或者前 x 根 K 线的价格信息,在 MC .NET 中,这些信息被打包到 Bars 接口中,对应的关系如下(比如取得前一根 K 线的信息):

EasyLanguage MC .NET
Open[1] Bars.Open[1]
Close[1] Bars.Close[1]
High[1] Bars.High[1]
Low[1] Bars.Low[1]
Time[1] Bars.Time[1]
Date[1] Bars.Time[1].Date
Volume[1] Bars.Volume[1]

在 EL 中,经常比较 Date[0] 和 Date[1] 来判断是否来到新的一天,那么在 MC .NET 中就要这样写:

if ( Bars.Time[0].Date != Bars.Time[1].Date )
{

    // new day

}

交易品种信息

当前交易的品种信息,比如 Minmove、BigPointValue、PriceScale 等,也被打包到了 Bars.Info 中,对于的关系如下:

EasyLanguage MC .NET
MinMove Bars.Info.MinMove
PriceScale Bars.Info.PriceScale
BigPointValue Bars.Info.BigPointValue

持仓信息

当前持仓的信息,比如 MarketPosition 等函数,被打包到了 StrategyInfo 接口中,对应的关系如下:

EasyLanguage MC .NET
MarketPosition StrategyInfo.MarketPosition
CurrentContracts Math.Abs( StrategyInfo.MarketPosition )

值得注意的是,在 EL 里 MarketPosition 只包含了 -1、0、1 的方向信息,但是在 MC .NET 中也包含了持仓数量,所以要想获得 EL 中 CurrentContracts 的结果只要简单的取 StrategyInfo.MarketPosition 的绝对值就行了。

自动平仓函数

EL 中的自动平仓函数也被 MC .NET 移植了过来,可以直接使用,方法名称稍微有点改变:

EasyLanguage MC .NET
setstoppostion CurSpecOrdersMode = ESpecOrdersMode.PerPosition;
setstopcontract CurSpecOrdersMode = ESpecOrdersMode.PerContract;
setstoploss(1234) GenerateStopLoss(1234)
setpercenttrailling(1234, 20) GeneratePercentTrailing(1234, 20)
profittarget(1234) GenerateProfitTarget(1234)
breakeven(1234) GenerateBreakEven(1234)
setexitonclose GenerateExitOnClose()

序列变量

在 EL 中,所有自定义的 Vars 变量,都可以通过 vars1[x] 的形式来引用 x 根 K 棒之前的值,如果要想在 MC .NET 也可以这样做的话,步骤如下:

  1. 声明一个 VariableSeries<T> 类型的变量,具体类型要看变量的用途(如果用来保存价格信息就用 double,如果来保存持仓信息就用 int)。
  2. 在 Create 函数中,对这个变量进行初始化。
  3. 在 StartCalc 函数中,设置变量的初始值。
  4. 然后就可以在 CalcBar 函数中按照 EL 的形式使用这个序列变量了,唯一的不同,在于给变量赋值的时候不能直接使用 var1 = x 而是要使用 var1.Value = x。

以 double 类型的序列变量为例:

namespace PowerLanguage.Strategy {
	public class test3 : SignalObject {
		public test3(object _ctx):base(_ctx){}
		
		private VariableSeries<double> var1;
		
		protected override void Create() {
			var1 = new VariableSeries<double>(this);
		}
		protected override void StartCalc() {
			var1.DefaultValue = 0;
		}
		protected override void CalcBar(){
			var1.Value = Bars.Close[0];
			
			if( var1[0] != var1[1] )
			{
				//...
			}
			
		}
	}
}

 

有了这些函数,基本上可以移植大部分 EL 策略了,迁移教程也告一段落。当然这并不是全部,更详细的信息可以参考 MC .NET 编辑器的帮助文件,或是直接在编辑器中查看类或者接口的自动补全,基本上就可以把用法了解个大概。当然更好的方法还是参考 MC .NET 内置策略代码的写法,不过官方说目前的内置策略代码有一部分是自动生成的,所以写法可能冗杂一些,并不一定要完全仿照内置策略的模式来写。

  • 无匹配
Stu 说:
2012年11月11日 16:45

你好很高兴看到您写的关于mc.net的技术文章 我是一名在芝加哥的期货交易员最近我也在研究这个.net平台。希望可以互相交流一下

Avatar_small
galeki 说:
2012年11月12日 03:48

握手~ 我还没敢拿他用来交易,官方也在进一步 beta 中,不过感觉 mc.net 还是挺有前途的。

我的联系方式可以在右上角的“关于”找到哦~

bodak yellow lyrics 说:
2017年11月11日 14:45

This page gives you a lot of information. Thank you!

fireboy and watergir 说:
2018年6月15日 11:29

Hi guys, your blog' s design is simple and clean and i like it. Your blog posts about Online writing Help are superb. Please keep them coming. Greets!

mywawavisit.com 说:
2018年6月19日 03:07

Do take part in Wawa Customer Survey and give your honest feedback about your experience visit to the store and grab a chance to win $250 worth of gift card.

gmail login 说:
2018年6月28日 09:49

我经常访问你的网站,并找到很多有趣的信息。 不仅好帖子,而且很好的评论。 谢谢你,期待你的页面越来越强大。

spotify web player 说:
2018年7月20日 15:37

Thanks for sharing these useful information! This is really interesting information for me.

happy wheels 说:
2018年10月05日 11:19

This is also a very good post which I really enjoyed reading. It is not every day that I have the possibility to see something like this..

instagram video down 说:
2018年12月01日 15:51

great article, I was very impressed about it, wish you would have stayed next share

instagram app 说:
2018年12月01日 15:52

I am very happy to read this. Appreciate your sharing

Manga Fox 说:
2018年12月05日 18:02

I really like your website and specially this post and that's the reason I am commenting here

Super Smash Flash 2 说:
2019年1月25日 10:50

This is a great article. It gave me a lot of useful information. thank you very much.

Fleeing The Complex 说:
2019年1月25日 10:50

Thank you for sharing valuable information. Nice post. I enjoyed reading this post.

unfair mario 说:
2019年1月25日 10:50

great post. i like it. feeling great when reading your post .

wallpaper hd 说:
2019年1月25日 16:03

The information you have very true and useful, thank you have shared this post.

go movies 说:
2019年1月25日 16:04

I would like to thank you for your nicely written post

super smash flash 2 说:
2019年1月25日 17:50

The information you have very true and useful, thank you have shared this post.

made in abyss 说:
2019年1月25日 17:51

great article, I was very impressed about it, wish you would have stayed next share

happy wheels 说:
2019年1月26日 12:57

New words you share very well. I have learned many things. thank you!

Vex 3 说:
2019年1月31日 17:07

I really wanted to send a small word to say thanks to you for the fantastic points you are writing on this site

Happy Wheels 说:
2019年3月09日 14:53

When I'm sad I usually play games. It will make me more comfortable. I like to spend time like that

hotmail entrar 说:
2019年3月09日 14:53

I have too insipid and tedious, but that's my personality. It's hard to change

build royale 说:
2019年4月04日 11:34

这是一篇很棒的小帖子,里面有一些宝贵的提示。 我完全同意。 你将激情和参与带入你所做的事情的方式可以真正改变你对现场的看法。

iphongthuynet 说:
2019年4月09日 17:26

<a href="https://www.plurk.com/iphongthuynet">iphongthuynet</a>
<a href="http://sco.lt/8kM9tA">iphongthuynet</a>

http://sco.lt/8kM9tA
thank you so much
im website: IPHONGTHUYNET
https://www.plurk.com/iphongthuynet

hockey legends 说:
2019年8月12日 15:44

Your post is very attractive. It discusses in detail the issues.

Write My Essay Onlin 说:
2019年8月22日 16:15

Many of you are TradeStation users and have no doubt used (or tried to use) EasyLanguage to program your own trading system. The name notwithstanding, EasyLanguage can be tricky, even for experienced programmers. So, this month, I'm going to cover a few EasyLanguage techniques that may be nonobvious to the uninitiated.

candy crush soda 说:
2019年11月25日 16:54

It is wonderful to be here with everyone, I have a lot of knowledge from what you share, to say thank you, the information and knowledge here helps me a lot

Web Design Company 说:
2020年3月24日 15:34

On the off chance that the .NET discharge was accessible years back when I chose to buy MC, I would have picked it rather the EL form since I am an extremely experienced and equipped software engineer. Be that as it may, since I've grown bunches of code in EL, I'm reluctant to put forth the additional attempt to change over it to the .NET variant, in spite of a portion of the restrictions of EL.

run 3 说:
2020年4月23日 18:41

Your article is very useful, the content is great, I have read a lot of articles, but for your article, it left me a deep impression, thank you for sharing.

basketball legends 说:
2020年4月27日 15:42

This is a great thing, I think everyone feels this information is very valuable, thank you

먹튀검증사이트 说:
2021年1月11日 21:20

I admire this article for the well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much. 먹튀검증사이트

no excuses runner 说:
2021年1月20日 19:17

For a long time me & my friend were searching for informative blogs, but now I am on the right place guys, you have made a room in my heart! 먹튀검증

Faddy 说:
2021年1月24日 15:28

Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info. https://mtsoul.net

Faddy 说:
2021年1月25日 21:38

Islamic Wall Art and Decor for the Modern Muslim Home Modern Islamic Canvas, Prints, and Framed Art for your home or as an Islamic Gift to family and friends. Top quality Islamic Wall Art made in USA and UK with FREE worldwide shipping modern islamic art

no excuses runner 说:
2021年1月26日 19:15

I know your aptitude on this. I should say we ought to have an online discourse on this. Composing just remarks will close the talk straight away! What's more, will confine the advantages from this data. arbeiten von zu hause

ryse residences cond 说:
2021年2月16日 20:58

You make so many great points here that I read your article a couple of times. Your views are in accordance with my own for the most part. This is great content for your readers. Cooking Games

CBSE 10th Admit Card 说:
2021年2月24日 22:42

CBSE will release the CBSE 10th admit card 2021 in April on the official website of the Board- cbse.nic.in. Schools need to visit the website, enter using their log ID and password and download the admit cards of all students studying in their schools in class 10th. Students are required to collect their CBSE class 10 admit card 2021 from their school. It is important to carry the CBSE 10th admit card 2021 on the day of exams as no candidate will be allowed to write the exam without it. CBSE 10th Admit Card 2021


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter