[疑問] Trailing Stop語法
如果想要到達100點 40% Trailing Stop, 但到300點後變成20% Trailing Stop,在MC語法中if marketposition <>0 then begin
setpercenttrailing_pt(100,40);
if openpositionprofit >= 300 then
setpercenttrailing_pt(300,20);
end;
最後只認到300點 20%... 那應該要如何寫 ?_____?
求教 T^T
同一訊號中有多個setpercenttrailing, 只有最後一個有效, 其他set系列關鍵字也是
可參考這個寫法, 點數,%, 你自己改{:9_582:}
//set ppfloor and ppratio values to protect profit
Var: ppfloor1(1000); //don’t invoke exit 1 until $1000 profit level is reached
Var: ppfloor2(2000); //don’t invoke exit 2 until $2000 profit level is reached
Var: ppfloor3(3000); //don’t invoke exit 3 until $3000 profit level is reached
Var:ppratio(0); //depends on maxpositionprofit
Var:ppratio1(.60); //profit exit 1 keep ratio – keep 60% of maximum profit
Var:ppratio2(.75); //profit exit 2 keep ratio – keep 75% of maximum profit
Var:ppratio3(.90); //profit exit 3 keep ratio – keep 90% of maximum profit
If maxpositionprofit>=ppfloor1 then ppratio=ppratio1;
If maxpositionprofit>=ppfloor2 then ppratio=ppratio2;
If maxpositionprofit>=ppfloor3 then ppratio=ppratio3;
If maxpositionprofit>=ppfloor1 then begin
if (openpositionprofit/maxpositionprofit)<ppratio then begin
Sell next bar at market;
Buy To Cover Next bar at market;
End;
End;
謝謝你!!
不過因為trailing stop是intrabar的, 這個語法如果intrabarordergeneration=false只能做到next bar, 我在嘗試
if marketposition<>0 then begin
setstopcontarct;
setpercenttrailing(100, 40)
var:ppfloor(3000), ppratio(.90);
If maxpositionprofit>=ppfloor then begin
if (openpositionprofit/maxpositionprofit)<ppratio then
Sell next bar at market;
end;
end;
不過假設在0.9平倉後, 原本的setpercenttrailing應該已經在系統裡 不知道會不會有問題. 平倉後, 原本的setpercenttrailing會取消的
另外, 把setpercenttrailing(100, 40); 改為setpercenttrailing_pt(100,40);
點數用setpercenttrailing_pt, 金額用setpercenttrailing
setpercenttrailing_pt(100,40) 是到達100點 拉回40%
setpercenttrailing(100, 40) 是到達$100 拉回40% 是的, 漏打了_pt沒錯..哈哈
用了幾天應該沒什麼大問題, 拉回幅度大的話有setpercenttrailing_pt做intrabar, 拉回慢的話就有上面寫的sell next bar, 保護盈利算是挺周全的~
頁:
[1]