variable: cs=0;
手数:=10;
M:=OPENMINUTES(time );
h30:ref(HHV(HIGH,M),1)*1.0001;
l30:ref(LLV( LOW,M),1)*0.9999;
//jc1:=cross(CLOSE,h30);
//tjc2:=cross(time,100000);
//sc1:=cross(l30,close);
long1:= cross(h,h30) AND TIME>100000;// and TTOTALDAYTRADE<1 and HOLDING=0;
long2:= h>h30 AND cross(TIME,100000);// and TTOTALDAYTRADE<1 and HOLDING=0;
short1:= cross(l30,l) AND TIME>100000;// and TTOTALDAYTRADE<1 and HOLDING=0;
short2:= L<l30 AND cross(TIME,100000);// and TTOTALDAYTRADE<1 and HOLDING=0;
long:= long1 or long2;
short:=short1 or short2;
if long=1 then cs:=cs+1;
if short=1 then cs:=cs+1;
{平多} SELL(cross(time,145859) and holding>0 ,0 ,market );
{平空}SELLSHORT(cross(time,145859) and holding<0 ,0 ,market );
{平多} SELL(short=1 and holding>0 ,0 ,market );
{平空}SELLSHORT( long=1 and holding<0 ,0 ,market );
{开多} BUY( long=1 and cs=1 ,手数 ,market );
{开空} BUYSHORT(short=1 and cs=1 ,手数 ,market );
你好,此公式编译正常,图表显示也正常,至于能不能自动化交易,还是要看楼主自己的需求和选择
M:=OPENMINUTES(time );//用这个表达当日的K线数目----可替换成以下两句
M:=barstlast(date<>ref(date,1))+1;
cross(time,145859) 楼主用这个是想表达 时间大于等于145859 吗?这么写好象有些问题
如果楼主刚接触金字塔,推荐楼主看一下金字塔“帮助”菜单下的教程
楼主的这个程序已经写的很不错了,只是有的地方考虑的不全面
提供给楼主一个前30分钟的突破示例,跟楼主的雷同,仅供参考
30突破
//开盘后前三十分钟最高最低价突破
//一天交易一次
//适用于1分钟周期
variable: cs=0;//控制一天交易1次
M:=BARSLAST(DATE<>REF(DATE,1) )+1; //当日的K线数目
h30:=VALUEWHEN(TIME<=093000,HHV(HIGH,M));
l30:=VALUEWHEN(TIME<=093000,LLV(LOW,M));
//建立多头进场条件
long:=CLOSE>h30 AND TIME<145500 AND TIME>093000;
if long then
begin
sellshort(holding < 0, 0, market);//平空
buy(holding = 0, 1, market);//开多
cs:=1;
end
//建立空头进场条件
short:=CLOSE<l30 AND TIME<145500 AND TIME>093000;
if short then
begin
sell(holding > 0, 0, market );//平多
buyshort(holding = 0, 1, market );//开空
cs:=1;
end
//收盘前2分钟平仓
if time >= 145800 then
begin
sell(holding > 0, 0, MARKET);
sellshort(holding < 0, 0, MARKET);
end
if time=closetime(0) cs:=0;//收盘时,对CS赋值为0,保证第2天满足条件时依然开仓一次