交易條件加上
asset-ref(asset,todaybar)<=0
variable:n=0;//n計算虧損總點數
if 平多條件1 and 持倉判斷 then begin
sell(1,0,下單價位);
if numprofit(1)<0 then n:=n+(exitprice-enterprice)*手數1;//手數1是開倉手數
end
if 平空條件1 and 持倉判斷 then begin
sellshort(1,0,下單價位);
if numprofit(1)<0 then n:=n+(enterprice-exitprice)*手數2;//手數2也是開倉手數
end
//這只是簡單的例舉了開多開空兩種情況,如果公式里面有多個開多開空語句,那么就要按照上面的方法多寫幾遍
s1:=n*MULTIPLIER;//虧損總金額
if openprofit>0 then
ss:=abs(s1)/abs(enterprice-c)/MULTIPLIER;//在盈利的情況下,把虧損總金額除以當前的開平價差,再除以合約單位,得出需要多少手,可能會有小數點
tt:=floor(ss);//把求出的手數向下取整,則得出平掉虧損持倉需要平掉當前多少手