停損出場條件不會觸發的腳本....

  •   82 
  • 最後發表   菜鳥  2 天前
菜鳥 發文於   2025/06/10

小編你好!

以下出場腳本,在實測時發現停損出場條件不會觸發,不知道能否指導一下該如何修改?  謝謝!!

//出場

if Filled <0 then begin 

  if  CurrentTime>=CloseTime then begin 

  SetPosition(0); { 時間出場 } 

      end else   

{ 依照成本價格設定停損/停利: 請注意當作空時, 判斷是否獲利的方向要改變 } 

         if  Close>=minList(FilledAvgPrice*(1+(0.01*SL)),CloseD(1)*(1+ (UPSL*0.01))) then begin 

             SetPosition(0); { 停損出場 } 

            if FilledRecordCount>=1 and filled=0  then  RaiseRunTimeError("已執行出場完成,中止策略") ;  

             end else   

                 if  close>FilledAvgPrice  and Position<>Filled then cancelAllOrders

                     else 

                 setposition(0,maxList(Getfield("參考價", "D")*0.915,FilledAvgPrice*(1-(0.01*PT))));{預掛停利出場 };

end;

排序方式: 標準 | 最新
虎科大許教授 發文於   2025/06/10

檢查看看下列條件是否滿足:

Close>=minList(FilledAvgPrice*(1+(0.01*SL)),CloseD(1)*(1+ (UPSL*0.01)))

 

菜鳥 發文於   2025/06/10

許教授您好!

我想寫的是"close>=虧損5%或日漲幅7%之較低價者,則空單停損出場。實際模擬時發生過漲到觸及漲停板,策略沒有停損。

不知道您問的是這個嗎? 

虎科大許教授 發文於   2025/06/10

input: SL(5,"停損趴數");

input: UPSL(7,"上漲趴數");

condition1=Close>=minList(FilledAvgPrice*(1+0.01*SL),GetField("參考價"),"D")*(1+0.01*UPSL));

當虧損超過5%或漲幅超過7%,condition1為True。

菜鳥 發文於   2025/06/11

許教授您好!

請問    if  Close>=minList(FilledAvgPrice*(1+(0.01*SL)),CloseD(1)*(1+ (UPSL*0.01))) then begin 

             SetPosition(0);

            if FilledRecordCount>=1 and filled=0  then  RaiseRunTimeError("已執行出場完成,中止策略") ;  

             end else ...........

跟        condition1=Close>=minList(FilledAvgPrice*(1+0.01*SL),GetField("參考價"),"D")*(1+0.01*UPSL));

     if  condition1 then  begin 

             SetPosition(0);

            if FilledRecordCount>=1 and filled=0  then  RaiseRunTimeError("已執行出場完成,中止策略") ;  

             end else ...........

兩者的差異會造成不同結果嗎? 請教之中有甚麼眉角呢?  感謝您不厭其煩地幫助我們~

虎科大許教授 發文於   2025/06/11

兩者基本上是一樣的。用參考價取代CloseD(1)會比較週延。你目前提供的程式應該可以停損,問題可能出在其他地方。

發表回覆
Close