教授 小編 您好
請問一下.我目前遇到的問題.止盈止損沒辦法到未出清.我回測+實戰常常出現一進場不到10秒就出清.我查看當下K棒也沒有到止盈止損觸發...常常虧損0.0幾%出清
ˊ這是我的腳本麻煩幫我看看 謝謝
// === 進場條件 ===
if (TimeNow >= StartTradeTime) and (TimeNow < StopTradeTime) and (Position = 0) then begin
// === 均線偏離過大時,不進場 ===
Vars: PriceDeviation(0), DeviationThreshold(0.015);
PriceDeviation = (C - ShortMA) / ShortMA;
if AbsValue(PriceDeviation) > DeviationThreshold then begin
Print("? 均線偏離過大,取消進場!");
end else begin
// === 多單進場條件 ===
if (ShortMA > MidMA) and (ShortMA[1] <= MidMA[1]) and (C > ShortMA) then begin
SetPosition(PositionSize, market);
MyEntryPrice = C;
Print("? 進場多單,價格:", MyEntryPrice);
end;
end;
end;
// === 多單止盈(即時執行) ===
if Position > 0 then begin
if (c >= MyEntryPrice * 1.012) then begin
Print("? 達到止盈 1.5%,立即平倉!");
SetPosition(0, market);
end;
end;
// === 多單止損(等待 K 棒收盤確認) ===
if Position > 0 then begin
if (c <= MyEntryPrice * 0.98) then begin
SetPosition(0, market);
end;
end;
2 評論