该函数模块可以计算出多个同方向订单的平均成本价格,所谓平均成本价格也就是多个订单在这个价位盈亏为0.获取平均交易成本价格,后面需要对多个订单做止损或盈利修改就方便调用了。
- double AveragePrice(string as_0) {
- double ld_8 = 0;
- double ld_16 = 0;
- for (int l_pos_24 = OrdersTotal() - 1; l_pos_24 >= 0; l_pos_24--) {
- bool cg = OrderSelect(l_pos_24, SELECT_BY_POS, MODE_TRADES);
- if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
- if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
- if (as_0 == "buy") {
- if (OrderType() == OP_BUY) {
- ld_8 += OrderOpenPrice() * OrderLots();
- ld_16 += OrderLots();
- }
- }
- if (as_0 == "sell") {
- if (OrderType() == OP_SELL) {
- ld_8 += OrderOpenPrice() * OrderLots();
- ld_16 += OrderLots();
- }
- }
- }
- }
- ld_8 = NormalizeDouble(ld_8 / ld_16, Digits);
- return (ld_8);
- }
|