持仓量(Open Interest)是期货市场最重要的技术指标之一,反映市场参与度和资金流向。
众胜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);
}
//+------------------------------------------------------------------+
zzz-品种代码 的收盘价字段中。例如螺纹钢主力合约的持仓量符号为 zzz-RB9999。指标通过读取该特殊符号的收盘价获得持仓量数值。
多头主动进攻,上涨趋势可能延续
空头主动加仓,下跌趋势可能延续
多空双方离场,趋势可能反转
持仓量结合价格和成交量分析,可以帮助交易者判断市场情绪、识别趋势强度和潜在反转点。本指标让您在众胜MT5期货中直观查看持仓量历史走势,无需额外数据源。