在自動交易設定1分K逐筆洗價, 若是 在一根K內多次觸發多單"階梯式"停利價 比如說 50元 賣出一張, 55元再賣出一張 如何的程式寫法或設定才能確保程式 在 50元 時只會執行一次 Sell(1, Market) ; ? 就像策略雷達的"K棒內單次觸發" ??
自動交易設定逐筆洗價, Filled or Position 值的變化
- 201
- 最後發表 JACK5665.TW 2021 六月 02
JACK5665.TW
發文於
2021/06/01
XQ小幫手
發文於
2021/06/02
Hello JACK5665.TW,
您可以設定變數來控制,或是用 SetPosition 來控制總張數。
var: IntrabarPersist exit_count(0);
if GetInfo("IsRealTime") = 1 and close = 50 and exit_count = 0 then begin
sell(1, Market);
exit_count = 1;
end;
//GetInfo("IsRealTime") 是確保運作在即時才會更動變數。
if GetInfo("IsRealTime") = 1 and close = 55 and exit_count = 1 then begin
sell(1, Market);
exit_count = 2;
end;
IntrabarPersist 的說明可以參考連結。
如果是用 SetPosition 的話,假設您原本的 Position 是 2 的話
if position = 2 and close = 50 then setposition(1, market);
//只要價格是50且position為2的狀況下就會將position調整為1
if position = 1 and close = 55 then setposition(0, market);
1 評論