MT4
测试环境中测试后如何显示均线
回复:0  浏览:985
  • 楼主admin 圈主
  • 2019-05-05 10:55
原创文章:macy01.blogcn.com
  
  开发一个显示7均线的指标,在EA中调用,那么在测试完毕后,即可显示7均线。在Start()函数中调用的代码如下:
  //------------------------------------------------------------------------------------------
  //以下为spiderMA指标对应的配置参数,用于测试环境中显示均线
  extern int _MAShow0=5;
  extern int _MAShow1=10;
  extern int _MAShow2=20;
  extern int _MAShow3=40;
  extern int _MAShow4=60;
  extern int _MAShow5=120;
  extern int _MAShow6=233;
  //------------------------------------------------------------------------------------------
  int start()
  {
    //如果是测试环境,测试结束后显示7条均线
    if(IsTesting())
      iCustom(NULL, _TradePeriod, "spiderMA", _MAShow0, _MAShow1, _MAShow2, _MAShow3, _MAShow4, _MAShow5, _MAShow6, 0, 0);
  }
  
  测试中发现,只要是EA中调用过的指标,在测试完毕后,在图形上就都会有显示。因此有些时候一个指标如果调用了多次,则会在测试后的图形上显示多次,为了避免这种情况的发生,往往需要使用HideTestIndicators()来取消一些指标的显示,具体方式如下:
     HideTestIndicators(true);
     closeBuy  = iCustom(......);
     HideTestIndicators(false);
  
  显示7均线的指标代码如下:
  //+------------------------------------------------------------------+
  //|                                                spiderMA.mq4 |
  //|                                                       笨蛋学经济 |
  //|                                        http://macy01.blogcn.com/ |
  //+------------------------------------------------------------------+
  #property copyright "笨蛋学经济"
  #property link      "http://macy01.blogcn.com/"
  
  #property indicator_chart_window
  #property indicator_buffers 7
  #property indicator_color1 White
  #property indicator_color2 Pink
  #property indicator_color3 Lime
  #property indicator_color4 RoyalBlue
  #property indicator_color5 Magenta
  #property indicator_color6 PeachPuff
  #property indicator_color7 Yellow
  
  double buf0_ma0[];
  double buf1_ma1[];
  double buf2_ma2[];
  double buf3_ma3[];
  double buf4_ma4[];
  double buf5_ma5[];
  double buf6_ma6[];
  
  extern int _MA0=5;
  extern int _MA1=10;
  extern int _MA2=20;
  extern int _MA3=40;
  extern int _MA4=60;
  extern int _MA5=120;
  extern int _MA6=233;
  
  //+------------------------------------------------------------------+
  //| Custom indicator initialization function                         |
  //+------------------------------------------------------------------+
  int init()
    {
  //---- indicators
     SetIndexStyle(0, DRAW_LINE, EMPTY);
     SetIndexBuffer(0, buf0_ma0);
     
     SetIndexStyle(1, DRAW_LINE, EMPTY);
     SetIndexBuffer(1, buf1_ma1);
     
     SetIndexStyle(2, DRAW_LINE, STYLE_SOLID, 2);
     SetIndexBuffer(2, buf2_ma2);
     
     SetIndexStyle(3, DRAW_LINE, EMPTY);
     SetIndexBuffer(3, buf3_ma3);
     
     SetIndexStyle(4, DRAW_LINE, EMPTY);
     SetIndexBuffer(4, buf4_ma4);
     
     SetIndexStyle(5, DRAW_LINE, STYLE_SOLID, 2);
     SetIndexBuffer(5, buf5_ma5);
     
     SetIndexStyle(6, DRAW_LINE, STYLE_DOT);
     SetIndexBuffer(6, buf6_ma6);
  //----
     return(0);
    }
  //+------------------------------------------------------------------+
  //| Custom indicator deinitialization function                       |
  //+------------------------------------------------------------------+
  int deinit()
    {
  //----
     
  //----
     return(0);
    }
  //+------------------------------------------------------------------+
  //| Custom indicator iteration function                              |
  //+------------------------------------------------------------------+
  int start()
    {
  //----  
     int countedBars=IndicatorCounted();
  
     if(countedBars < 0)
       return(-1);
     
     int limit=Bars-countedBars;
     if(limit>2000)
       limit=2000;
     
     for(int i=0; i