程序写的不正确,起码要有如下结构:
{ //--- //......省略...... int limit; ArraySetAsSeries(Buffer_1,false); if(prev_calculated==0) { //.....计算.... limit = rates_total - 1; } else limit=prev_calculated-1; //-------------------------- for(i=limit; i<rates_total; i++) { //.....计算.... } return(rates_total); }
只要在交易平台的菜单栏上方点击“文件”,点击“打开数据文件夹”,再打开的窗口的MQL4里面的“Experts”,复制下去重启交易软件就可以使用了。
谢谢了
旧版的指标在新版MT4里不能使用,用新版MQL4编写后,指标能加载显示了,但是不能跟随图表更新,也不能在一分钟图里显示了。求指教,谢谢呀。代码如下:
#property copyright "2005-2015, MetaQuotes Software Corp."
#property link "http://www.mql4.com"
#property description "RSI Array"
#property strict
//#include <MovingAverages.mqh>
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_color1 Red
#property indicator_color2 Red
#property indicator_color3 Lime
#property indicator_color4 Red
#property indicator_color5 Lime
#property indicator_level1 0
//--- indicator parameters
input int RSI_Period = 21;
input int RSIPrice =5;
input int cPeriod1=10;
input int cPeriod2=13;
input string Array_method ="SMA-0,EMA-1,SMMA-2,LWMA-3" ;
input ENUM_MA_METHOD method=MODE_EMA;
//--- indicator buffers
double a[],b[],temp[],up[],down[];
//string company;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit(void)
{
IndicatorBuffers(5);
IndicatorDigits(Digits+1);
//--- drawing settings
SetIndexStyle(0, DRAW_NONE);
SetIndexBuffer(0, temp);
SetIndexDrawBegin(0,cPeriod1);
//
SetIndexStyle(1, DRAW_LINE);
SetIndexBuffer(1, a);
SetIndexDrawBegin(1,cPeriod1);
//
SetIndexStyle(2, DRAW_LINE);
SetIndexBuffer(2, b);
SetIndexDrawBegin(2,cPeriod1);
//
SetIndexStyle(3, DRAW_ARROW);
SetIndexBuffer(3, up);
SetIndexDrawBegin(3,cPeriod1);
SetIndexArrow(3,233);
//
SetIndexStyle(4, DRAW_ARROW);
SetIndexBuffer(4, down);
SetIndexDrawBegin(4,cPeriod1);
SetIndexArrow(4,234);
//----
IndicatorShortName("RSIA("+IntegerToString(RSI_Period)+","+IntegerToString(RSIPrice)+","+IntegerToString(cPeriod1)+","+IntegerToString(cPeriod2)+")");
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(rates_total<=RSI_Period ||cPeriod1<2)
return(0);
//--- last counted bar will be recounted
int limit,i;
limit=rates_total-prev_calculated;
if(prev_calculated>0)
limit++;
//--- main loop
for(i=0;i<limit;i++)
temp[i]=iRSI(NULL,0,RSI_Period,RSIPrice,i);
// temp[i]=iCCI(NULL,0,CCI_Period,price,i);}
////////
for(i=0;i<limit;i++){
a[i]=iMAOnArray(temp,0,cPeriod1,0,method,i);
b[i]=iMAOnArray(temp,0,cPeriod2,0,method,i);}
//////////////////////
for(i=1;i<limit;i++){
if(a[i+1]<b[i+1]&&a[i]>=b[i]) up[i]=b[i]-5;
else if(a[i+1]>b[i+1]&&a[i]<=b[i]) down[i]=a[i]+5;}
return(rates_total);
}