# 指标喷发整体特征的计算

10 三月 2014, 07:20
0
1 409

### 简介

• 未来的支撑位和阻力位；
• 趋势方向（价格变动）；
• 过去积累的变动强度。

• 同一类型的喷发点有集群倾向。
• 密集的集群可吸引价格，或反过来排斥价格。

```//--- external variable for storing averaging period of the iEnvelopes indicator
input int   ma_period=140; // averaging period of the iEnvelopes indicator
//--- array for storing deviations of the iEnvelopes indicator
double      ENV[]={0.01,0.0165,0.0273,0.0452,0.0747,01234,0.204,0.3373,0.5576,0.9217,1.5237};
//--- array for storing iMA indicator periods
int         MA[]={4,7,11,19,31,51,85};```

```//+------------------------------------------------------------------+
//|                                      emission_of_MA_envelope.mq5 |
//|                           https://www.mql5.com/ru/users/DC2008 |
//+------------------------------------------------------------------+
#property version   "1.00"
//---
#include <GetIndicatorBuffers.mqh>
#include <Emission.mqh>
//--- external variable for storing averaging period of the iEnvelopes indicator
input int   ma_period=140;      // averaging period of the iEnvelopes indicator
//--- array for storing deviations of the iEnvelopes indicator
double      ENV[]={0.01,0.0165,0.0273,0.0452,0.0747,01234,0.204,0.3373,0.5576,0.9217,1.5237};
//--- array for storing the iMA indicator periods
int         MA[]={4,7,11,19,31,51,85};
//--- array for storing pointers to the iMA and iEnvelopes indicators
int         handle_MA[];
int         handle_Envelopes[];
//--- market data
datetime    T[],prevTimeBar=0;
double      H[],L[];
#define     HL(a, b) (a+b)/2
//--- class instances
CEmission      EnvMa(0,300);
PointEmission  pEmission;
//--- drawing styles for points of emission
#define     COLOR_UPPER  C'51,255,255'
#define     COLOR_LOWER  C'0,51,255'
#define     COLOR_MA     C'255,51,255'
color       colorPoint[]={COLOR_UPPER,COLOR_LOWER,COLOR_MA};
CodeColor   styleUpper={158,COLOR_UPPER,SMALL};
CodeColor   styleLower={158,COLOR_LOWER,SMALL};
CodeColor   styleMA={158,COLOR_MA,SMALL};
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
ArraySetAsSeries(T,true);
ArraySetAsSeries(H,true);
ArraySetAsSeries(L,true);
//---
int size=ArraySize(MA);
ArrayResize(handle_MA,size);
//--- create a pointer to the object - the iMA indicator
for(int i=0; i<size; i++)
{
handle_MA[i]=iMA(NULL,0,MA[i],0,MODE_SMA,PRICE_MEDIAN);
//--- if an error occurs when creating the object, print the message
if(handle_MA[i]<0)
{
Print("The iMA object[",MA[i],"] has not been created: Error = ",GetLastError());
//--- forced program termination
return(-1);
}
}
//---
size=ArraySize(ENV);
ArrayResize(handle_Envelopes,size);
//--- create a pointer to the object - the iEnvelopes indicator
for(int i=0; i<size; i++)
{
handle_Envelopes[i]=iEnvelopes(NULL,0,ma_period,0,MODE_SMA,PRICE_MEDIAN,ENV[i]);
//--- if an error occurs when creating the object, print the message
if(handle_Envelopes[i]<0)
{
Print("The iEnvelopes object[",ENV[i],"] has not been created: Error = ",GetLastError());
//--- forced program termination
return(-1);
}
}
//---
return(0);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---

}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
//--- market data
CopyTime(NULL,0,0,2,T);
CopyHigh(NULL,0,0,2,H);
CopyLow(NULL,0,0,2,L);
//--- fill the declared arrays with current values from all indicator buffers
string name;
uint GTC=GetTickCount();
//---- indicator buffers
double   ibMA[],ibMA1[];      // arrays for the iMA indicator
double   ibEnvelopesUpper[];  // array for the iEnvelopes indicator (UPPER_LINE)
double   ibEnvelopesLower[];  // array for the iEnvelopes indicator (LOWER_LINE)
for(int i=ArraySize(handle_MA)-1; i>=0; i--)
{
if(!CopyBufferAsSeries(handle_MA[i],0,0,2,true,ibMA))
return;
//---
for(int j=ArraySize(handle_Envelopes)-1; j>=0; j--)
{
if(!GetEnvelopesBuffers(handle_Envelopes[j],0,2,ibEnvelopesUpper,ibEnvelopesLower,true))
return;
//--- find the intersection point of the iEnvelopes(UPPER_LINE) and iMA indicators
pEmission=EnvMa.CalcPoint(ibEnvelopesUpper[1],ibEnvelopesUpper[0],ibMA[1],ibMA[0],T[0]);
if(pEmission.real) // if the intersection point is found, draw it in the chart
{
name="iEnvelopes(UPPER_LINE)"+(string)j+"=iMA"+(string)i+(string)GTC;
EnvMa.CreatePoint(name,pEmission,styleUpper);
}
//--- find the intersection point of the iEnvelopes(LOWER_LINE) and iMA indicators
pEmission=EnvMa.CalcPoint(ibEnvelopesLower[1],ibEnvelopesLower[0],ibMA[1],ibMA[0],T[0]);
if(pEmission.real) // if the intersection point is found, draw it in the chart
{
name="iEnvelopes(LOWER_LINE)"+(string)j+"=iMA"+(string)i+(string)GTC;
EnvMa.CreatePoint(name,pEmission,styleLower);
}
}
//---
for(int j=ArraySize(handle_MA)-1; j>=0; j--)
{
if(i!=j)
{
if(!CopyBufferAsSeries(handle_MA[j],0,0,2,true,ibMA1))
return;
//--- find the intersection point of the iMA and iMA indicators
pEmission=EnvMa.CalcPoint(ibMA1[1],ibMA1[0],ibMA[1],ibMA[0],T[0]);
if(pEmission.real) // if the intersection point is found, draw it in the chart
{
name="iMA"+(string)j+"=iMA"+(string)i+(string)GTC;
EnvMa.CreatePoint(name,pEmission,styleMA);
}
}
}
}
//--- deletion of the graphical objects of emission not to stuff the chart
if(T[0]>prevTimeBar) // delete once per bar
{
int  total=ObjectsTotal(0,0,-1);
prevTimeBar=T[0];
for(int obj=total-1;obj>=0;obj--)
{
string obj_name=ObjectName(0,obj,0,OBJ_TEXT);
datetime obj_time=(datetime)ObjectGetInteger(0,obj_name,OBJPROP_TIME);
if(obj_time<T[0])
ObjectDelete(0,obj_name);
}
Comment("Emission © DC2008       Objects = ",total);
}
//---
}```

```//+------------------------------------------------------------------+
//|                                                     Emission.mqh |
//|                           https://www.mql5.com/ru/users/DC2008 |
//+------------------------------------------------------------------+
#property version   "1.00"
#define  BIG   7    // point size
#define  SMALL 3    // point size
//+------------------------------------------------------------------+
//| pMABB structure                                                  |
//+------------------------------------------------------------------+
struct PointEmission
{
double            x;       // X-coordinate of the time point
double            y;       // Y-coordinate of the price point
datetime          t;       // t-coordinate of the point's time
bool              real;    // whether the point exists
};
//+------------------------------------------------------------------+
//| CodeColor structure                                              |
//+------------------------------------------------------------------+
struct CodeColor
{
long              Code;    // point symbol code
color             Color;   // point color
int               Width;   // point size
};
//+------------------------------------------------------------------+
//| Base class for emissions                                         |
//+------------------------------------------------------------------+
class CEmission
{
private:
int               sec;
int               lim_Left;   // limiting range of visibility in bars
int               lim_Right;  // limiting range of visibility in bars

public:
PointEmission     CalcPoint(double   y1,  // Y-coordinate of straight line 1 on bar [1]
double   y0,  // Y-coordinate of straight line 1 on bar [0]
double   yy1, // Y-coordinate of straight line 2 on bar [1]
double   yy0, // Y-coordinate of straight line 2 on bar [0]
datetime t0   // t-coordinate of the current bar Time[0]
);
bool              CreatePoint(string name,            // point name
PointEmission &point,   // coordinates of the point
CodeColor &style);      // point drawing style
CEmission(int limitLeft,int limitRight);
~CEmission();
};
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
CEmission::CEmission(int limitLeft,int limitRight)
{
sec=PeriodSeconds();
lim_Left=limitLeft;
lim_Right=limitRight;
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
CEmission::~CEmission()
{
}
//+------------------------------------------------------------------+
//| The CalcPoint method of the CEmission class                      |
//+------------------------------------------------------------------+
PointEmission CEmission::CalcPoint(double   y1, // Y-coordinate of straight line 1 on bar [1]
double   y0, // Y-coordinate of straight line 1 on bar [0]
double   yy1,// Y-coordinate of straight line 2 on bar [1]
double   yy0,// Y-coordinate of straight line 2 on bar [0]
datetime t0  // t-coordinate of the current bar Time[0]
)
{
PointEmission point={NULL,NULL,NULL,false};
double y0y1=y0-y1;
double y1yy1=y1-yy1;
double yy0yy1=yy0-yy1;
double del0=yy0yy1-y0y1;
if(MathAbs(del0)>0)
{
point.x=y1yy1/del0;
if(point.x<lim_Left || point.x>lim_Right) return(point);
point.y=y1+y0y1*y1yy1/del0;
if(point.y<0) return(point);
point.t=t0+(int)(point.x*sec);
point.real=true;
return(point);
}
return(point);
}
//+------------------------------------------------------------------+
//| The CreatePoint method of the CEmission class                    |
//+------------------------------------------------------------------+
bool CEmission::CreatePoint(string name,            // point name
PointEmission &point,  // coordinates of the point
CodeColor &style)      // point drawing style
{
if(ObjectCreate(0,name,OBJ_TEXT,0,0,0))
{
ObjectSetString(0,name,OBJPROP_FONT,"Wingdings");
ObjectSetInteger(0,name,OBJPROP_ANCHOR,ANCHOR_CENTER);
ObjectSetInteger(0,name,OBJPROP_FONTSIZE,style.Width);
ObjectSetString(0,name,OBJPROP_TEXT,CharToString((uchar)style.Code));
ObjectSetDouble(0,name,OBJPROP_PRICE,point.y);
ObjectSetInteger(0,name,OBJPROP_TIME,point.t);
ObjectSetInteger(0,name,OBJPROP_COLOR,style.Color);
return(true);
}
return(false);
}```

### 喷发的整体特征

• 浅绿色 - iMA 与 iEnvelopes 的交叉点，UPPER_LINE 缓冲区。
• 蓝色 - iMA 与 iEnvelopes 交叉点，LOWER_LINE 缓冲区。
• 洋红色 - iMA 与 iMA 交叉点。

```//--- arrays for calculation and display of integral characteristics of emissions
#define     NUMBER_TYPES_POINT   3
double      sum[NUMBER_TYPES_POINT],sumprev[NUMBER_TYPES_POINT];
datetime    sum_time[NUMBER_TYPES_POINT];
int         n[NUMBER_TYPES_POINT],W[NUMBER_TYPES_POINT];
color       colorLine[]={clrAqua,clrBlue,clrMagenta};
```

OnTick() 模块：

```//--- calculation of integral characteristics of emissions
ArrayInitialize(n,0);
ArrayInitialize(sum,0.0);
ArrayInitialize(sum_time,0.0);
for(int obj=total-1;obj>=0;obj--)
{
string   obj_name=ObjectName(0,obj,0,OBJ_TEXT);
datetime obj_time=(datetime)ObjectGetInteger(0,obj_name,OBJPROP_TIME);
if(obj_time>T[0])
{
color    obj_color=(color)ObjectGetInteger(0,obj_name,OBJPROP_COLOR);
double   obj_price=ObjectGetDouble(0,obj_name,OBJPROP_PRICE);
for(int i=ArraySize(n)-1; i>=0; i--)
if(obj_color==colorPoint[i])
{
n[i]++;
sum[i]+=obj_price;
sum_time[i]+=obj_time;
}
}
}
//--- displaying integral characteristics of emissions
for(int i=ArraySize(n)-1; i>=0; i--)
{
if(n[i]>0)
{
name="H.line."+(string)i;
ObjectCreate(0,name,OBJ_HLINE,0,0,0,0);
ObjectSetInteger(0,name,OBJPROP_COLOR,colorLine[i]);
ObjectSetInteger(0,name,OBJPROP_STYLE,STYLE_DASHDOT);
ObjectSetInteger(0,name,OBJPROP_WIDTH,1);
ObjectSetDouble(0,name,OBJPROP_PRICE,sum[i]/n[i]);
}
}```

### 图形分析

```//--- displaying integral characteristics of emissions
ArrayInitialize(W,10);
W[ArrayMaximum(n)]=20;
W[ArrayMinimum(n)]=3;
for(int i=ArraySize(n)-1; i>=0; i--)
{
if(n[i]>0)
{
//--- horizontal lines of mean prices
name="H.line."+(string)i;
ObjectCreate(0,name,OBJ_HLINE,0,0,0,0);
ObjectSetInteger(0,name,OBJPROP_COLOR,colorLine[i]);
ObjectSetInteger(0,name,OBJPROP_STYLE,STYLE_DASHDOT);
ObjectSetInteger(0,name,OBJPROP_WIDTH,1);
ObjectSetDouble(0,name,OBJPROP_PRICE,sum[i]/n[i]);
//--- markers
name="P."+(string)i;
ObjectCreate(0,name,OBJ_TEXT,0,0,0);
ObjectSetString(0,name,OBJPROP_FONT,"Wingdings");
ObjectSetInteger(0,name,OBJPROP_ANCHOR,ANCHOR_CENTER);
ObjectSetInteger(0,name,OBJPROP_FONTSIZE,17);
ObjectSetString(0,name,OBJPROP_TEXT,CharToString(163));
ObjectSetInteger(0,name,OBJPROP_COLOR,colorLine[i]);
ObjectSetDouble(0,name,OBJPROP_PRICE,sum[i]/n[i]);
ObjectSetInteger(0,name,OBJPROP_TIME,sum_time[i]/n[i]);
//--- integral curves
name="T"+(string)i+".line"+(string)T[1];
ObjectCreate(0,name,OBJ_TREND,0,0,0);
ObjectSetInteger(0,name,OBJPROP_COLOR,colorLine[i]);
ObjectSetInteger(0,name,OBJPROP_WIDTH,W[i]);
if(sumprev[i]>0)
{
ObjectSetDouble(0,name,OBJPROP_PRICE,0,sumprev[i]);
ObjectSetInteger(0,name,OBJPROP_TIME,0,T[1]);
ObjectSetDouble(0,name,OBJPROP_PRICE,1,(sum[i]/n[i]));
ObjectSetInteger(0,name,OBJPROP_TIME,1,T[0]);
}
//--- numerical values of integral characteristics
name="Text"+(string)i+".control";
ObjectCreate(0,name,OBJ_TEXT,0,0,0);
ObjectSetInteger(0,name,OBJPROP_ANCHOR,ANCHOR_LEFT_LOWER);
ObjectSetInteger(0,name,OBJPROP_FONTSIZE,30);
ObjectSetInteger(0,name,OBJPROP_COLOR,colorLine[i]);
string str=DoubleToString((double)n[i]/(double)(n[0]+n[1])*100,1);
ObjectSetString(0,name,OBJPROP_TEXT,str);
ObjectSetDouble(0,name,OBJPROP_PRICE,0,(sum[i]/n[i]));
ObjectSetInteger(0,name,OBJPROP_TIME,0,sum_time[i]/n[i]);
}
}```

• 浅绿色线为通道上限。
• 蓝色线为通道下限。

```//---
if(n[ArrayMinimum(n)]>0)
{
datetime d[2];
for(int j=0;j<2;j++)
{
d[j]=sum_time[j]/n[j];
}
int i=ArrayMinimum(d);

name="Price.line"+(string)T[1];
ObjectCreate(0,name,OBJ_TREND,0,0,0);
ObjectSetInteger(0,name,OBJPROP_WIDTH,8);
ObjectSetDouble(0,name,OBJPROP_PRICE,0,HL(H[1],L[1]));
ObjectSetInteger(0,name,OBJPROP_TIME,0,T[1]);
ObjectSetDouble(0,name,OBJPROP_PRICE,1,HL(H[0],L[0]));
ObjectSetInteger(0,name,OBJPROP_TIME,1,T[0]);
ObjectSetInteger(0,name,OBJPROP_COLOR,colorLine1[i]);
}
//---```

```      //--- emissions of integral characteristics of the original emissions
pEmission=EnvMa.CalcPoint(sumprev[0],sum[0]/n[0],sumprev[2],sum[2]/n[2],T[0]);
if(pEmission.real) // if the intersection point is found, draw it in the chart
{
name="test/up"+(string)GTC;
EnvMa.CreatePoint(name,pEmission,styleUpper2);
}
pEmission=EnvMa.CalcPoint(sumprev[1],sum[1]/n[1],sumprev[2],sum[2]/n[2],T[0]);
if(pEmission.real) // if the intersection point is found, draw it in the chart
{
name="test/dn"+(string)GTC;
EnvMa.CreatePoint(name,pEmission,styleLower2);
}```

```#define     COLOR_2_UPPER  C'102,255,255'
#define     COLOR_2_LOWER  C'51,102,255'
CodeColor   styleUpper2={178,COLOR_2_UPPER,BIG};
CodeColor   styleLower2={178,COLOR_2_LOWER,BIG};```

### 喷发的时间序列

```//+------------------------------------------------------------------+
//|                                                 TimeEmission.mqh |
//|                           https://www.mql5.com/ru/users/DC2008 |
//+------------------------------------------------------------------+
#property version   "1.00"
//---
#include <Emission.mqh>
#define ARRMAX       64
#define ARRDELTA     8
//+------------------------------------------------------------------+
//| pIntegral structure                                              |
//+------------------------------------------------------------------+
struct pIntegral
{
double            y;       // Y-coordinate of the price point (mean price of the points with the same time)
datetime          t;       // t-coordinate of the point's time
int               n;       // n-number of points with the same time
};
//+------------------------------------------------------------------+
//| Base class for time series of emissions                          |
//+------------------------------------------------------------------+
class CTimeEmission
{
private:
pIntegral         time_series_Emission[]; // time series of emission
int               size_ts; // number of elements in time series
datetime           t[1];
public:
//--- method of writing new elements to time series of emission
void              Write(PointEmission &point);
//--- method of reading integral characteristics of emissions
CTimeEmission();
~CTimeEmission();
};

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
CTimeEmission::CTimeEmission()
{
ArrayResize(time_series_Emission,ARRMAX,ARRMAX);
size_ts=ArraySize(time_series_Emission);
for(int i=size_ts-1; i>=0; i--)
time_series_Emission[i].t=0;
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
CTimeEmission::~CTimeEmission()
{
}
//+------------------------------------------------------------------+
//| The Write method of the CTimeEmission class                      |
//+------------------------------------------------------------------+
void CTimeEmission::Write(PointEmission &point)
{
CopyTime(NULL,0,0,1,t);
size_ts=ArraySize(time_series_Emission);
for(int k=0;k<size_ts;k++)
{
if(time_series_Emission[k].t<t[0]) // find the first empty cell
{
if(k>size_ts-ARRDELTA)
{   // increase the array size, if necessary
int narr=ArrayResize(time_series_Emission,size_ts+ARRMAX,ARRMAX);
for(int l=size_ts-1;l<narr;l++)
time_series_Emission[l].t=0;
}
time_series_Emission[k].y=point.y;
time_series_Emission[k].t=point.t;
time_series_Emission[k].n=1;
return;
}
if(time_series_Emission[k].t==point.t) // find the first similar cell
{
time_series_Emission[k].y=(time_series_Emission[k].y*time_series_Emission[k].n+point.y)/(time_series_Emission[k].n+1);
time_series_Emission[k].n++;
return;
}
}
}
//+------------------------------------------------------------------+
//| The Read method of the CTimeEmission class                       |
//+------------------------------------------------------------------+
{
CopyTime(NULL,0,0,1,t);
pIntegral property_Emission={0.0,0,0};
size_ts=ArraySize(time_series_Emission);
for(int k=0;k<size_ts;k++)
{
if(time_series_Emission[k].t>=t[0])
{
property_Emission.y+=time_series_Emission[k].y*time_series_Emission[k].n;
property_Emission.t+=(time_series_Emission[k].t-t[0])*time_series_Emission[k].n;
property_Emission.n+=time_series_Emission[k].n;
}
}
if(property_Emission.n>0)
{
property_Emission.y=property_Emission.y/property_Emission.n;
property_Emission.t=property_Emission.t/property_Emission.n+t[0];
}
return(property_Emission);
}```

### 整体特征的俭省计算

```//+------------------------------------------------------------------+
//|                                   emission_of_MA_envelope_ts.mq5 |
//|                           https://www.mql5.com/ru/users/DC2008 |
//+------------------------------------------------------------------+
#property version   "1.00"
//---
#include <GetIndicatorBuffers.mqh>
#include <Emission.mqh>
#include <TimeEmission.mqh>
//--- number of point types
#define     NUMBER_TYPES_POINT   3
//--- array for storing the iMA indicator periods
int      MA[]={4,7,11,19,31,51,85};
//--- external variable for storing averaging period of the iEnvelopes indicator
input int ma_period=140; // averaging period of the iEnvelopes indicator
//--- array for storing deviations of the iEnvelopes indicator
double   ENV[]={0.01,0.0165,0.0273,0.0452,0.0747,01234,0.204,0.3373,0.5576,0.9217,1.5237};
//--- array for storing pointers to the iMA indicator
int      handle_MA[];
//--- array for storing pointers to the iEnvelopes indicator
int      handle_Envelopes[];
//--- market data
datetime    T[],prevTimeBar=0;
double      H[],L[];
#define     HL(a, b) (a+b)/2
//--- class instances
CEmission      EnvMa(0,200);
PointEmission  pEmission;
CTimeEmission  tsMA[NUMBER_TYPES_POINT];
pIntegral      integral[NUMBER_TYPES_POINT];
//--- drawing styles for points of emission
#define     DEL            500
//--- arrays for calculation and display of integral characteristics of emissions
double      sumprev[NUMBER_TYPES_POINT];
int         n[NUMBER_TYPES_POINT],W[NUMBER_TYPES_POINT];
color       colorLine[]={clrAqua,clrBlue,clrMagenta};
int         fontPoint[]={30,30,30};
int         fontMarker[]={16,16,16};
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
ArraySetAsSeries(T,true);
ArraySetAsSeries(H,true);
ArraySetAsSeries(L,true);
ArrayInitialize(sumprev,0.0);
//---
int size=ArraySize(MA);
ArrayResize(handle_MA,size);
//--- create a pointer to the object - the iMA indicator
for(int i=0; i<size; i++)
{
handle_MA[i]=iMA(NULL,0,MA[i],0,MODE_SMA,PRICE_MEDIAN);
//--- if an error occurs when creating the object, print the message
if(handle_MA[i]<0)
{
Print("The iMA object[",MA[i],"] has not been created: Error = ",GetLastError());
//--- forced program termination
return(-1);
}
}
//+------------------------------------------------------------------+
size=ArraySize(ENV);
ArrayResize(handle_Envelopes,size);
//--- create a pointer to the object - the iEnvelopes indicator
for(int i=0; i<size; i++)
{
handle_Envelopes[i]=iEnvelopes(NULL,0,ma_period,0,MODE_SMA,PRICE_MEDIAN,ENV[i]);
//--- if an error occurs when creating the object, print the message
if(handle_Envelopes[i]<0)
{
Print("The iEnvelopes object[",ENV[i],"] has not been created: Error = ",GetLastError());
//--- forced program termination
return(-1);
}
}
//---
return(0);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---

}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
//--- market data
CopyTime(NULL,0,0,2,T);
CopyHigh(NULL,0,0,2,H);
CopyLow(NULL,0,0,2,L);
//--- fill the declared arrays with current values from all indicator buffers
string name;
uint GTC=GetTickCount();
//---- indicator buffers
double   ibMA[],ibMA1[];      // arrays for the iMA indicator
double   ibEnvelopesUpper[];  // array for the iEnvelopes indicator (UPPER_LINE)
double   ibEnvelopesLower[];  // array for the iEnvelopes indicator (LOWER_LINE)
for(int i=ArraySize(handle_MA)-1; i>=0; i--)
{
if(!CopyBufferAsSeries(handle_MA[i],0,0,2,true,ibMA))
return;
//---
for(int j=ArraySize(handle_Envelopes)-1; j>=0; j--)
{
if(!GetEnvelopesBuffers(handle_Envelopes[j],0,2,ibEnvelopesUpper,ibEnvelopesLower,true))
return;
//--- find the intersection point of the iEnvelopes(UPPER_LINE) and iMA indicators
pEmission=EnvMa.CalcPoint(ibEnvelopesUpper[1],ibEnvelopesUpper[0],ibMA[1],ibMA[0],T[0]);
if(pEmission.real) // if the intersection point is found, add it to the time series of emission
tsMA[0].Write(pEmission);
//--- find the intersection point of the iEnvelopes(LOWER_LINE) and iMA indicators
pEmission=EnvMa.CalcPoint(ibEnvelopesLower[1],ibEnvelopesLower[0],ibMA[1],ibMA[0],T[0]);
if(pEmission.real) // if the intersection point is found, add it to the time series of emission
tsMA[1].Write(pEmission);
}
//---
for(int j=ArraySize(handle_MA)-1; j>=0; j--)
{
if(i!=j)
{
if(!CopyBufferAsSeries(handle_MA[j],0,0,2,true,ibMA1))
return;
//--- find the intersection point of the iMA and iMA indicators
pEmission=EnvMa.CalcPoint(ibMA1[1],ibMA1[0],ibMA[1],ibMA[0],T[0]);
if(pEmission.real) // if the intersection point is found, add it to the time series of emission
tsMA[2].Write(pEmission);
}
}
}
//--- deletion of the graphical objects of emission not to stuff the chart
if(T[0]>prevTimeBar)
{
prevTimeBar=T[0];
//---
for(int i=ArraySize(n)-1; i>=0; i--)
sumprev[i]=integral[i].y;
//---
for(int obj=ObjectsTotal(0,0,-1)-1;obj>=0;obj--)
{
string obj_name=ObjectName(0,obj,0,OBJ_TREND);
datetime obj_time=(datetime)ObjectGetInteger(0,obj_name,OBJPROP_TIME);
if(obj_time<T[0]-DEL*PeriodSeconds())
ObjectDelete(0,obj_name);
}
Comment("Emission © DC2008   Graphical objects = ",ObjectsTotal(0,0,-1));
}
//--- calculation of integral characteristics of emission
for(int i=ArraySize(n)-1; i>=0; i--)
//--- displaying integral characteristics of emission
ArrayInitialize(W,5);
if(integral[0].n>integral[1].n)
{
W[0]=20;
W[1]=10;
}
else
{
W[0]=10;
W[1]=20;
}
for(int i=ArraySize(n)-1; i>=0; i--)
{
//--- horizontal lines of mean prices
name="H.line."+(string)i;
ObjectCreate(0,name,OBJ_HLINE,0,0,0,0);
ObjectSetInteger(0,name,OBJPROP_COLOR,colorLine[i]);
ObjectSetInteger(0,name,OBJPROP_STYLE,STYLE_DASHDOT);
ObjectSetInteger(0,name,OBJPROP_WIDTH,1);
ObjectSetDouble(0,name,OBJPROP_PRICE,integral[i].y);
//--- markers
name="P."+(string)i;
ObjectCreate(0,name,OBJ_TEXT,0,0,0);
ObjectSetString(0,name,OBJPROP_FONT,"Wingdings");
ObjectSetInteger(0,name,OBJPROP_ANCHOR,ANCHOR_CENTER);
ObjectSetInteger(0,name,OBJPROP_FONTSIZE,fontMarker[i]);
ObjectSetString(0,name,OBJPROP_TEXT,CharToString(163));
ObjectSetInteger(0,name,OBJPROP_COLOR,colorLine[i]);
ObjectSetDouble(0,name,OBJPROP_PRICE,integral[i].y);
ObjectSetInteger(0,name,OBJPROP_TIME,integral[i].t);
//--- integral curves
name="T"+(string)i+".line"+(string)T[1];
ObjectCreate(0,name,OBJ_TREND,0,0,0);
ObjectSetInteger(0,name,OBJPROP_COLOR,colorLine[i]);
ObjectSetInteger(0,name,OBJPROP_WIDTH,W[i]);
if(sumprev[i]>0)
{
ObjectSetDouble(0,name,OBJPROP_PRICE,0,sumprev[i]);
ObjectSetInteger(0,name,OBJPROP_TIME,0,T[1]);
ObjectSetDouble(0,name,OBJPROP_PRICE,1,integral[i].y);
ObjectSetInteger(0,name,OBJPROP_TIME,1,T[0]);
}
//--- numerical values of integral characteristics
if(integral[0].n+integral[1].n>0)
{
name="Text"+(string)i+".control";
ObjectCreate(0,name,OBJ_TEXT,0,0,0);
ObjectSetInteger(0,name,OBJPROP_ANCHOR,ANCHOR_LEFT_LOWER);
ObjectSetInteger(0,name,OBJPROP_FONTSIZE,fontPoint[i]);
ObjectSetInteger(0,name,OBJPROP_COLOR,colorLine[i]);
string str=DoubleToString((double)integral[i].n/(double)(integral[0].n+integral[1].n)*100,1);
ObjectSetString(0,name,OBJPROP_TEXT,str);
ObjectSetDouble(0,name,OBJPROP_PRICE,0,integral[i].y);
ObjectSetInteger(0,name,OBJPROP_TIME,0,integral[i].t);
}
}
}```

• 通道突破，
• 彼此或与价格交叉，
• 改变方向。

### 总结

1. 指标喷发整体特征的计算，为市场分析（时间序列）提供了新工具、新方法。
2. 利用时间序列，我们已经实现了整体特征计算的速度提高。
3. 而且，它已经为我们打开了使用喷发的自动化交易策略开发的大门。

emission.mqh (5.44 KB)
timeemission.mqh (4.63 KB)
MQL5 编程基础：时间