double ma[i]=iMA( string symbol, int timeframe, int period, int ma_shift, int ma_method, int applied_price, i )
double ema=iMAOnArray( ma[i], int total, int period, int ma_shift, int ma_method, int shift)
//+------------------------------------------------------------------+
//| aeetes.mq4 |
//| Copyright ?2008, MetaQuotes Software Corp. |
//| https://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2008, MetaQuotes Software Corp."
#property link "https://www.metaquotes.net/"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 MediumBlue
//---- input parameters
extern int Ext1=5;
extern int Ext2=10;
//---- buffers
double MaBuffer[];
double EmaBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,MaBuffer);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,EmaBuffer);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
if(Bars<=50) return(0);
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- ma
for(int i=0; i<limit; i++)
{
MaBuffer[i]=iMA(NULL,0,Ext1,0,MODE_EMA, PRICE_MEDIAN, i) ;
}
//---- ema
for(i=0; i<limit; i++)
{
EmaBuffer[i]=iMAOnArray(MaBuffer, 0, Ext2, 0, MODE_SMA, i);
}
//----
return(0);
}
//+------------------------------------------------------------------+
//| aeetes.mq4 |
//| Copyright ?2008, MetaQuotes Software Corp. |
//| https://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2008, MetaQuotes Software Corp."
#property link "https://www.metaquotes.net/"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 MediumBlue
//---- input parameters
extern int Ext1=5;
extern int Ext2=10;
//---- buffers
double MaBuffer[];
double EmaBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,MaBuffer);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,EmaBuffer);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
if(Bars<=50) return(0);
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- ma
for(int i=0; i<limit; i++)
{
MaBuffer[i]=iMA(NULL,0,Ext1,0,MODE_EMA, PRICE_MEDIAN, i) ;
}
//---- ema
for(i=0; i<limit; i++)
{
EmaBuffer[i]=iMAOnArray(MaBuffer, 0, Ext2, 0, MODE_SMA, i);
}
//----
return(0);
}
这个写法有问题,因为会同时出现两条线,事实上,我们只需要其中的一条,也就是EmaBuffer[i]输出的图像,另外一条则是干扰,必须去掉才行,这里是否有命令可以不输出那条线呢?
我直接用公式里的EMA()函数调用SMA()发现不能够自动更新且数据运算量过大,应该是全局变量和局部变量的定义有问题吧?怎么解决呢?请教各位高手