Hello xqyi,
 
您可以用 position 和 filled 來限制策略的部位庫存,讓其不要連續進場/出場。
且腳本中 setposition 的交易指令本身就會決定進出場的數量,只要有所限制的話就不會發生部位庫存變為2的狀況。
舉例來說:
condition1 = close cross over average(close, 10);    //進場條件
condition2 = close cross under average(close, 10);   //出場條件
condition3 = filledavgprice > 0 and close >= filledavgprice *1.01;    //停利條件
 
if position = 0 and filled = 0 and condition1 then setposition(1, market);     //沒有部位庫存且滿足進場條件時買進1張
if position = 1 and filled = 1 and (condiiton2 or condition3) then setposition(0, market);    //有1張部位庫存時且符合停利或出場條件的話就平倉
 
這樣策略的執行商品就只會在符合條件後買進1張和賣出1張。
 
需注意的是啟動中的策略本身是獨立運作的,其他策略或手動交易對運作中的策略部位庫存是不會有影響的。
若策略啟動時要用當下的實際庫存來運作的話,可以將策略設定為依庫存或是自訂數值來調整。
             
                
1 評論