討論區列表
MultiCharts
一般模式
討論串模式
標題:
[發問] 手單進場,自動加碼、停損、出場
by 2023-10-25 14:33:14
0
暱稱:
有為青年
信箱:不顯示
成就:發文(0) / 回文(0) / 推薦(0)
您好
我參考討論區的範例,整合下列的程式,以均線來進出場,請問有無錯誤地方須修正,請大神指導,謝謝。
PS:範例的pDate=d+
19000000,但也有人沒放,哪個是對的??
-----------------------------------------------------------------------------------------------------------
Inputs: pDate(20130117), pTime(0912), pPrice(7760), EntryMode("B"), pSL(5);
var double stopLossPrice; // 停損價格
var int additionalEntry = 0; // 加碼計數
var double totalProfitPoints = 0; // 總利潤點數
var bool exitConditionMet = false; // 出場條件觸發標誌
var bool profitLockConditionMet = false; // 盈利鎖定條件觸發標誌
if d = pDate and t = pTime and EntriesToday(D) = 0 then begin
// 如果日期、時間條件符合且今天還未進場,進入以下處理
if EntryMode = "B" then begin
// 如果是多單策略
if pPrice > Average(C, 20) then begin
// 如果進場價格高於20日均線,則進行多單進場
buy("B") next bar pPrice limit;
stopLossPrice = Lowest(low, 5);
setstoploss(stopLossPrice);
end else begin
// 如果進場價格不高於20日均線,設定出場條件觸發標誌
exitConditionMet = true;
end;
end else if EntryMode = "S" then begin
// 如果是空單策略
if pPrice < Average(C, 20) then begin
// 如果進場價格低於20日均線,則進行空單進場
sell("S") next bar pPrice limit;
stopLossPrice = Highest(high, 5);
setstoploss(stopLossPrice);
end else begin
// 如果進場價格不低於20日均線,設定出場條件觸發標誌
exitConditionMet = true;
end;
end;
end;
if EntryMode = "B" then begin
// 如果是多單策略
if C > Average(C, 10) and Close > Average(C, 10) and H - pPrice >= 20 and additionalEntry = 0 then begin
// 如果價格條件符合且還未加碼,則進行多單加碼
buy("AdditionalB") next bar at market;
additionalEntry = 1;
end;
end else if EntryMode = "S" then begin
// 如果是空單策略
if C < Average(C, 10) and Close < Average(C, 10) and pPrice - L >= 20 and additionalEntry = 0 then begin
// 如果價格條件符合且還未加碼,則進行空單加碼
sellshort("AdditionalS") next bar at market;
additionalEntry = 1;
end;
end;
// 新增的保利條件
if totalProfitPoints >= 3 and additionalEntry = 0 then begin
// 如果總利潤點數達到3點且尚未加碼,設定盈利鎖定條件觸發標誌
profitLockConditionMet = true;
end
if EntryMode = "B" then begin
// 如果是多單策略
if (C < Average(C, 20) or totalProfitPoints >= 300) and not exitConditionMet and not profitLockConditionMet then begin
// 如果出場條件符合且未觸發出場條件或盈利鎖定條件,則進行多單出場
sell("ExitB") next bar at market;
end;
end else if EntryMode = "S" then begin
// 如果是空單策略
if (C > Average(C, 20) or totalProfitPoints >= 300) and not exitConditionMet and not profitLockConditionMet then begin
// 如果出場條件符合且未觸發出場條件或盈利鎖定條件,則進行空單出場
buytocover("ExitS") next bar at market;
end;
end;
totalProfitPoints = (High - pPrice) + (MarketPosition * (C - EntryPrice));
第一頁
上一頁
下一頁
最後頁
討論區列表
MultiCharts
MultiCharts
│
討論區
│
會員專區
│
教學講座
│
支援與服務
│
產品購買
│
申請試用
All rights for MultiCharts Trading Software are reserved by MultiCharts, LLC
凱衛資訊股份有限公司 營利事業統一編號(21261212) 著作權所有 本網站最佳瀏覽解析度為 1024 x 768
隱私權政策
│
網站安全政策
│
著作權說明
若不清楚點選圖片更新驗證碼
註冊帳號
忘記密碼
解除鎖定