版主擬好,請問一下我的自動停利停損程式怎麼不會執行,策略部位四個選項都試過了,都不會執行,不管是手動下單,還是自動下單,都不會執行,可以幫我看一下是哪裡有問題嗎?
// OCO 停利停損 (只針對新進場單)
// -----------------------------------
input: profit_points(500, "停利(點)");
input: loss_points(300, "停損(點)");
vars: entry_price(0), last_filled(0);
// 初始化
if CurrentBar = 1 then
last_filled = Filled;
// 偵測新進場
if Filled <> last_filled then begin
// 只記錄最新進場均價,不處理舊單
entry_price = FilledAvgPrice;
last_filled = Filled;
end;
// 有新單在跑才做判斷
if Filled > 0 then begin
// 多單停利
if profit_points > 0 and C >= entry_price + profit_points then
SetPosition(0, label:="多單停利出場");
// 多單停損
if loss_points > 0 and C <= entry_price - loss_points then
SetPosition(0, label:="多單停損出場");
end
else if Filled < 0 then begin
// 空單停利
if profit_points > 0 and C <= entry_price - profit_points then
SetPosition(0, label:="空單停利出場");
// 空單停損
if loss_points > 0 and C >= entry_price + loss_points then
SetPosition(0, label:="空單停損出場");
end;
4 評論