发新话题
打印

[指标EA编写讨论] 老师给看一下,我给指标加的报警怎么没反应

老师给看一下,我给指标加的报警怎么没反应

//+------------------------------------------------------------------+
//|                                                Nina_StepMA_1.mq4 |
//+------------------------------------------------------------------+
#property indicator_separate_window

#property indicator_buffers 4
#property indicator_color1 Yellow
#property indicator_color2 Aqua
#property indicator_color3 Blue
#property indicator_color4 Red

#property indicator_minimum 0
#property indicator_maximum 1

extern string Comment1             = "1234 ";
extern string Comment2             = "email : xzcz1234@163.com";
//----input parameters
extern int PeriodWATR=10;
extern double Kwatr=1.0000;
extern int HighLow=0;
extern int CalculatedBars = 2000;

extern bool   EnableSoundAlert     = true;
extern bool   EnableVisualAlert    = true;
extern bool   EnableEmailAlert     = true;
//---- indicator buffers
double LineMinBuffer[];
double LineMidBuffer[];
double LineBuyBuffer[];
double LineSellBuffer[];

static datetime alertTag = D'1980.01.01';
static datetime soundTag = D'1980.01.01';
static datetime emailTag = D'1980.01.01';
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
  string short_name;
  IndicatorBuffers(4);
//---- indicator line
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
   SetIndexStyle(2,DRAW_ARROW,STYLE_SOLID,1);
   SetIndexStyle(3,DRAW_ARROW,STYLE_SOLID,1);
   
   SetIndexEmptyValue(2,0);
   SetIndexArrow(2,233);
   SetIndexEmptyValue(3,0);
   SetIndexArrow(3,234);
   
   SetIndexBuffer(0,LineMinBuffer);
   SetIndexBuffer(1,LineMidBuffer);
   SetIndexBuffer(2,LineBuyBuffer);
   SetIndexBuffer(3,LineSellBuffer);

   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
//---- name for DataWindow and indicator subwindow label
   short_name="StepMA_Stoch("+PeriodWATR+","+Kwatr+","+HighLow+")";
   IndicatorShortName(short_name);
//----
   SetIndexDrawBegin(0,PeriodWATR);
   SetIndexDrawBegin(1,PeriodWATR);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int      i,shift,TrendMin,TrendMax,TrendMid;
   double   SminMin0,SmaxMin0,SminMin1,SmaxMin1,SumRange,dK,WATR0,WATRmax,WATRmin,WATRmid;
   double   SminMax0,SmaxMax0,SminMax1,SmaxMax1,SminMid0,SmaxMid0,SminMid1,SmaxMid1;
   double   linemin,linemax,linemid,Stoch1,Stoch2,bsmin,bsmax;
   static bool turn_alarm = true;
          
   int StepSizeMin,StepSizeMax,StepSizeMid;
   double min,max,mid,h,l,c;
   int position_ind0=0, position_ind1=0;
   // position_ind0 = -1, below
   //               =  1, up
          
   ArrayInitialize(LineBuyBuffer,0);
   ArrayInitialize(LineSellBuffer,0);
  
   if(CalculatedBars>Bars || CalculatedBars == 0 ) CalculatedBars = Bars;

   for(shift=CalculatedBars-1;shift>=0;shift--){       
          SumRange=0;
          for (i=PeriodWATR-1;i>=0;i--){
         dK = 1+1.0*(PeriodWATR-i)/PeriodWATR;
         SumRange+= dK*MathAbs(High[i+shift]-Low[i+shift]);
         }
          WATR0 = SumRange/PeriodWATR;
       
          WATRmax=MathMax(WATR0,WATRmax);
          if (shift==CalculatedBars-1-PeriodWATR) WATRmin=WATR0;
          WATRmin=MathMin(WATR0,WATRmin);
       
          StepSizeMin=MathRound(Kwatr*WATRmin/Point);
          StepSizeMax=MathRound(Kwatr*WATRmax/Point);
          StepSizeMid=MathRound(Kwatr*0.5*(WATRmax+WATRmin)/Point);
          
     min = Kwatr*WATRmin;
     max = Kwatr*WATRmax;
     mid = Kwatr*0.5*(WATRmax+WATRmin);
          
          //b = iBarShift(Symbol(),tPeriod,Time[shift]);
          c = Close[shift];//iClose(Symbol(),tPeriod,b);
          h = High[shift];//iHigh(Symbol(),tPeriod,b)
          l = Low[shift];//iLow(Symbol(),tPeriod,b)
          
          if (HighLow>0){
            SmaxMin0=l+2*min;
            SminMin0=h-2*min;
          
            SmaxMax0=l+2*max;
            SminMax0=h-2*max;
          
            SmaxMid0=l+2*mid;
            SminMid0=h-2*mid;
          
            if(c>SmaxMin1) TrendMin=1;
            if(c<SminMin1) TrendMin=-1;
          
            if(c>SmaxMax1) TrendMax=1;
            if(c<SminMax1) TrendMax=-1;
          
            if(c>SmaxMid1) TrendMid=1;
            if(c<SminMid1) TrendMid=-1;
            }
         
          if (HighLow == 0){
            SmaxMin0=c+2*min;
            SminMin0=c-2*min;
          
            SmaxMax0=c+2*max;
            SminMax0=c-2*max;
          
            SmaxMid0=c+2*mid;
            SminMid0=c-2*mid;
          
            if(c>SmaxMin1) TrendMin=1;
            if(c<SminMin1) TrendMin=-1;
          
            if(c>SmaxMax1) TrendMax=1;
            if(c<SminMax1) TrendMax=-1;
          
            if(c>SmaxMid1) TrendMid=1;
            if(c<SminMid1) TrendMid=-1;
            }
                
          if(TrendMin>0 && SminMin0<SminMin1) SminMin0=SminMin1;
          if(TrendMin<0 && SmaxMin0>SmaxMin1) SmaxMin0=SmaxMin1;
               
          if(TrendMax>0 && SminMax0<SminMax1) SminMax0=SminMax1;
          if(TrendMax<0 && SmaxMax0>SmaxMax1) SmaxMax0=SmaxMax1;
          
          if(TrendMid>0 && SminMid0<SminMid1) SminMid0=SminMid1;
          if(TrendMid<0 && SmaxMid0>SmaxMid1) SmaxMid0=SmaxMid1;
          
          
          if (TrendMin>0) linemin=SminMin0+min;
          if (TrendMin<0) linemin=SmaxMin0-min;
          
          if (TrendMax>0) linemax=SminMax0+max;
          if (TrendMax<0) linemax=SmaxMax0-max;
          
          if (TrendMid>0) linemid=SminMid0+mid;
          if (TrendMid<0) linemid=SmaxMid0-mid;
          
          bsmin=linemax-max;
          bsmax=linemax+max;
          Stoch1=(linemin-bsmin)/(bsmax-bsmin);
          Stoch2=(linemid-bsmin)/(bsmax-bsmin);
          
          LineMinBuffer[shift]=Stoch1;
          LineMidBuffer[shift]=Stoch2;
          
          
          SminMin1=SminMin0;
          SmaxMin1=SmaxMin0;
          
          SminMax1=SminMax0;
          SmaxMax1=SmaxMax0;
          
          SminMid1=SminMid0;
          SmaxMid1=SmaxMid0;
          
          // don't do anything for current bar since it is keeping changing.
          if(shift != 0) {  
             position_ind0 = position_ind1;
             if(LineMinBuffer[shift]>LineMidBuffer[shift]){
                position_ind1=1;
             }
             else {
                position_ind1=-1;
             }
          // current bar is keeping on changing
          // so don't put arrow on it
          // that means we only set on signal for confirmed bar
             if((position_ind0==-1) && (position_ind1==1)) {
             // cross up
                LineBuyBuffer[shift] = LineMidBuffer[shift];
             }
             if((position_ind0==1) && (position_ind1==-1)) {
             // cross down
                LineSellBuffer[shift] = LineMidBuffer[shift];
             }
           }
   }
       
        if(Volume[0]>1) return(0);
        // for the current crossing, make the sound
        // still have problem for this mechanism, leave it for later modification          
       
        // Gestione Alert visivo //
        if (EnableVisualAlert==true && i==1 && LineBuyBuffer[shift] > LineSellBuffer[shift] && alertTag!=Time[0])
        {
         Alert("卖出信号 ",Symbol()," ",Periodo(Period()));
         alertTag = Time[0];
        }
        if (EnableVisualAlert==true && i==1 && LineBuyBuffer[shift] < LineSellBuffer[shift] && alertTag!=Time[0])
        {
         Alert("买入信号 ",Symbol()," ",Periodo(Period()));
         alertTag = Time[0];
        }   
         
        // Gestione Alert sonoro //      
        if (EnableSoundAlert==true && i==1 && LineBuyBuffer[shift] > LineSellBuffer[shift] && soundTag!=Time[0])
        {
         PlaySound ("short.wav");
         soundTag = Time[0];
        }
        if (EnableSoundAlert==true && i==1 && LineBuyBuffer[shift] < LineSellBuffer[shift] && soundTag!=Time[0])
        {
         PlaySound ("long.wav");
         soundTag = Time[0];
        }
        
        // Gestione Alert con email //      
        if (EnableEmailAlert==true && i==1 && LineBuyBuffer[shift] > LineSellBuffer[shift] && emailTag!=Time[0])
        {
         SendMail("Supernova alert signal!","卖出信号 " + (StringConcatenate(Symbol()," ",Periodo(Period()))));
         emailTag = Time[0];
        }
        if (EnableEmailAlert==true && i==1 && LineBuyBuffer[shift] < LineSellBuffer[shift] && emailTag!=Time[0])
        {
         SendMail("Supernova alert signal!","买入信号 " + (StringConcatenate(Symbol()," ",Periodo(Period()))));
         emailTag = Time[0];
  
        }
      
        return(0);       
}
string Periodo(int TF)
{
if (TF==1)    { return("M1"); }
if (TF==5)    { return("M5"); }
if (TF==15)   { return("M15"); }
if (TF==30)   { return("M30"); }
if (TF==60)   { return("H1"); }
if (TF==240)  { return("H4"); }
if (TF==1440) { return("D1"); }  
}

//+------------------------------------------------------------------+
附件: 您所在的用户组无法下载或查看附件

TOP

i==1 && LineBuyBuffer[shift] > LineSellBuffer[shift]
检查这部分变量,及变量数组的值。

TOP

请斑竹解释一下

//+------------------------------------------------------------------+
//|                                         EMA-Crossover_Signal.mq4 |
//|         Copyright ?2005, Jason Robinson (jnrtrading)            |
//|                   http://www.jnrtading.co.uk                     |
//+------------------------------------------------------------------+

/*
  +------------------------------------------------------------------+
  | Allows you to enter two ema periods and it will then show you at |
  | Which point they crossed over. It is more usful on the shorter   |
  | periods that get obscured by the bars / candlesticks and when    |
  | the zoom level is out. Also allows you then to remove the emas   |
  | from the chart. (emas are initially set at 5 and 6)              |
  +------------------------------------------------------------------+
*/   
#property copyright "Copyright ?2005, Jason Robinson (jnrtrading)"
#property link      "http://www.jnrtrading.co.uk"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 DodgerBlue
#property indicator_color2 Red

double CrossUp[];
double CrossDown[];
extern int FasterMode = 1; //0=sma, 1=ema, 2=smma, 3=lwma
extern int FasterMA =   13;
extern int SlowerMode = 1; //0=sma, 1=ema, 2=smma, 3=lwma
extern int SlowerMA =   25;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0, DRAW_ARROW, EMPTY);
   SetIndexArrow(0, 233);
   SetIndexBuffer(0, CrossUp);
   SetIndexStyle(1, DRAW_ARROW, EMPTY);
   SetIndexArrow(1, 234);
   SetIndexBuffer(1, CrossDown);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
   int limit, i, counter;
   double fasterMAnow, slowerMAnow, fasterMAprevious, slowerMAprevious, fasterMAafter, slowerMAafter;
   double Range, AvgRange;
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;

   limit=Bars-counted_bars;
   
   for(i = 0; i <= limit; i++) {
   
      counter=i;
      Range=0;
      AvgRange=0;
      for (counter=i ;counter<=i+9;counter++)
      {
         AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
      }
      Range=AvgRange/10;
      
      fasterMAnow = iMA(NULL, 0, FasterMA, 0, FasterMode, PRICE_CLOSE, i);
      fasterMAprevious = iMA(NULL, 0, FasterMA, 0, FasterMode, PRICE_CLOSE, i+1);
      fasterMAafter = iMA(NULL, 0, FasterMA, 0, FasterMode, PRICE_CLOSE, i-1);

      slowerMAnow = iMA(NULL, 0, SlowerMA, 0, SlowerMode, PRICE_CLOSE, i);
      slowerMAprevious = iMA(NULL, 0, SlowerMA, 0, SlowerMode, PRICE_CLOSE, i+1);
      slowerMAafter = iMA(NULL, 0, SlowerMA, 0, SlowerMode, PRICE_CLOSE, i-1);
      
      if ((fasterMAnow > slowerMAnow) && (fasterMAprevious < slowerMAprevious) && (fasterMAafter > slowerMAafter)) {
         CrossUp = Low - Range*0.5;
      }
      else if ((fasterMAnow < slowerMAnow) && (fasterMAprevious > slowerMAprevious) && (fasterMAafter < slowerMAafter)) {
         CrossDown = High + Range*0.5;
      }
   }
   return(0);
}

TOP

发新话题