  
- UID
- 2
- 积分
- 2914403
- 威望
- 1407234 布
- 龙e币
- 1507169 刀
- 在线时间
- 13521 小时
- 注册时间
- 2009-12-3
- 最后登录
- 2025-3-3

|
[MC源码] multicharts关于如何实现当根bar收盘前几秒平仓&&精英版及Pro资管版
策略需求:
Bar内策略,对于一分钟周期,想实现当根bar开盘tick入场,当根bar收盘前几秒去平仓!
策略情境实现如下:首先图表设置,示例图表为1 min,子图为1秒

工作区有个特别设置:
针对MC pro 或精英版,需要在策略属性-》回测中

策略代码如下:- [IntrabarOrderGeneration=true] //允许开启bar内模式
- [AllowSendOrdersAlways=true]; // 允许在bar状态处于未知的时候委托发单,即Barstatus的值为-1的时候为未知状态;
- Inputs: pN(5); // 收盘前几秒,可自定义目前设置为5秒;
- var: intrabarpersist var0(0); // bar内策略变量需要定义为intrabarpersist才可以tick级别变化;
- once cleardebug;
- if getappinfo(aiStrategyAuto)=1 then // 限制只有开启自动交易后才可以执行买卖及其他语句;
- begin
- if marketposition=0 and barstatus=0 then // bar开盘时买入进场,barstatus可F1看帮助
- buy ("B") next bar at market;
- if marketposition<>0 and time_s of data2>=CalcTime_s(time*100,-pN) then // 通过子图秒周期的时间,与主图收盘时间减去的秒数比较;
- sell ("S") next bar at market;
- Print(Barnumber:0:0," ",marketposition:0:0," ", time_S of data2:0:0," ",time:0:0," ",CalcTime_s(time*100,-pN):0:0);
- //调试输出结果验证代码部分
- end;
复制代码 输出结果:

追踪器委托记录的委托时间:

Ps: 上面大家可以看到委托时间和成交时间差距有几秒,是因为测试用的是模拟账号,模拟后台撮合成交有时会比较慢。大家可着重关注委托时间;
另外因为MC策略的执行是根据每笔数据去计算的,那么当数据不连续的时候,比如从145555 直接跳动145601,那么委托记录的执行也会慢的。
委托信号截图:
本帖隐藏的内容需要积分高于 5 才可浏览
具体情况大家可自行再测试; |
论坛官方微信、群(期货热点、量化探讨、开户与绑定实盘)
|