欢迎使用金字塔普通技术服务论坛,您可以在相关区域发表技术支持贴。
我司技术服务人员将优先处理 VIP客服论坛 服务贴,普通区问题处理速度慢,请耐心等待。谢谢您对我们的支持与理解。


金字塔客服中心 - 专业程序化交易软件提供商金字塔软件高级功能研发区 → 建议开发c#作为自动交易语言

   

欢迎使用金字塔普通技术服务论坛,您可以在相关区域发表技术支持贴。
我司技术服务人员将优先处理 VIP客服论坛 服务贴,普通区问题处理速度慢,请耐心等待。谢谢您对我们的支持与理解。    


  共有14454人关注过本帖平板打印复制链接

主题:建议开发c#作为自动交易语言

帅哥哟,离线,有人找我吗?
winewine99
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:新手上路 帖子:47 积分:422 威望:0 精华:1 注册:2010/3/19 15:47:54
以下列OpenQuant代码为例,给讲讲封装过程,并在金字塔中调用怎么做  发帖心情 Post By:2010/6/19 19:44:45 [只看该作者]

using OpenQuant.API; using OpenQuant.API.Indicators; using System.Drawing; public class MyStrategy : Strategy { // quantity to buy on a trade [Parameter("Order quantity (number of contracts to trade)")] double Qty = 100; [Parameter("Bar Block Size")] int BarBlockSize = 6; [Parameter("Length of SMA in blocks (weeks)", "SMA")] int FastSMALength = 22; [Parameter("Length of SMA in blocks (weeks)", "SMA")] int SlowSMALength = 55; int positionInBlock = 0; bool buyOnNewBlock; bool sellOnNewBlock; // two moving averages SMA fastSMA; SMA slowSMA; public override void OnStrategyStart() { // set up the fast average fastSMA = new SMA(Bars, FastSMALength * 7, Color.Yellow); Draw(fastSMA, 0); // set up the slow average slowSMA = new SMA(Bars, SlowSMALength * 7, Color.Pink); Draw(slowSMA, 0); } public override void OnBarOpen(Bar bar) { // calc quantity to reverse a position double orderQty = 2 * Qty; if (!HasPosition) orderQty = Qty; if (positionInBlock == 0) { if (buyOnNewBlock) { Buy(orderQty, "Reverse to Long"); buyOnNewBlock = false; } if (sellOnNewBlock) { Sell(orderQty, "Reverse to Short"); sellOnNewBlock = false; } } } public override void OnBar(Bar bar) { // if our SMAs contain the current bar date if (fastSMA.Contains(bar.DateTime) && slowSMA.Contains(bar.DateTime)) { // see which one is above the other Cross cross = fastSMA.Crosses(slowSMA, bar); if (cross == Cross.Above) buyOnNewBlock = true; if (cross == Cross.Below) sellOnNewBlock = true; } positionInBlock = (positionInBlock++) % BarBlockSize; } }

 回到顶部
总数 13 1 2 下一页