© 本贴为 wuwei 原创/首发,严禁抄袭!
最后由 wuwei 于 2024-6-23 17:08 编辑
1. 全面统计功能:该代码能够全面统计当前所有订单的数量、总手数、总盈亏、总手续费和总隔夜利息。
2. 实时更新:代码实时更新统计信息,确保交易者随时掌握最新的订单动态。
3. 简洁直观:结果通过日志和图表清晰显示,便于交易者快速获取关键信息。
- //+------------------------------------------------------------------+
- //| OrderStatistics.mq4 |
- //| Generated by ChatGPT |
- //| |
- //+------------------------------------------------------------------+
- #property strict
-
- // Order statistics structure
- struct OrderStats {
- int orderCount;
- double totalLots;
- double totalProfit;
- double totalLoss;
- double totalCommission;
- double totalSwap;
- };
-
- //+------------------------------------------------------------------+
- //| GetOrderStatistics function |
- //+------------------------------------------------------------------+
- OrderStats GetOrderStatistics() {
- OrderStats stats;
- stats.orderCount = 0;
- stats.totalLots = 0.0;
- stats.totalProfit = 0.0;
- stats.totalLoss = 0.0;
- stats.totalCommission = 0.0;
- stats.totalSwap = 0.0;
-
- for (int i = OrdersTotal() - 1; i >= 0; i--) {
- if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
- stats.orderCount++;
- stats.totalLots += OrderLots();
- stats.totalCommission += OrderCommission();
- stats.totalSwap += OrderSwap();
-
- double orderProfit = OrderProfit() + OrderSwap() + OrderCommission();
- if (orderProfit >= 0) {
- stats.totalProfit += orderProfit;
- } else {
- stats.totalLoss += orderProfit;
- }
- }
- }
-
- return stats;
- }
-
- //+------------------------------------------------------------------+
- //| Script program start function |
- //+------------------------------------------------------------------+
- void OnStart() {
- OrderStats stats = GetOrderStatistics();
-
- Print("Total Orders: ", stats.orderCount);
- Print("Total Lots: ", DoubleToStr(stats.totalLots, 2));
- Print("Total Profit: ", DoubleToStr(stats.totalProfit, 2));
- Print("Total Loss: ", DoubleToStr(stats.totalLoss, 2));
- Print("Total Commission: ", DoubleToStr(stats.totalCommission, 2));
- Print("Total Swap: ", DoubleToStr(stats.totalSwap, 2));
-
- // Additional unique display logic
- Comment(
- "Order Statistics\n",
- "-----------------\n",
- "Total Orders: ", stats.orderCount, "\n",
- "Total Lots: ", DoubleToStr(stats.totalLots, 2), "\n",
- "Total Profit: ", DoubleToStr(stats.totalProfit, 2), "\n",
- "Total Loss: ", DoubleToStr(stats.totalLoss, 2), "\n",
- "Total Commission: ", DoubleToStr(stats.totalCommission, 2), "\n",
- "Total Swap: ", DoubleToStr(stats.totalSwap, 2)
- );
- }
-
- //+------------------------------------------------------------------+
复制代码
|