# MT5 如何读取一月内的最高价和最低价?

MT5  如何读取一月内的最高价和最低价?

zhoumowei:
MT5  如何读取一月内的最高价和最低价?

```#property copyright "Copyright 2017,fxMeter."
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
{
//---
double mnHigh=GetHigh(Symbol(),PERIOD_MN1,0);
double mnLow=GetLow(Symbol(),PERIOD_MN1,0);

}
//+------------------------------------------------------------------+

double GetHigh(string sym,ENUM_TIMEFRAMES tf,int index)
{
double high[1]={0.0};
if(CopyHigh(sym,tf,index,1,high)==1)
return(high[0]);
return(0.0);
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double GetLow(string sym,ENUM_TIMEFRAMES tf,int index)
{
double low[1]={0.0};
if(CopyLow(sym,tf,index,1,low)==1)
return(low[0]);
return(0.0);
}
//+------------------------------------------------------------------+```

Ziheng Zhuang:

再请教了个问题;也是MT5的:

我按下述方法读   bands 时得到的是中轨值  !!!请问如何能读出PERIOD_M1周期下的   下轨值和上轨值?

double bands_value;

double m_buff_CCI_SHUZU[];

CopyBuffer(iBands(NULL,PERIOD_M1,20,2,0,PRICE_CLOSE),0,0,1,m_buff_CCI_SHUZU);    //中轨

bands_value=m_buff_CCI_SHUZU[0];

https://www.mql5.com/zh/docs/indicators/ibands

Ziheng Zhuang:

https://www.mql5.com/zh/docs/indicators/ibands

1.   iBands的问题  已在你的指导下   全部解决了;;;;多谢了

2.   回到第一个问题:按上述方法读取到的好象是当月的最高价哟;;;;;;;;;;我希望是读取前N天的最高价!

```#property copyright "Copyright 2017,fxMeter."
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
{
//---
double mnHigh=GetHigh(Symbol(),PERIOD_MN1,0);
double mnLow=GetLow(Symbol(),PERIOD_MN1,0);

double dHigh= GetHigh(Symbol(),PERIOD_D1,10,0);
double dlow = GetLow(Symbol(),PERIOD_D1,10,0);

}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double GetHigh(string sym,ENUM_TIMEFRAMES tf,int index)
{
double high[1]={0.0};
if(CopyHigh(sym,tf,index,1,high)==1)
return(high[0]);
return(0.0);
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double GetLow(string sym,ENUM_TIMEFRAMES tf,int index)
{
double low[1]={0.0};
if(CopyLow(sym,tf,index,1,low)==1)
return(low[0]);
return(0.0);
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double GetHigh(string sym,ENUM_TIMEFRAMES tf,int nBars,int index)
{
double high[];
if(CopyHigh(sym,tf,index,nBars,high)<=0)return(0.0);
int maxIndex=ArrayMaximum(high);
if(maxIndex>0) return(high[maxIndex]);
//---
return(0.0);
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double GetLow(string sym,ENUM_TIMEFRAMES tf,int nBars,int index)
{
double low[];
if(CopyLow(sym,tf,index,nBars,low)<=0)return(0.0);
int minIndex=ArrayMinimum(low);
if(minIndex>0) return(low[minIndex]);
//---
return(0.0);
}
//+------------------------------------------------------------------+```

Ziheng Zhuang:

/*

double GetHigh(string sym,ENUM_TIMEFRAMES tf,int nBars,int index)

{

double high[];

if(CopyHigh(sym,tf,index,nBars,high)<=0)return(0.0);

int maxIndex=ArrayMaximum(high);

if(maxIndex>0) return(high[maxIndex]);

return(0.0);

}

*/

WR1= GetHigh(Symbol(),PERIOD_D1,22,0);  //ok===14.1455

WR2= GetHigh(Symbol(),PERIOD_D1,21,0);  //ng===0.0

//品种=USDZAR;;;程序如上;;;结果如下

//单步执行结果:22天以上能找到最大值;;22天以下找不到;;;;;;;;;;请教是否因为周末的原因数据不完全引起的

```double GetHigh(string sym,ENUM_TIMEFRAMES tf,int nBars,int index)
{
double high[];
if(CopyHigh(sym,tf,index,nBars,high)<=0)return(0.0);
int maxIndex=ArrayMaximum(high);
if(maxIndex>=0) return(high[maxIndex]);
//---
return(0.0);
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double GetLow(string sym,ENUM_TIMEFRAMES tf,int nBars,int index)
{
double low[];
if(CopyLow(sym,tf,index,nBars,low)<=0)return(0.0);
int minIndex=ArrayMinimum(low);
if(minIndex>=0) return(low[minIndex]);
//---
return(0.0);
}
//+------------------------------------------------------------------+```

Ziheng Zhuang:

这两个问题都已圆满解决!

多谢了

1.请问 如何给 自己已编写好的 MT5  EA程序 加密 ?     是运行  .MQ5的源程序,还是转换成其他格式的运行   较安全些?

2.请帮忙用MT5程序指令实现这样的功能:     假如 A帐户净值>\$1100      则 自动将A帐户转出\$1000   到B帐户!!!!       落袋为安防突发

3.请问::::我已在A帐户下使能了ABCDE共5个品种的MT5_EA;;;;想在B帐户下使能FGHIJ即其他5个不同品种的MT5_EA   要如何操作????(我当前的现象是从A帐户转到B帐户后,系统自动使能了和A帐户一样的品种了)