计算当前持仓多单中亏损的多单数量

楼主  收藏   举报   帖子创建时间:  2019-05-05 14:37 回复:0 关注量:222
该函数计算当前持仓的多单中亏损多单的数量。

  1. double GetOrderLot(){
  2. for (int i=0; i<OrdersTotal(); i++){
  3. if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)){double lot = OrderLots();}}
  4. if(lot==0){lot=Lots;}else{lot=lot+Lots;}
  5. return(lot);}
  6. 以此可以计算你的亏损的多单的张数
  7. int CheckOpenBUYPositions()
  8. {
  9. int cnt, NumPositions;
  10. int NumBuyTrades, NumSellTrades; // Number of buy and sell trades in this symbol
  11. NumBuyTrades = 0;
  12. NumSellTrades = 0;
  13. for(cnt=OrdersTotal()-1;cnt>=0;cnt--)
  14. {
  15. OrderSelect (cnt, SELECT_BY_POS, MODE_TRADES);
  16. if ( OrderSymbol() != Symbol()) continue;
  17. if ( OrderMagicNumber() != QQ) continue;
  18. if(OrderType() == OP_BUY &&OrderProfit() < 0)
  19. {
  20. NumBuyTrades++;
  21. }
  22. return (NumBuyTrades);
  23. }
  24. }
打赏