来源:mc官网
这次要来介绍的是一种以开盘状况来判断今日趋势行情的日內突破策略,希望可以帮助到大家学习写策略。
策略思想:
定出上下轨为突破点,上下轨是以每天开盘后第一根K线的最高跟最低值,后面行情突破后即进场,此策略主要是抓取单边行情,当遇到横盘震荡时会即时止损出场,防止大幅亏损,以下测试商品为IF,周期是1 min。。
源码如下:
[IntrabarOrderGeneration=true]
//开启bar内交易
input:m(1.01),n(0.99),stime(900),endtime(1455);
//定义参数
var:upline(high),downline(low);
//定义变量
if date<>date[1] then begin
upline=highD(0);
downline=lowD(0);
tl_new(date,915,upline,date,1515,upline);
tl_new(date,915,downline,date,1515,downline);
end;
//每天给上下轨赋值,tl_new是画线工具。
condition1=openD(0)>=closeD(1)*m;
//条件1是博跳空高开,底下暂时先不用,如果需要可以在下方条件控制处添加
condition2=openD(0)<=closeD(1)*n;
//条件2是博跳空低开,底下暂时先不用,如果需要可以在下方条件控制处添加
condition3=time>=stime and time<=endtime and marketposition=0 and close>upline;
//条件3规定日内交易时间,作为开多单语句
condition4=time>=stime and time<=endtime and marketposition=0 and close<downline;
//条件4规定日内交易时间,作为开空单语句
if condition3 then buy next bar at market;
//满足条件3(这边条件1先不用),开多单
if marketposition=1 and close crosses below downline then sell next bar at market;
//当持多单时,以下轨价格作为止损价格出场,防止行情大幅翻转亏损
if condition4 then sellshort next bar at market;
//满足条件4(这边条件2先不用),开空单
if marketposition=-1 and close crosses above upline then buytocover next bar at market;
//当持仓空单时,以上轨价格作为止损价格出场,防止行情大幅翻转亏损
if time>endtime and marketposition<>1 then buytocover next bar at market;
if time>endtime and marketposition<>-1 then sell next bar at market;
//收盘前平仓,根据周期,需要调整 endtime 的参数