各位大神 小編好
我有一個策略能成功編譯,回測時卻沒有任何數據 (我用逐筆洗價)
麻煩幫我看看哪裡可能出了問題謝謝
// 宣告參數
input: BigOrderRatio(0.1, "大單量佔昨日成交比例"),
LongStopLoss(5, "多方停損百分比"),
LongTakeProfit(5, "多方停利百分比"),
ShortStopLoss(1, "空方停損百分比"),
ShortTakeProfit(1, "空方停利百分比"),
MaxPrice(100, "最高股價限制");
var:intrabarpersist EntryPrice1(0),
intrabarpersist ShortEntryPrice(0),
intrabarpersist YesterdayVolume(0),
intrabarpersist LastVolume(0),
intrabarpersist LastPosition(0),
intrabarpersist LastTime(0),
intrabarpersist DayFirstTick(1), // 用於標記當天第一筆
intrabarpersist FirstTickProcessed(0); // 用於確認第一筆處理完成
// 設定回測區間
settotalbar(3);
setbarback(3);
// 重置日期變更判斷
if Date <> Date[1] then
begin
DayFirstTick = 1;
FirstTickProcessed = 0;
end;
// 取得昨日成交量 (用時間來判斷新的一根K棒開始)
if Time <> LastTime then
begin
YesterdayVolume = Volume[1];
LastTime = Time;
end;
// 處理第一筆搓合單
if DayFirstTick = 1 then
begin
LastVolume = Volume;
DayFirstTick = 0;
FirstTickProcessed = 1;
return;
end;
// 定義交易條件
condition1 = Volume - LastVolume > YesterdayVolume * BigOrderRatio; // 單筆成交量超過昨日總量的1/10
condition2 = Close <= MaxPrice; // 股價需小於100元
condition3 = CurrentTime >= 90000 and CurrentTime <= 120000; // 交易時間在9:00-12:00之間
condition4 = FirstTickProcessed = 1; // 確保第一筆已經處理完成
// 更新LastVolume
LastVolume = Volume;
// 多方進場邏輯
if position = 0 and condition1 and condition2 and condition3 and condition4 then
begin
EntryPrice1 = Close;
LastPosition = 1;
setposition(1, market, label:="多方進場-大單");
end;
// 多方出場邏輯
if position = 1 then
begin
// 停損 (5%)
if Close <= EntryPrice1 * (1 - LongStopLoss / 100) then
begin
LastPosition = 0;
setposition(0, market, label:="多方停損");
end;
// 停利 (5%)
if Close >= EntryPrice1 * (1 + LongTakeProfit / 100) then
begin
LastPosition = 0;
setposition(0, market, label:="多方停利");
end;
end;
// 空方進場邏輯 (融券)
if position = 0 and condition1 and condition2 and condition3 and condition4 then
begin
ShortEntryPrice = Close;
LastPosition = -1;
setposition(-1, market, label:="空方進場-大單");
end;
// 空方出場邏輯
if position = -1 then
begin
// 停損 (1%)
if Close >= ShortEntryPrice * (1 + ShortStopLoss / 100) then
begin
LastPosition = 0;
setposition(0, market, label:="空方停損");
end;
// 停利 (1%)
if Close <= ShortEntryPrice * (1 - ShortTakeProfit / 100) then
begin
LastPosition = 0;
setposition(0, market, label:="空方停利");
end;
end;
// 收盤時間強制平倉
if position <> 0 and CurrentTime > 120000 then
begin
LastPosition = 0;
setposition(0, market, label:="收盤平倉");
end;
3 評論