請問為什麼我這樣設定停損了,程式到了2%沒有幫我自動停損,而且漲超過6%的股票我應該也也設置不交易了呀,停損在自動交易那邊也是設定市價了,可是還是被鎖漲停,另外我設定只有9:30以前交易,可是在回測的時候常常會超過9.30還在交易,13:00也未必照著我的設定平倉
--------------------------------------------------------------------------
input: profit_percent(2.5, "停利(%)");
input: loss_percent(2, "停損(%)");
input: open_percent(2, "開盤漲幅(%)");
input: before_920_percent(5, "9:20之前漲幅(%)");
settotalbar(1); // 只考慮當日的開盤價
value3 = GetField("漲停價", "D") * 0.96;
var: entry_condition(false); // 進場條件
// 判斷開盤價漲幅是否小於2%
entry_condition = Open < Open[1] * (1 + 0.01 * open_percent);
if entry_condition then begin
// 只考慮9:20之前的價格資訊
settotalbar(20); // 15分鐘內的資訊
// 判斷9:20之前股價是否漲幅大於5%且價格在48元以下
entry_condition = XXOO(某條件) and
Time < 093000 ;
if entry_condition then begin
// 在這裡處理符合進場條件時的交易指令
// 例如 SetPosition(-1) 表示進行空頭交易
SetPosition(-6, AddSpread(Close, 4));
end;
end;
if Position = -6 and Filled = -6 then begin
if profit_percent > 0 and Close <= FilledAvgPrice*(1-0.01*profit_percent) then begin
SetPosition(0);
end else if loss_percent > 0 and Close >= FilledAvgPrice*(1+0.01*loss_percent) then begin
SetPosition(0);
end else if CurrentTime >130000 then begin SetPosition(0);
end;
end;
if Position = -5 and Filled = -5 then begin
if profit_percent > 0 and Close <= FilledAvgPrice*(1-0.01*profit_percent) then begin
SetPosition(0);
end else if loss_percent > 0 and Close >= FilledAvgPrice*(1+0.01*loss_percent) then begin
SetPosition(0);
end else if time >130000 then begin SetPosition(0);
end;
end;
if Position = -4 and Filled = -4 then begin
if profit_percent > 0 and Close <= FilledAvgPrice*(1-0.01*profit_percent) then begin
SetPosition(0);
end else if loss_percent > 0 and Close >= FilledAvgPrice*(1+0.01*loss_percent) then begin
SetPosition(0);
end else if time >130000 then begin SetPosition(0);
end;
end;
if Position = -3 and Filled = -3 then begin
if profit_percent > 0 and Close <= FilledAvgPrice*(1-0.01*profit_percent) then begin
SetPosition(0);
end else if loss_percent > 0 and Close >= FilledAvgPrice*(1+0.01*loss_percent) then begin
SetPosition(0);
end else if time >130000 then begin SetPosition(0);
end;
end;
if Position = -2 and Filled = -2 then begin
if profit_percent > 0 and Close <= FilledAvgPrice*(1-0.01*profit_percent) then begin
SetPosition(0);
end else if loss_percent > 0 and Close >= FilledAvgPrice*(1+0.01*loss_percent) then begin
SetPosition(0);
end else if time >130000 then begin SetPosition(0);
end;
end;
if Position = -1 and Filled = -1 then begin
// 依照成本價格設定停損/停利: 請注意當作空時, 判斷是否獲利的方向要改變
if profit_percent > 0 and Close <= FilledAvgPrice*(1-0.01*profit_percent) then begin
SetPosition(0);
end else if loss_percent > 0 and Close >= FilledAvgPrice*(1+0.01*loss_percent) then begin
SetPosition(0);
end else if time >130000 then begin SetPosition(0);
end;
end;












22 評論