下為自己寫的一個簡單自動交易策略
主要想說每天最高價出現時,做放空
但跑回測始終都是無交易,不確定邏輯對不對
希望小幫手幫忙debug
input:start(1,"開啟交易"), out(2,"開啟平倉");
var: _stocktype(true), barcount(0), hc(0);
if IsSessionFirstBar then begin
barcount = 0;
hc=0;
end;
if Date<>Date[1] then begin
barcount+=1;
end;
if barcount<> 0 then
begin
if (barcount=1 and v=0) then //開盤緩搓
begin
if barcount>=2 then
begin
hc=Fasthighestbar(H,barcount-2);//當天最高價的k棒
end
else //一般狀況
begin
hc=Fasthighestbar(H,barcount);//當天最高價的k棒
end;
end;
end;
condition1 = time > 090000 and time < 093000
and getField("收盤價", "D")[1] = getField("漲停價", "D")[1]
and hc = 0 and barcount>=2
and _stocktype = GetSymbolInfo("買賣現沖")
and close>10
and close<200;
//十字
if start=1 then begin
if barfreq<> "Min" or barinterval <> 1 then return;
if condition1 then setposition(-1, market);
end;
if out=2 then begin
input: exit_period(15, "收盤前N分鐘平倉");
var: market_close_condition(true); { 是否已經進入收盤階段 }
market_close_condition = EnterMarketCloseTime(exit_period);
condition2 = close>GetField("收盤價", "D")[1]*1.075;
if filled <> 0 and position <> 0 then begin
if (market_close_condition or condition2 or close = GetField("跌停價", "D")) then begin
setposition(0, GetField("漲停價", "D"));
end;
end;
end;
 
            
        
        
        
            
3 評論