def f0_11(st_0, magic):
l_count_8 = 0
for i in range(OrdersTotal() – 1, -1, -1):
if OrderSelect(i, SELECT_BY_POS, MODE_TRADES):
if OrderSymbol() != Symbol() or OrderMagicNumber() != magic:
continue
if OrderSymbol() == Symbol() and OrderMagicNumber() == magic:
if st_0 == “buy” and OrderType() == OP_BUY:
l_count_8 += 1
if st_0 == “sell” and OrderType() == OP_SELL:
l_count_8 += 1
return l_count_8
def f0_13(as_0, magic):
ld_8 = 0
ld_16 = 0
for i in range(OrdersTotal() – 1, -1, -1):
if OrderSelect(i, SELECT_BY_POS, MODE_TRADES):
if OrderSymbol() != Symbol() or OrderMagicNumber() != magic:
continue
if OrderSymbol() == Symbol() and OrderMagicNumber() == magic:
if as_0 == “buy” and OrderType() == OP_BUY:
ld_8 += OrderOpenPrice() * OrderLots()
ld_16 += OrderLots()
if as_0 == “sell” and OrderType() == OP_SELL:
ld_8 += OrderOpenPrice() * OrderLots()
ld_16 += OrderLots()
if ld_16 != 0:
ld_8 = round(ld_8 / ld_16, 2)
return ld_8
这个因子计算持仓的平均价格,可以用来评估当前持仓的平均成本
以及在量化交易策略中用于风险管理和决策制定。