[i]Bands 汉译布林

//[i]Bands 汉译布林

include <MovingAverages.mqh>

property indicator_chart_window

property indicator_buffers 3

property indicator_color1 LightSeaGreen

property indicator_color2 LightSeaGreen

property indicator_color3 LightSeaGreen

input int 均线周期= 20;
input int 位移棒数= 0;
input double 标差倍数= 2.0;

double 中均组[];
double 上轨组[];
double 下轨组[];
double 标差组[];
//+------------------------------------------------------------------+
//| 初始化 |
//+------------------------------------------------------------------+
int OnInit(void)
{
//---
IndicatorBuffers(4);
IndicatorDigits(Digits);
//---
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,中均组);
SetIndexShift(0,位移棒数);
SetIndexLabel(0,"Bands 中轨");
//---
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,上轨组);
SetIndexShift(1,位移棒数);
SetIndexLabel(1,"Bands 上轨");
//---
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2,下轨组);
SetIndexShift(2,位移棒数);
SetIndexLabel(2,"Bands 下轨");
//---
SetIndexBuffer(3,标差组);
//---
if(均线周期<=0)
{
Print("周期参数出错=",均线周期);
return(INIT_FAILED);
}
//---
SetIndexDrawBegin(0,均线周期+位移棒数);
SetIndexDrawBegin(1,均线周期+位移棒数);
SetIndexDrawBegin(2,均线周期+位移棒数);
//--- 初始化成功
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| 主函数
//+------------------------------------------------------------------+
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[])
{
int i,pos;
//---
if(rates_total<=均线周期 || 均线周期<=0)
return(0);

//--- 从0到rates_total计数
ArraySetAsSeries(中均组,false);
ArraySetAsSeries(上轨组,false);
ArraySetAsSeries(下轨组,false);
ArraySetAsSeries(标差组,false);
ArraySetAsSeries(close,false);
//--- 初赋空值
if(prev_calculated<1)
{
for(i=0; i<均线周期; i++)
{
中均组[i]= EMPTY_VALUE;
上轨组[i]= EMPTY_VALUE;
下轨组[i]= EMPTY_VALUE;
}
}
//--- 开始计算位
if(prev_calculated>1)
pos= prev_calculated-1;
else
pos= 0;

//--- 主循环内容
for(i=pos; i<rates_total && !IsStopped(); i++)
{
//--- 中间线
中均组[i]= SimpleMA(i,均线周期,close);
//--- 计算StdDev
标差组[i]= 标差计算子(i,close,中均组,均线周期);
//--- 上轨线
上轨组[i]= 中均组[i]+标差倍数标差组[i];
//--- 下轨线
下轨组[i]= 中均组[i]-标差倍数
标差组[i];
//---
}
//----计算结束,返回K线总数
return(rates_total);
}
//+------------------------------------------------------------------+
//| 计算标准差子
//+------------------------------------------------------------------+
double 标差计算子(int 位,const double &价组[],const double &MA组[],int 周期)
{
//--- 变量
double 估算标准差= 0.0;
//--- 检查位
if(位>=周期)
{
//--- calcualte StdDev
for(int i=0; i<周期; i++)
估算标准差 += MathPow(价组[位-i]-MA组[位],2);//价与均线之差的平方 的和
估算标准差= MathSqrt(估算标准差/周期); //再开方后 除以周期跨度
}
//---
return(估算标准差);
}
//+------------------------------------------------------------------+

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Lua 5.1 参考手册 by Roberto Ierusalimschy, Luiz Henrique de F...
    苏黎九歌阅读 13,932评论 0 38
  • //[i]RSI汉译 property indicator_separate_window property in...
    牛在汇上飞阅读 306评论 0 0
  • 拟声拟态词 1.「おろおろ」 *呜咽哭泣貌,抽抽搭搭地(哭) ・おろおろと泣く *坐立不安,惊慌失措 ・子供が迷子...
    日语小课堂阅读 761评论 0 0
  • 昨晚,回到家中,内子问:你有没有感觉家里跟平时不一样? 嗯。可我却说不出哪儿不一样。 你没觉得家里很静吗?内子的眼...
    天长水秋阅读 1,885评论 30 55
  • $\gamma$不支持tex 支持自动排序kaikai
    lemon4113阅读 111评论 0 0