📈 众胜MT5期货持仓量指标 获取当前与历史持仓量

众胜MT5期货持仓量指标展示图 - 螺纹钢rb2608日线持仓量3141手
📌 上图:众胜MT5期货持仓量指标展示 - 螺纹钢2608合约日线持仓量(Open Interest)为3141手

持仓量(Open Interest)是期货市场最重要的技术指标之一,反映市场参与度和资金流向。
众胜MT5期货内置了持仓量数据,以下自定义指标可以直接在图表中显示持仓量曲线。

🎯 指标功能

  • 获取当前K线对应的期货持仓量
  • 获取历史任意时点的持仓量数据
  • 在独立窗口以黄色曲线显示持仓量走势
  • 支持所有期货品种和周期(众胜MT5期货)

🔑 核心技术点

  • 使用 zzz-{品种代码} 特殊符号获取持仓量数据
  • iClose() 函数读取持仓量数值
  • iBarShift() 精确匹配历史K线时间
  • 支持指标自动重绘和历史数据回溯

📜 完整源代码:期货持仓量指标FutureOpenInterest.mq5

//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//|                                    期货持仓量指标FutureOpenInterest.mq5 |
//|                                    Copyright 众胜MT5期货 www.wewin28.com |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "众胜MT5期货 www.wewin28.com 1145412@qq.com"
#property link      "http://www.wewin28.com"
#property version   "1.2"

#property indicator_separate_window
#property indicator_buffers       1
#property indicator_plots   1
#property indicator_type1         DRAW_LINE
#property indicator_color1        clrYellow

input color indicatorColor=clrYellow; // Period

double openInterests[];
int limit=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,openInterests,INDICATOR_DATA);
   IndicatorSetString(INDICATOR_SHORTNAME,"持仓量OpenInterest(众胜MT5期货)");
   IndicatorSetInteger(INDICATOR_DIGITS,0);
   ArraySetAsSeries(openInterests, true);

//IndicatorSetInteger(INDICATOR_COLOR_INDEX,0);

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int 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(prev_calculated==0)
     {
      limit=rates_total;
     }
   else
     {
      limit=1;
     }
     
   string openInterestSymbol="zzz-"+Symbol();
   
   //获得当前持仓量   
   if(limit==1)
     {
      double openInterest=iClose(openInterestSymbol, PERIOD_CURRENT, 0);  
      openInterests[0]=openInterest;
     }
   //获得历史持仓量
   else
     {
      for(int i=0; i<limit; i++)
        {
         datetime dt=iTime(Symbol(), PERIOD_CURRENT, i);

         int bar=iBarShift(openInterestSymbol, PERIOD_CURRENT, dt, true);
         
         if(bar!=-1)
           {
            double openInterest=iClose(openInterestSymbol, PERIOD_CURRENT, bar);

            openInterests[i]=openInterest;
           }         
        }
        
       
     }

      ChartRedraw(0);
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
💡 原理说明: 众胜MT5期货CTP接口中,持仓量数据存储在特殊符号 zzz-品种代码 的收盘价字段中。例如螺纹钢主力合约的持仓量符号为 zzz-RB9999。指标通过读取该特殊符号的收盘价获得持仓量数值。

📖 持仓量在期货交易中的意义(众胜MT5期货)

📈
价涨仓增

多头主动进攻,上涨趋势可能延续

📉
价跌仓增

空头主动加仓,下跌趋势可能延续

🔄
价仓同减

多空双方离场,趋势可能反转

持仓量结合价格和成交量分析,可以帮助交易者判断市场情绪、识别趋势强度和潜在反转点。本指标让您在众胜MT5期货中直观查看持仓量历史走势,无需额外数据源。