想請問一個語法問題,假設我有三個多單進場條件(A、B、C),每個進場條件也各有三種出場(平倉,不翻單)方式(a1、a2、a3、b1、b2、b3、c1、c2、c3)
我想做到的是,指定在A條件進場,a2條件出場時,才在下一根K棒進場放空(SE),以下是我的語法:
vars:A(false),current_status(0);
if condition1 and current_status=0 then begin buy("A") next bar at market; A=true; end;
if marketposition=1 then begin if condition4 then sell("a1") from entry("A") next bar at XXX stop; if condition5 then sell("a2") from entry("A") next bar at XXX stop; if condition6 then sell("a3") from entry("A") next bar at XXX stop; end;
//翻單語法 var:SE(false); if A=ture and condition5 then begin sell("a2") from entry("A") next bar ar XXX stop; SE=true; current_status=0; end; if marketposition=0 then begin if SE=true and current_status=0 then sellshort("SE") next bar at market; end;
藍色部份是我的翻單語法,寫出來編譯ok,確實有在A進場、a2條件出場的下一根反空,但是卻也有在B進場、C進場的條件下,翻單放空, 不曉得是語法邏輯哪裡有錯,因為我想做到的是只有在A進場a2條件出場時,才會觸發SE空單。
懇請小秘書協助解決這個難題...感激不盡,謝謝!!!
這段如果是要專做進場 A 的出場,
改成下面這樣就好?
if marketposition=1 and A = true then begin if condition4 then sell("a1") from entry("A") next bar at XXX stop; if condition5 then sellshort("a2") from entry("A") next bar at XXX stop; if condition6 then sell("a3") from entry("A") next bar at XXX stop; end;
如果要用你原本的程式碼,
if marketposition=0 then begin if SE=true and current_status=0 then sellshort("SE") next bar at market; end;
這段裡的 SE 變成 True 之後就一路 True 下去了,當然等於沒作用,
要想辦法讓他回歸 False 有滿足進場 A 及Condition 5 再變 True
謝謝 @虛心求教的回覆!
有試過這個寫法,但用from entry......語法的出場無法直接反手放空~
if marketposition=1 and A = true then begin if condition4 then sell("a1") from entry("A") next bar at XXX stop; if condition5 then sellshort("a2") from entry("A") next bar at XXX stop; if condition6 then sell("a3") from entry("A") next bar at XXX stop;
已使用這個方法完成了~謝謝指教!