我想撰寫一個無條件買入,
停損N%的交易策略。
但是我發現回測時
常常有賣出後1分鐘馬上進場
又再隔了1分鐘馬上賣出的訊號(請看附件檔案)
想問使用日頻率回測
如何設定當天賣出後不再進場?
以下是程式碼:
// 宣告變數
vars: myEntryPrice(0), myStopLossPrice(0), lastExitDate(0);
// 無條件進場,使用市價買入
if position = 0 and date <> lastExitDate then begin
setposition(1, market);
myEntryPrice = close; // 記錄進場價格
myStopLossPrice = myEntryPrice * 0.85; // 設置停損價為進場價的85%
end;
// 檢查是否達到停損條件
if position = 1 and close <= myStopLossPrice then begin
setposition(0); // 停損出場
lastExitDate = date; // 記錄賣出日期
end;
7 評論