timecondition1 = time>0930 and time< 1455;
timecondition2 = time>2130 and Time< 2255;
timecondition = timecondition1 or timecondition2;
hltime1 = time > 0905 and Time < 0915;{2high2sell or 2low2buy time}
hltime2 = time > 2105 and time < 2115;
hltime = hltime1 or hltime2;
//filter net model
ma1 = Average(close,5) of data2;
ma2 = Average(close,10)of data2;
filtercondition1 = ma1 > ma2 and Close > minlist(ma1,ma2); //bulltrend
filtercondition2 = ma1 < ma2 and Close < maxlist(ma1,ma2); //beartrend
//strategy model-{Aberration}
{first enter}
ma = Average(price1,35);
std = StandardDev(price1,35,1);
var1 = ma + 2*std;
var2 = ma - 2*std;
buycondition = price1 > var1;
sellcondition = price1 < var2;
{second entry}
condition1 = close[1] < var2[1] and Close > var2;
condition2 = Close[1] > var1[1] and Close < var1;
{buy/sell model}
if mp=0 then begin
if filtercondition1 and buycondition and timecondition then begin
buy("breakout-buy") 1 shares next bar at market;
end;
if filtercondition1 and condition1 and hltime then begin
buy("2low-buy") 1 shares next bar at market;
end;
if filtercondition2 and sellcondition and timecondition then begin
sellshort("breakdown-sell") 1 shares next bar at market;
end;
if filtercondition2 and condition2 and hltime then begin
sellshort("2high-sell") 1 shares next bar at market;
end;
end;
//strategy-exit
if mp=1 and Close < ma and Close-entryprice >= 5 then sell("long-exit") 1 shares next bar at market;
if mp=-1 and Close > ma and entryprice - Close>= 5 then buytocover("short-exit") 1 shares next bar at market;
//time-exit model
if mp<>0 then begin
if Time>1455 and time <1500 then begin
if mp=-1 then buytocover("short-exit at 14:55")1 shares next bar at market;
if mp= 1 then sell("long-exit at 14:55")1 shares next bar at market;
end;
if Time>2255 and time <2300 then begin
if mp=-1 then buytocover("short-exit at 22:55") 1 shares next bar at market;
if mp= 1 then sell("long-exit at 22:55") 1 shares next bar at market;
end;
end;
//set-stop model
if mp<>0 then begin
SetStopContract;
SetProfitTarget(150);
SetPercentTrailing(140,50);
end;
//check model {if strategy has problem,use print check}
{print(ma1);}作者: 咸鱼 时间: 2021-3-31 21:16