本帖最后由 技术006 于 2023-1-4 09:17 编辑
[PEL] 复制代码 //***********************************//交易系统//***********************************//
variable:nums:=0;
if bpkcond and holding<=0 then begin
sellshort(holding<0,0,thisclose);
buy(holding=0,lot,thisclose);
nums:=1;
end
if spkcond and holding>=0 then begin
sell(holding>0,0,thisclose);
buyshort(holding=0,lot,thisclose);
nums:=1;
end
////
多单回调:holding>0 and (底背离 or cross(ma1,c) or cross(0,j)) and enterbars>1;
空单回调:holding<0 and (顶背离 or cross(c,ma1) or cross(j,100)) and enterbars>1;
//多单回调:holding>0 and cross(0,j);
//空单回调:holding<0 and cross(j,100);
//
if nums<2 then begin
回调加多:buy(多单回调,lot,thisclose);
nums:=2;
end
if nums<2 then begin
回调加空:sell(空单回调,lot,thisclose);
nums:=2;
end
//
顶背离止盈卖1/2:sell(holding>0 and 顶背离 ,holding/2,thisclose);
底背离止盈买1/2:sellshort(holding<0 and 底背离 ,holding/2,thisclose);
//按照之前的写法,只要barslast(顶背离)>1成立,就会修改nums,//但是平仓语句中存在子条件,它不一定同时执行,从而造成之后的再次加仓。(其他几处同理,所以将子条件拆出来放在主干部分)
if barslast(顶背离)>1 and holding>0 and c<ma2 then begin
破ma1清多:sell(1,0,thisclose);
nums:=0;
end
if barslast(底背离)>1 and holding<0 and c>ma2 then begin
破ma1清空:sellshort(1,0,thisclose);
nums:=0;
end
if nums>=0 and holding>0 and c<ma2 then begin
破ma2清多:sell(1,0,thisclose);
nums:=0;
end
if nums>=0 and holding<0 and c>ma2 then begin
破ma2清空:sellshort(1,0,thisclose);
nums:=0;
end
|