許教授,
假若我的部位是不同訊號分次建倉,那目前的寫法是不是只會計算第一筆交易的停損價格?
// -------- 停損邏輯 (多單) --------
if Position > 0 and Filled > 0 then begin
// 計算過去 13 根K棒的最低價
if not long_stop_loss_initialized then begin
long_stop_loss_price =Lowest(Low[1], 13) ; // 只在建倉時設定一次
long_stop_loss_initialized = true; // 初始化後設置標誌
end;
想請教您如果想要每次新增倉位都可以用最新的平均成本設定停損價,應該要如何修改呢?
另外,移動停利的部分是不是也有需要修正的地方,因為夜盤測試
input:
profit_drawback_point_13(4, "當上漲超過 13 點時的回撤點數"),
profit_drawback_point_26(10, "當上漲超過 26 點時的回撤點數"),
profit_drawback_point_39(13, "當上漲超過 39 點時的回撤點數");
// -------- 移動停利邏輯 (多單) --------
if Position > 0 and Filled > 0 then begin
// 停利邏輯:當獲利達到26點時啟動移動停利
if max_profit_point = 0 and Close >= FilledAvgPrice + 26 then
max_profit_point = High; // 啟動移動停利
// 設定回撤點數
if max_profit_point > 39 then
current_drawback_point = profit_drawback_point_39
else if max_profit_point > 26 then
current_drawback_point = profit_drawback_point_26
else if max_profit_point > 13 then
current_drawback_point = profit_drawback_point_13;
// 計算移動停利價格
long_trail_stop_price = max_profit_point - current_drawback_point;
// 停利回撤判斷,若達到回撤條件則平倉
if Close <= long_trail_stop_price then begin
SetPosition(0); // 停利平倉
max_profit_point = 0; // 重置最大獲利點
long_stop_loss_initialized = false; // 停利後重置標誌
end
else if Close > max_profit_point then begin
// 更新最大獲利點,若價格上升,更新停利條件
max_profit_point = High;
end;
end;
自動交易有在
20241115 01:37:46 建立多單 22755
然後在
20241115 01:50:01 多單移動停利賣出 22729
可是期間高點已經有達到 22768,應該是要執行profit_drawback_point_13(4, "當上漲超過 13 點時的回撤點數")
於22764時執行出場,可是實測結果卻跟理想中有出入,至少也希望能執行原本多單停損// 當價格上漲13點時,將止損設為進場價格+8點的邏輯,
因此想請教您,不知道是不是哪邊的寫法與邏輯有錯誤,需要調整呢?
8 評論