指标: 趋势累积器(Trends Accumulator)

 

趋势累积器(Trends Accumulator):

价格变化的累积工具,定义了趋势的开始和终止。

作者: Diogo Seca

 
早上好,迭戈,我正在使用趋势累积器,我想要个性化的修改,我们能谈谈吗?
 

您需要在说明中指定指标绘制的内容。

 
Automated-Trading:

趨勢累積器(Trends Accumulator) :

作者:Diogo Seca


能在趨勢改變的時候加上聲音提示嗎

 
Add reminder sound
 

你好,迪奥戈、


你们有 MT4 版本吗?谢谢

 
指标 非常完美,但我发现一个问题.....。
有可能解决这个问题吗?
 

带颜色:


//属性

#property copyright "Copyright 2016, quebralim"

#property link "https://www.mql5.com/en/users/quebralim"

#property version "1.4"

#property description "Trends Accumulator" #属性描述 "趋势累积器"。

#property indicator_separate_window

#property indicator_buffers 4

#property indicator_plots 1

#property indicator_type1 DRAW_COLOR_HISTOGRAM

#property indicator_colour1 clrBlue,clrRed

#property indicator_width1 10

#property indicator_label1 "Trends Accumulator" (趋势累积器

//输入

输入 uint Threshold =40; //Threshold (in points)

输入 uint MA_Period =10; //MA 周期(以条为单位)

输入 ENUM_MA_METHOD MA_Method =MODE_EMA; //MA 方法

输入 ENUM_APPLIED_PRICE MA_Price =PRICE_TYPICAL; //MA 价格

//globals

double bTA[]; // TA 缓冲区

double bMA[]; // MA 缓冲区

int hMA; // MA 处理程序

double cTA[]; // Clr 缓冲区

double xTA[]; // Clr TA Buffer



//+------------------------------------------------------------------+

//| 指标初始化函数

//+------------------------------------------------------------------+

int OnInit()

{

//输入检查

if(MA_Period<1)

return INIT_PARAMETERS_INCORRECT;


//索引入口

SetIndexBuffer(0,xTA,INDICATOR_DATA);

SetIndexBuffer(1,cTA,INDICATOR_COLOR_INDEX);

SetIndexBuffer(2,bMA,INDICATOR_CALCULATIONS);

SetIndexBuffer(3,bTA,INDICATOR_CALCULATIONS);

PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);

PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,MA_Period);

//指标名称初始化

IndicatorSetString(INDICATOR_SHORTNAME, "Trend Accumulator ("+(string)Threshold+", "+(string)MA_Period+")");


//MA 初始化

hMA=iMA(_Symbol,_Period,MA_Period,0,MA_Method,MA_Price);

if (hMA == INVALID_HANDLE){

Print("Failed to initilise the MA indicator!");

返回 INIT_FAILED;

}

//success!

返回 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[])

{

// 是否有足够的数据?

if(rates_total<=(int)MA_Period)

{

返回 0;

}


//MA准备好复制了吗?

ResetLastError();

if(BarsCalculated(hMA)<rates_total)

{

Print("Not all data of MA is calculated.错误 #",GetLastError());

返回 prev_calculated;

}


// 我们要复制多少 MA 数据?

int to_copy;

if(prev_calculated>rates_total || prev_calculated<=0)

{

to_copy=rates_total;

}

否则

{

to_copy=rates_total-prev_calculated+2;

}


//测试大型操作前是否停止

if(IsStopped())

{

返回 0;

}


//复制 MA 缓冲区

ResetLastError();

if(CopyBuffer(hMA,0,0,to_copy,bMA)<=0)

{

Print("Failed getting MA!错误 #",GetLastError());

返回 prev_calculated;

}


//计算起始值

int i;

if(prev_calculated<=(int)MA_Period)

{

i=(int)MA_Period;

}

否则

{

i=prev_calculated-1;

}


// 通过开始......i......率_总计计算 TA

int iMax;

while(i<rates_total-1)

{

//停止子句

if(IsStopped())

{

返回 0;

}


//第一值

bTA[i]=bTA[i-1]+bMA[i]-bMA[i-1];

xTA[i]=bTA[i];

if(xTA[i]<0)

{

xTA[i]=xTA[i]*(-1);

}

cTA[i]=0;

if(bTA[i]<0)

{

cTA[i]=1;

}


//最后最大值

if(bTA[i]*bTA[i-1]>0)

{

iMax=MaxAround(i);

}

否则

{

iMax=MaxAround(i-1);

}


//必要时重写

if((bTA[iMax]>0 && bTA[iMax]-bTA[i]>=Threshold*_Point) //if it's fallen too low

|| (bTA[iMax]<0 && bTA[i]-bTA[iMax]>=Threshold*_Point))

{ // 如果上升过高

bTA[iMax+1]=bMA[iMax+1]-bMA[iMax];

xTA[iMax+1]=bTA[iMax+1];

if(xTA[iMax+1]<0)

{

xTA[iMax+1]=xTA[iMax+1]*(-1);

}

cTA[iMax+1]=0;

if(bTA[iMax+1]<0)

{

cTA[iMax+1]=1;

}

for(int k=iMax+2; k<=i;++k)

{

bTA[k]=bTA[k-1]+bMA[k]-bMA[k-1];

xTA[k]=bTA[k];

if(xTA[k]<0)

{

xTA[k]=xTA[k]*(-1);

}

cTA[k]=0;

if(bTA[k]<0)

{

cTA[k]=1;

}

}

}


//increment

++i;

}

//只估计最后一个信号

bTA[i]=bTA[i-1]+bMA[i]-bMA[i-1];

xTA[i]=bTA[i];

if(xTA[i]<0)

{

xTA[i]=xTA[i]*(-1);

}

cTA[i]=0;

if(bTA[i]<0)

{

cTA[i]=1;

}


//完成

return i;

}

//+------------------------------------------------------------------+

//| 最大左右|

//+------------------------------------------------------------------+

//返回:当前趋势中绝对最大值的索引

int MaxAround(int i)

{

int iMax=i;

//正向版本

if(bTA[i]>0)

{

while(i > 0 && bTA[--i]>0)

{

if(bTA[i]>bTA[iMax])

{

iMax=i;

}

}

}

//负版本

else if(bTA[i]<0)

{

while(i > 0 && bTA[--i]<0)

{

if(bTA[i]<bTA[iMax])

{

iMax=i;

}

}

}

//返回

返回 iMax;

}

//+------------------------------------------------------------------+