下载MetaTrader 5
要添加评论,请登录注册
购买之前您可以测试应用程序。了解如何测试!
郑美援
85
郑美援 2010.02.05 08:56 

不是 mt4(MQL4)的问题

我想求助一个mt5(mql5)的问题,也许在这里问不合适,请大家原谅。


我想将mt5软件自带的【ROC】指标修改一下,作为自编指标使用。
1. 用 [ ROC(12)+ROC(24) ]/2 代替原来的 ROC(12);

2.另外添加一条 [ ROC(12)+ROC(24) ]/2 的10周期的移动平均线;应该怎样修改原指标呢?谢谢大家。

mt5软件自带的【ROC】指标源码如下:


//+------------------------------------------------------------------+
//| ROC.mq5 |
//| Copyright 2009, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property description "Rate of Change"
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 LightSeaGreen
//--- input parameters
input int InpRocPeriod=12; // Period
//--- indicator buffers
double ExtRocBuffer[];
//--- global variable
int ExtRocPeriod;
//+------------------------------------------------------------------+
//| Rate of Change initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- check for input
if(InpRocPeriod<1)
{
ExtRocPeriod=12;
Print("Incorrect value for input variable InpRocPeriod =",InpRocPeriod,
"Indicator will use value =",ExtRocPeriod,"for calculations.");
}
else ExtRocPeriod=InpRocPeriod;
//--- indicator buffers mapping
SetIndexBuffer(0,ExtRocBuffer,INDICATOR_DATA);
//--- set accuracy
IndicatorSetInteger(INDICATOR_DIGITS,2);
//--- name for DataWindow and indicator subwindow label
IndicatorSetString(INDICATOR_SHORTNAME,"ROC("+string(ExtRocPeriod)+")");
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtRocPeriod);
//--- initialization done
}
//+------------------------------------------------------------------+
//| Rate of Change |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,const int prev_calculated,const int begin,const double &price[])
{
//--- check for rates count
if(rates_total<ExtRocPeriod)
return(0);
//--- preliminary calculations
int pos=prev_calculated-1; // set calc position
if(pos<ExtRocPeriod)
pos=ExtRocPeriod;
//--- the main loop of calculations
for(int i=pos;i<rates_total;i++)
{
if(price==0.0)
ExtRocBuffer=0.0;
else
ExtRocBuffer=(price-price[i-ExtRocPeriod])/price*100;
}
//--- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+

okwh
1629
okwh 2010.02.05 17:10  

大概是

1 ExtRocBuffer=((price-price[i-ExtRocPeriod])/price*100+ (price-price[i-ExtRocPeriod×2])/price*100 )/2;

2 有些复杂,自己看吧

郑美援
85
郑美援 2010.02.06 03:10  

首先谢谢你, DxdCn 。你说的对。关于第1个问题,我按照你给的思路做出来了,已经解决了。但是第2个问题,给【ROC】加一条均线,我搞了半天也没搞成。

做出来的是这样的,不知道是怎么回事,附源码,请指教。

源码如下:

//+------------------------------------------------------------------+
//| ROC.mq5 |
//| Copyright 2009, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property description "Rate of Change"
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots 2
#property indicator_type1 DRAW_LINE
#property indicator_color1 LightSeaGreen
#property indicator_type2 DRAW_LINE
#property indicator_color2 Magenta
//--- input parameters
input int InpRocPeriod=12; // Period
//--- indicator buffers
double ExtRocBuffer[];
double ExtRocBuffer1[];

//--- global variable
int ExtRocPeriod;
//+------------------------------------------------------------------+
//| Rate of Change initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- check for input
if(InpRocPeriod<1)
{
ExtRocPeriod=12;
Print("Incorrect value for input variable InpRocPeriod =",InpRocPeriod,
"Indicator will use value =",ExtRocPeriod,"for calculations.");
}
else ExtRocPeriod=InpRocPeriod;
//--- indicator buffers mapping
SetIndexBuffer(0,ExtRocBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtRocBuffer1,INDICATOR_DATA);

//--- set accuracy
IndicatorSetInteger(INDICATOR_DIGITS,2);
//--- name for DataWindow and indicator subwindow label
IndicatorSetString(INDICATOR_SHORTNAME,"ROC("+string(ExtRocPeriod)+")");
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtRocPeriod);
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtRocPeriod);
//--- initialization done
}
//+------------------------------------------------------------------+
//| Rate of Change |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,const int prev_calculated,const int begin,const double &price[])
{
//--- check for rates count
if(rates_total<ExtRocPeriod)
return(0);
//--- preliminary calculations
int pos=prev_calculated-1; // set calc position
if(pos<ExtRocPeriod)
pos=ExtRocPeriod;
//--- the main loop of calculations
for(int i=pos;i<rates_total;i++)
{
if(price[i]==0.0)
{ ExtRocBuffer[i]=0.0; ExtRocBuffer1[i]=0.0;}
else
{ ExtRocBuffer[i]=(price[i]-price[i-ExtRocPeriod])/price[i]*100;
ExtRocBuffer1[i]=iMA(NULL,PERIOD_CURRENT,10,0,MODE_EMA,ExtRocBuffer[i]);}
}


//--- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+

郑美援
85
郑美援 2010.02.09 19:51  
谢谢各位,已经解决了。
deng9
3
deng9 2011.08.21 03:50  

怎么解决的,可以说说吗?我现在也碰到一样的问题,而且编译通过,但显示不出来





//+------------------------------------------------------------------+
//| ROC.mq5 |
//| Copyright 2009, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property description "Rate of Change"
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots 2
#property indicator_type1 DRAW_LINE
#property indicator_color1 LightSeaGreen
#property indicator_type2 DRAW_LINE
#property indicator_color2 Magenta
//--- input parameters
input int InpRocPeriod=12; // Period
//--- indicator buffers
double ExtRocBuffer[];
double ExtRocBuffer1[];

//--- global variable
int ExtRocPeriod;
//+------------------------------------------------------------------+
//| Rate of Change initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- check for input
if(InpRocPeriod<1)
{
ExtRocPeriod=12;
Print("Incorrect value for input variable InpRocPeriod =",InpRocPeriod,
"Indicator will use value =",ExtRocPeriod,"for calculations.");
}
else ExtRocPeriod=InpRocPeriod;
//--- indicator buffers mapping
SetIndexBuffer(0,ExtRocBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtRocBuffer1,INDICATOR_DATA);

//--- set accuracy
IndicatorSetInteger(INDICATOR_DIGITS,2);
//--- name for DataWindow and indicator subwindow label
IndicatorSetString(INDICATOR_SHORTNAME,"ROC("+string(ExtRocPeriod)+")");
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtRocPeriod);
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtRocPeriod);
//--- initialization done
}
//+------------------------------------------------------------------+
//| Rate of Change |
int OnCalculate(const int rates_total,const int prev_calculated,const int begin,const double &price[])
{
//--- check for rates count
if(rates_total<ExtRocPeriod)
return(0);
//--- preliminary calculations
int pos=prev_calculated-1; // set calc position
if(pos<ExtRocPeriod)
pos=ExtRocPeriod;
//--- the main loop of calculations
int i=pos;
while(i<rates_total && !IsStopped())
{
if(price[i]==0.0)
ExtRocBuffer[i]=0.0;
else
ExtRocBuffer[i]=(price[i]-price[i-ExtRocPeriod])/price[i]*100;
i++;}
int j=pos;
while(j<rates_total && !IsStopped())
{
if(price[j]==0.0)
ExtRocBuffer[j]=0.0;
else
ExtRocBuffer1[j]=iMA(NULL,PERIOD_CURRENT,10,0,MODE_EMA,ExtRocBuffer[j]);
j++;}
//--- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+

/
要添加评论,请登录注册