本帖最后由 ll9687 于 2017-10-20 15:59 编辑
求助!与系统基本一模一样的指标,为什么我的指标就不会跟着及时更新呢?。。。。。。。
指标如下:ADX的指标,请好心人帮指点下,万分感谢!
#property copyright "LL9687"
#property link "LL9687@163.com"
#property version "1.00"
#property strict
//#include <MovingAverages.mqh>
#property indicator_separate_window
#property indicator_buffers 6
#property indicator_color1 White
#property indicator_color2 Crimson
#property indicator_color3 DodgerBlue
#property indicator_color4 Red
#property indicator_color5 LimeGreen
#property indicator_width1 1
#property indicator_level1 20
#property indicator_levelcolor clrSilver
#property indicator_levelstyle STYLE_DOT
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
input int ADX_Period=14; //ADX周期
input double Adx_Min=24; //ADX最小值
double adxVal[];
double plsDI[]; //保存ADX三个动态数组值
double minDI[];
double Buffer4[];
double Buffer5[];
int OnInit()
{
//--- indicator buffers mapping
IndicatorBuffers(4);
IndicatorDigits(Digits);
//--- drawing settings
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE,STYLE_DASHDOTDOT);
SetIndexStyle(2,DRAW_LINE,STYLE_DASHDOTDOT);
SetIndexStyle(3,DRAW_ARROW);
SetIndexStyle(4,DRAW_ARROW);
//---
SetIndexBuffer(0,adxVal);
SetIndexBuffer(1,plsDI);
SetIndexBuffer(2,minDI);
SetIndexBuffer(3,Buffer4);
SetIndexBuffer(4,Buffer5);
//---
IndicatorShortName("My_ADX("+IntegerToString(ADX_Period)+")");
SetIndexLabel(0,"ADX");
SetIndexLabel(1,"+DI");
SetIndexLabel(2,"-DI");
SetIndexArrow(3,241);
SetIndexArrow(4,242);
//---
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[])
{
//---
int i,limit;
//---
if(rates_total<=ADX_Period)
return(0);
limit=rates_total-prev_calculated;
if(prev_calculated>0)
limit++;
//--- adx counted in the 1-st buffer
for(i=0; i<limit; i++)
{
adxVal=iADX(NULL,0,ADX_Period,PRICE_CLOSE,MODE_MAIN,i);
plsDI=iADX(NULL,0,ADX_Period,PRICE_CLOSE,MODE_PLUSDI,i);
minDI=iADX(NULL,0,ADX_Period,PRICE_CLOSE,MODE_MINUSDI,i);
}
for(i=0; i<limit; i++)
{
Buffer4=EMPTY_VALUE;
Buffer5=EMPTY_VALUE;
if(adxVal[i+1]<=adxVal[i+2] && adxVal[i+0]>adxVal[i+1] && adxVal[i+0]<=Adx_Min && plsDI[i+0]>minDI[i+0])
Buffer4=minDI;
if(adxVal[i+1]<=adxVal[i+2] && adxVal[i+0]>adxVal[i+1] && adxVal[i+0]<=Adx_Min && plsDI[i+0]<minDI[i+0])
Buffer5=plsDI;
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
|