找到一个筹码分布指标,但是运行不了,求助。

 

源码如下:

//+------------------------------------------------------------------+
//| _VolumeDistribute.mq4 |
//| Copyright ?2007, MetaQuotes Software Corp. |
//| https://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2007, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"

#property indicator_chart_window
extern int maxLen = 1000 ;
int iPV ;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
for(int i =0 ; i < iPV ; i ++)
{
string str = DoubleToStr( i, 0 ) ;
ObjectDelete(str) ;
}
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+

int start()
{
int counted_bars=IndicatorCounted();
double PV[] ;
double imax = 0 ;
double imin = 0 ;
double max = 0 ;
double min = 10000 ;
//求出给定长度的价格的区间
for(int i = 0 ; i < maxLen ; i ++)
{
imax = iHigh(Symbol(), PERIOD_M1, i ) ;
imin = iLow(Symbol(), PERIOD_M1, i ) ;
//Print( " imax = ", imax ) ;
//Print( " imin = ", imin ) ;
if( max < imax ) max = imax ;
if( min > imin ) min = imin ;
}
//定义所需的price-volume 数组
iPV = (max - min )/Point;
Print( " iPV = ", iPV) ;
ArrayResize(PV, iPV) ;
for( i =0 ; i < iPV ; i ++ )
PV =0 ;
//计算各个价位的交易量
for(i = 0 ; i < maxLen ; i ++)
{
imax = iHigh(Symbol(), PERIOD_M1, i ) ;
imin = iLow (Symbol(), PERIOD_M1, i ) ;

double ivol = iVolume( Symbol(), PERIOD_M1, i )*Point ;

for(double price = imin ; price <= imax ; price ++)
{
int price_Pos = (price - min )/Point ;
PV[price_Pos] = PV[price_Pos] + ivol/(imax - imin + 1 ) ;
}
}
//找出最大的交易量
double maxVolume ;
maxVolume = 0 ;
for( i = 0 ; i < iPV ; i ++ )
if( maxVolume < PV ) maxVolume = PV ;
Print(" maxVolume = ", maxVolume ) ;
//归一化
for( i = 0 ; i < iPV ; i ++ )
PV = PV / maxVolume ;
//画出图形
for( i = 0 ; i < iPV ; i ++ )
{
double EndX = Time[0] + 3600* 5 ;
double EndY = min + i* Point ;
double StartX = EndX - PV * 3600 * 4 ;
double StartY = EndY ;
string ObjName = DoubleToStr(i, 0 ) ;
ObjectDelete(ObjName);
ObjectCreate(ObjName, OBJ_TREND, 0, StartX, StartY, EndX, EndY);
ObjectSet(ObjName, OBJPROP_RAY, 0);
ObjectSet(ObjName, OBJPROP_COLOR, Red);
}
return( 0 );
}
//+------------------------------------------------------------------+