percenttrailing止盈語句代碼如下:
[IntrabarOrderGeneration=true];
input:target(10),Percent(30);//,BS(NumericSimple);
vars:intrabarpersist mp(0),intrabarpersist flagB(0),intrabarpersist flagS(0), intrabarpersist valueh(0),intrabarpersist valuel(999999);
once cleardebug;
mp=marketposition;
if mp<>mp[1] then
begin?
? ? ? ? valueh=0;
? ? ? ? valuel=999999;
? ? ? ? flagb=0;
? ? ? ? flags=0;
end;
if mp>0 and valueh<=h then
valueh=h;
if mp<0 and valuel>=l then
valuel=l;
if (mp>0 and valueh-entryprice>target) then
flagB=1;
if mp<0 and entryprice-valuel>target then
flags=1;?
if mp=1 and flagB=1 then
sell("L_trailing") next bar at valueh-Percent*(valueh-entryprice)/100 stop;
if mp=-1 and flagS=1 then
buytocover("S_trailing") next bar at??valuel+percent*(entryprice-valuel)/100 stop;
我在實際使用時遇到了一個情況:市場價格變動太快,導致止盈指令發出后沒有成交。
我的訴求是用at market的方式下單,請問老師應該如何改動上述語句才能達到目的,謝謝!
(來自舊論壇客戶,spacehk)
?
?
@evenrich
非bar內模式,非精細資料歷史回測沒有問題!
但是這段代碼在非bar內模式下有一個小問題:因為非bar內模式下,策略的計算是每根bar收盤時進行的,并且判斷委托單執行條件是否滿足,而這段代碼中是需要判斷多頭開倉以來的最高價與進場價之差是否大于目標價格(以多頭為例),然后再委托追蹤止損單,但是對“多頭開倉以來的最高價與進場價之差是否大于目標價格”不會太及時,因為這個條件可能在bar的形成過程中就滿足了,導致判斷延遲。
?
當然可以的,帖子”MC回測邏輯及條件單(包括set關鍵字)的執行邏輯“中有詳細介紹哦
?
當然可以的,帖子”MC回測邏輯及條件單(包括set關鍵字)的執行邏輯“中有詳細介紹哦