//+------------------------------------------------------------------+//| ShowLots.mq4 |//| 醒目显示多空手数 |//+------------------------------------------------------------------+#property copyright "Show Lots"#property indicator_chart_window#property strict// --- 可调参数(在指标属性中修改)---input color BuyColor = clrLimeGreen; // 多单颜色(亮绿)input color SellColor = clrRed; // 空单颜色(红)input int FontSize = 24; // 字体大小(可调20~30)input int XOffset = 10; // 左边距(像素)input int YOffset = 50; // 上边距(像素)string g_prefix = "ShowLots_";datetime g_lastTime = 0;//+------------------------------------------------------------------+//| 创建文字标签(辅助函数) |//+------------------------------------------------------------------+voidCreateLabel(string name, string text, color clr, int fontSize, int x, int y){ if(ObjectCreate(0, name, OBJ_LABEL, 0, 0, 0)) { ObjectSetInteger(0, name, OBJPROP_CORNER, CORNER_LEFT_UPPER); ObjectSetInteger(0, name, OBJPROP_XDISTANCE, x); ObjectSetInteger(0, name, OBJPROP_YDISTANCE, y); ObjectSetString(0, name, OBJPROP_TEXT, text); ObjectSetInteger(0, name, OBJPROP_COLOR, clr); ObjectSetInteger(0, name, OBJPROP_FONTSIZE, fontSize); ObjectSetString(0, name, OBJPROP_FONT, "Arial Bold"); ObjectSetInteger(0, name, OBJPROP_BACK, false); ObjectSetInteger(0, name, OBJPROP_SELECTABLE, false); ObjectSetInteger(0, name, OBJPROP_HIDDEN, true); }}//+------------------------------------------------------------------+//| 主函数 |//+------------------------------------------------------------------+intOnCalculate(constint rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]){ // 每秒刷新一次 if(TimeCurrent() - g_lastTime < 1) return(rates_total); g_lastTime = TimeCurrent(); // --- 统计多空手数 --- double buyLots = 0, sellLots = 0; for(int i = OrdersTotal() - 1; i >= 0; i--) { if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue; if(OrderSymbol() != Symbol()) continue; if(OrderType() == OP_BUY) buyLots += OrderLots(); else if(OrderType() == OP_SELL) sellLots += OrderLots(); } // --- 删除旧的标签(保证刷新)--- ObjectsDeleteAll(0, g_prefix); // --- 创建多单标签 --- string buyText = "多单: " + DoubleToStr(buyLots, 2) + " 手"; CreateLabel(g_prefix + "buy", buyText, BuyColor, FontSize, XOffset, YOffset); // --- 创建空单标签(在多单下方,间隔 字体大小+5 像素)--- string sellText = "空单: " + DoubleToStr(sellLots, 2) + " 手"; CreateLabel(g_prefix + "sell", sellText, SellColor, FontSize, XOffset, YOffset + FontSize + 5); // 手动刷新图表 ChartRedraw(0); return(rates_total);}//+------------------------------------------------------------------+//| 移除指标时清空 |//+------------------------------------------------------------------+voidOnDeinit(constint reason){ ObjectsDeleteAll(0, g_prefix); Comment("");}//+------------------------------------------------------------------+