下载MetaTrader 5

学着编了个指标,编辑器通过了,但显示不正常,恳请高手们来给指教一下吧。

要添加评论,请登录注册
wang
9
wang  

本人初学MT4编指标,试着做了个两个指标。一个是乖离率+移动平均+显示交叉的指标。另一个是MA的MA,可虽然编辑器提示都是0错误0警告,显示却没一个正常,急切希望有好心人人给指点一下。

第一个指标源码如下:

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

#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Silver

//---- input parameters
extern int       MAPeriod=20;

//---- buffers
double ind_buffer[];
double BiasBuffer[];
double MABiasBuffer[];
double up[];
double dn[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorBuffers(5);
   SetIndexBuffer(0, BiasBuffer);
   SetIndexBuffer(1, ind_buffer);
   SetIndexBuffer(2,MABiasBuffer);
   SetIndexBuffer(3,up);
   SetIndexBuffer(4,dn);
  
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexStyle(4,DRAW_ARROW);

   SetIndexArrow(3,159);
   SetIndexArrow(4,159);

   
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("BIAS("+MAPeriod+")");
   SetIndexLabel(0,"BIAS");
      
//----
   SetIndexDrawBegin(0,MAPeriod);
   return(0);
//----
   }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   int i;
   
//----
   if(Bars<=MAPeriod) return(0);
   
//---- initial zero
   if(counted_bars<1)
      for(i=1;i<=MAPeriod;i++) BiasBuffer[Bars-i]=0.0;
//----
   i=Bars-MAPeriod-1;
   if(counted_bars>=MAPeriod) i=Bars-counted_bars-1;
   while(i>=0)
     {ind_buffer[i]=iMA(NULL,0,MAPeriod,0,MODE_SMA,PRICE_CLOSE,i);
      BiasBuffer[i]=(Close[i]-ind_buffer[i])/ind_buffer[i];
      MABiasBuffer[i]=iMAOnArray(BiasBuffer,Bars,5,0,MODE_SMA,i);
      i--;
     }

if (BiasBuffer[i+2]<MABiasBuffer[i+2] && BiasBuffer[i+1]>MABiasBuffer[i+1])
      {
        up[i-1]=MABiasBuffer[i-1];
        }
         if (BiasBuffer[i+2]>MABiasBuffer[i+2] && BiasBuffer[i+1]<MABiasBuffer[i+1])
      {
        dn[i-1]=MABiasBuffer[i-1];
        }
      
         
//----
   return(0);
  }
  
//+------------------------------------------------------------------+
第二个指标源码如下:
//+------------------------------------------------------------------+
//|                                                         MA_MA.mq4 |
//|                                           Copyright @ 2006,shwlm |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright @ 2006,shwlm"
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red
//---- input parameters
extern int       MAPeriod=25;
extern int       MAPeriod1=3;
extern int       Shift=5;
extern int       Shift1=0;

//---- buffers
double ind_buffer[];
double BiasBuffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//   SetIndexStyle(0,DRAW_LINE);
//   SetIndexBuffer(0,ExtMapBuffer1);

   IndicatorBuffers(2);
   SetIndexBuffer(0, BiasBuffer);
   SetIndexStyle(0,DRAW_LINE);
   
   SetIndexBuffer(1, ind_buffer);
     


   
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("BIAS("+MAPeriod+")");
   SetIndexLabel(0,"BIAS");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   int i; 
     i=Bars-1;
//----
     ind_buffer[i]=iMA(NULL,0,MAPeriod,Shift,MODE_SMA,PRICE_CLOSE,i);
     BiasBuffer[i]= iMAOnArray(ind_buffer,0,MAPeriod1,Shift1,MODE_SMA,i);
//----
   return(0);
  }
//+------------------------------------------------------------------+
要添加评论,请登录注册