以下程式碼再回測時 會大量的不正常出場 , 我只是希望他加碼但是他會變成出場指令 , 我附上 加碼這段程式碼
max_pos = IntPortion((max_order_price * 10000) / (Close * 1000)); //加碼條件 if position > 0 and filled > 0 and close*filled*1000 >= (filledavgPrice*filled*1000)+add_profit then begin SetPosition(max_pos, label:="獲利加碼"); end;
目前爬文我了解到 回測跟實單應該是有不同的 , 平時用在實單的程式碼要做回測,是有部分需要修改的
請問哪裡可以爬文到這相關的內容呢, 想盡可能的模擬真實情況 , 以下我附上全部程式碼 謝謝各位的幫忙!!
//參數設定 input: order_price(4, "下單金額(萬)"), stop_loss(1500, "停損金額"), add_profit(1500, "獲利金額加碼條件"), max_order_price(10, "加碼後總金額(萬)"); //變數宣告 vars: order_size(0), add_order_size(0), max_pos(0), highest_20(0), lowest_10(0), stop_price(0), profit(0); //計算指標 highest_20 = Highest(High, 20)[1]; lowest_10 = Lowest(Low, 10)[1]; //計算部位大小 order_size = IntPortion((order_price * 10000) / (Close * 1000)); max_pos = IntPortion((max_order_price * 10000) / (Close * 1000)); //進場邏輯 //這裡加上position = 0 and FIlled= 0 的條件更警慎,並漲幅超過3%才算有效突破 if position = 0 and FIlled= 0 and Close Cross Over highest_20 and close>=close[1]*1.03 then begin SetPosition(order_size, label:="突破20日高進場"); end; //停損條件 if position > 0 and filled > 0 then begin stop_price = ((filledavgPrice*1000*filled*1.003)-stop_loss) / (filled*1000); //這裡用filledavgPrice抓庫存均價會更準確,這裡的公式為計算要停損的股價 if close < stop_price then SetPosition(0, label:="停損出場"); end; //加碼條件 if position > 0 and filled > 0 and close*filled*1000 >= (filledavgPrice*filled*1000)+add_profit then begin SetPosition(max_pos, label:="獲利加碼"); end; //停利條件 if position > 0 and filled> 0 and Close < lowest_10 then begin SetPosition(0, label:="跌破10日低出場"); end; //顯示資訊 print("停損價", stop_price, "20日高", highest_20, "10日低", lowest_10, "滿倉", max_pos);
4 評論