自定义指标里面 设置了3个缓冲区 导致指标画出了三条线, 本人只想留一条(差价那条) 如何让指标只显示一个缓冲区 另外两个不显示 求指导

 
#property copyright "LXD"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_plots   1
//--- plot Label1
#property indicator_label1  "Label1"

#property indicator_color1  clrBlack
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot Label2
#property indicator_label2  "Label2"

#property indicator_color2  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width2  1
//--- plot Label3
#property indicator_label3  "Label3"
#property indicator_type3   DRAW_LINE
#property indicator_color3  clrForestGreen
#property indicator_style3  STYLE_SOLID
#property indicator_width3  1
//--- indicator buffers
double         Label1Buffer[];
double         Label2Buffer[];
double         Label3Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Label1Buffer);
   SetIndexBuffer(1,Label2Buffer);
   SetIndexBuffer(2,Label3Buffer);
   
//---
   return(INIT_SUCCEEDED);
  }
  
  int start()
  {
  for(int i=0;i<Bars;i++)
  {Label1Buffer[i]=iClose("UKOUSD",0,i);
  Label2Buffer[i]=iClose("USOUSD",0,i);
  Label3Buffer[i]=(Label1Buffer[i]-Label2Buffer[i]) ;}
  return(0);
  }
//+------------------------------------------------------------------+
//| 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[])
  
//---
  {
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+-------------------------------------------------
通过MQL5社区和服务探索MetaTrader 5的新机遇
通过MQL5社区和服务探索MetaTrader 5的新机遇
  • www.mql5.com
The Synchronized Charts script allows comparing bars of different symbols or different periods of the same symbol. Attach the script to a chart and move bars or change the scale, all opened chart will move synchronously with the current one. The bars on different charts aligned to the border according to their open time. CreateGridOrdersTune A...
 
SWEETBOY1990:
#property copyright "LXD"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_plots   1
//--- plot Label1
#property indicator_label1  "Label1"

#property indicator_color1  clrBlack
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot Label2
#property indicator_label2  "Label2"

#property indicator_color2  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width2  1
//--- plot Label3
#property indicator_label3  "Label3"
#property indicator_type3   DRAW_LINE
#property indicator_color3  clrForestGreen
#property indicator_style3  STYLE_SOLID
#property indicator_width3  1
//--- indicator buffers
double         Label1Buffer[];
double         Label2Buffer[];
double         Label3Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Label1Buffer);
   SetIndexBuffer(1,Label2Buffer);
   SetIndexBuffer(2,Label3Buffer);
   
//---
   return(INIT_SUCCEEDED);
  }
  
  int start()
  {
  for(int i=0;i<Bars;i++)
  {Label1Buffer[i]=iClose("UKOUSD",0,i);
  Label2Buffer[i]=iClose("USOUSD",0,i);
  Label3Buffer[i]=(Label1Buffer[i]-Label2Buffer[i]) ;}
  return(0);
  }
//+------------------------------------------------------------------+
//| 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[])
  
//---
  {
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+-------------------------------------------------
Label1Buffer[i]=iClose("UKOUSD",0,i);
  Label2Buffer[i]=iClose("USOUSD",0,i);
  Label3Buffer[i]=(Label1Buffer[i]-Label2Buffer[i]) ;上面的两行删掉。这是mt4里的做法,不知道在mt5里面好不好用。
 

Forum on trading, automated trading systems and testing trading strategies

When you post code please use the CODE button (Alt-S)!

Use the CODE button

Thank you.

 
Xianwei Li:
Label1Buffer[i]=iClose("UKOUSD",0,i);
  Label2Buffer[i]=iClose("USOUSD",0,i);
  Label3Buffer[i]=(Label1Buffer[i]-Label2Buffer[i]) ;上面的两行删掉。这是mt4里的做法,不知道在mt5里面好不好用。

问题已解决,  只需要在 变量定义模块当中 把 #property  Indicator_color1  和indicator_color2  的属性修改成  clrNone  就可以让两条均线不显示了

原因: