|
|
#property indicator_separate_window
#property indicator_buffers 7
#property indicator_color1 Black
#property indicator_color2 Red
#property indicator_color3 DeepSkyBlue
#property indicator_color4 Brown
#property indicator_color5 Green
#property indicator_color6 Silver
#property indicator_color7 DarkViolet
//---- input parameters
extern int n=5;
extern int p=10;
extern int q=20;
extern int r=30;
extern int s=99;
extern int t=101;
//---- buffers
double osc[];
double osd[];
double ose[];
double osf[];
double osg[];
double osh[];
double osi[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit(void)
{
//---- indicators
// SetIndexStyle(0,DRAW_HISTOGRAM);
IndicatorDigits(Digits+3);
IndicatorBuffers(7);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,osc);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,osd);
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2,ose);
SetIndexStyle(3,DRAW_LINE);
SetIndexBuffer(3,osf);
SetIndexStyle(4,DRAW_LINE,STYLE_DOT);
SetIndexBuffer(4,osg);
SetIndexStyle(5,DRAW_LINE,STYLE_DOT);
SetIndexBuffer(5,osh);
SetIndexStyle(6,DRAW_LINE,STYLE_DOT);
SetIndexBuffer(6,osi);
//----
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
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[])
{
double osc1,osc2,osc3,osc4,osc5;
int limit=rates_total-prev_calculated;
// if(prev_calculated>0)
// limit++;
for (int i=0;i<limit;i++) {
osc1=Close[i];
osc2=iMA(NULL,0,n,0,MODE_SMA,PRICE_CLOSE,i+n);
osc3=iMA(NULL,0,p,0,MODE_SMA,PRICE_CLOSE,i+p);
osc4=iMA(NULL,0,q,0,MODE_SMA,PRICE_CLOSE,i+q);
osc5=iMA(NULL,0,r,0,MODE_SMA,PRICE_CLOSE,i+r);
osc[i]=osc1/osc2*100;
osd[i]=osc1/osc3*100;
ose[i]=osc1/osc4*100;
osf[i]=osc1/osc5*100;
osg[i]=s;
osh[i]=100;
osi[i]=t;
}
if(ose[2]>101 && ose[1]<101 )
{
SendMail(Symbol()+":做空顶部信号",Symbol()+":做空顶部信号,到上层周期确定所处趋势");
}
if(ose[2]>100 && ose[1]<100 )
{
SendMail(Symbol()+":做空中途信号",Symbol()+":做空中途信号,到上层周期确定是否中途加速");
}
if(ose[2]<99 && ose[1]>99 )
{
SendMail(Symbol()+":做多底部信号",Symbol()+":做多底部信号,到上层周期确定所处趋势");
}
if(ose[2]<100 && ose[1]>100 )
{
SendMail(Symbol()+":做多中途信号",Symbol()+":做多中途信号,到上层周期确定是否中途加速");
}
return(rates_total);
}
//+------------------------------------------------------------------+
我想做c/ma(ref(c,n),n)的线,并在金叉或死叉发生后的第二个周期发邮件预警。
现在问题是,这个指标在图上无法自动计算新的烛线数值。必须反复切换周期才能更新。
二,我这个预警的写法对吗?能实现目的吗?假如是4小时周期的话,会不会在4个小时内一直发邮件提醒呢?
|
|