指令沒有觸發

  •   66 
  • 最後發表   34264331  2025 七月 02
34264331 發文於   2025/06/27

If Position <> lastPos Then Begin

    print("=== 倉位變化偵測 ===");

    print("時間=", NumToStr(date,0),NumToStr(Time,0), "倉位=", Position, ", 平均成交價=", NumToStr(FilledAvgPrice, 2));

    lastPos = Position;

End;

 

if filled  > 0 and  stopgain[1] <> stopgain then begin

 stopgain = filledAvgPrice+100;

 setposition(0,stopgain);

 print ("stopgain price =", stopgain,stopgain[1] );

end;

if filled < 0  and stopgain[1] <> stopgain then begin

 stopgain = filledAvgPrice-100;

 setposition(0,stopgain);

 print ("stopgain price =", stopgain,stopgain[1]);

end;
下面的stop gain 有時無法打印

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

你的print指令要在符合stopgain[1] <> stopgain條件才會打印,若兩者相等,就不會打印。

34264331 發文於   2025/06/27

問題是指令在跑很多次時會出現很多版本(用的都是同一腳本)版本1 正常

版本2:stopgain[1] = stopgain 指令還會觸發= =?

截圖圖片

版本3:直接略過

截圖圖片

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

若你只希望平倉時打印,則加入position控制:

if position > 0 and filled > 0  and stopgain[1] <> stopgain then begin

if position < 0 and filled < 0  and stopgain[1] <> stopgain then begin

34264331 發文於   2025/06/28

謝謝 但是為什麼明明條件不符合 他還會繼續執行,這才是最大的問題吧

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

那應該是你的stopgain變數宣告的時候沒有加intrabarpersist。

XS小編 發文於   2025/07/02

Hello 34264331,

 

小編補充,stopgain[1] 會是 "上一根" Bar 最後一次運算的數值,而非 "上一次" 運算的數值。

細節可以參考 IntraBarPersist 的說明。

另外即使用 IntraBarPersist 來宣告,stopgain[1] 還是是 "上一根" Bar的數值。

若需要前一次洗價的數值的話,可以用另一個 IntraBarPersist 的變數來保存。

發表回覆
Close