以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://www.weistock.com/bbs/index.asp)
--  策略编写求助区  (http://www.weistock.com/bbs/list.asp?boardid=11)
----  策略编写  (http://www.weistock.com/bbs/dispbbs.asp?boardid=11&id=159155)

--  作者:qq代人发帖
--  发布时间:2017/11/2 10:03:24
--  策略编写
编译 ”....... ”有两条线 A and B;
金叉:A>B ;
死叉:A<B ;
应用”……”有两个周期5 and 1; 
5金叉 and 1金叉 then KB;
5金叉 and 1死叉 then PB;
5死叉 and 1死叉 then KS;
5死叉 and 1金叉 then PS;
定量两个时间段;
time1:=大于090500 and 小于145800;
time2:=大于210500 and 小于225800;
if time<>time1 or time<>time2 then 清仓;

--  作者:fly
--  发布时间:2017/11/6 11:02:24
--  
2条线为:5日均线20日均线,(金叉:5日均线上传20日均线;死叉:5日均线下破20日均线)
品种:螺纹钢
两个周期:5分钟、1分钟
策略运行在1分钟周期上

我们将以上面的具体条件为例,根据您1楼的需求编写代码,可以吗?

--  作者:banzhuan
--  发布时间:2017/11/8 16:07:26
--  
ma5:ma(close,5);
ma20:ma(close,20);
ss:=1;//下单手数

jc_5:=cross( STKINDI(STKLABEL ,\'ma.ma1\' ,0,2,-1) , STKINDI(STKLABEL,\'ma.ma3\',0,2,-1));
//由于1分钟引用5分钟周期会造成信号闪烁,所以引用上一根ma5分钟周期的金叉;
sc_5:=cross(STKINDI(STKLABEL,\'ma.ma3\',0,2,-1),STKINDI(STKLABEL,\'ma.ma1\',0,2,-1));
//引用上一根ma5分钟周期的死叉;
JC:=cross(ma5,ma20);//1分钟周期金叉;
sc:=cross(ma20,ma5);//1分钟周期死叉;

if sc_5 and jc  then  sellshort(holding<0,holding,MARKET);//5死叉 and 1金叉
if jc_5 and jc  then  buy(holding=0,ss,MARKET);//5金叉 and 1金叉
if JC_5 and sc  then  sell(holding>0,holding,MARKET);//5金叉 and 1死叉
if SC_5 and sc  then  buyshort(holding=0,ss,MARKET);//5死叉 and 1死叉

//使用的交易时间是金字塔时区,在北京时间的基础上加4个小时;
//由于引用上一根周期的5分钟K线,第一根K线时间已经大于130500;
if  (time>185800 and time<190000) or (time>025800 and time<030000) then 
begin
sell(holding>0,holding,market);
sellshort(holding<0,holding,market);
end
[此贴子已经被作者于2017/11/8 16:08:02编辑过]