Besoin d'aide sur un indicateur en MQL

Forum sur le trading automatique et algorithmique : systèmes, backtests, robots de trading, résultats et limites, code à l'appui.
Boom
Apprenti Jedi
Messages : 801
Enregistré le : 09 janv. 2017 10:56

Besoin d'aide sur un indicateur en MQL

Message non lu par Boom »

Bonjour à tous,

Je viens de programmé un nouvel EA mais pendant les tests, je me suis aperçu d'un bug dans un indicateur, il m'envoie une valeur hors plage (2147483647).

J'ai beau le scruté, je ne vois pas ce qui cloche, en attendant de trouvé une solution, j'exclue l'ouverture d'une position en cas de valeur hors plage, mais du coup moins de trades.

Ci-dessous, l'appel dans mon EA, peu importe le pointeur, la valeur hors plage ne se situe jamais sur le même.

Code : #

   HMAFast=iCustom(NULL,5,"Hma",PeriodHMAFast,3,0,0,0);
   HMAFastPrev1=iCustom(NULL,5,"Hma",PeriodHMAFast,3,0,0,1);
   HMAFastPrev2=iCustom(NULL,5,"Hma",PeriodHMAFast,3,0,0,2);
Et ci-dessous le code de l'indicateur.

Merci par avance.

Code : #

//+---------------------------------------------------------------------------+ 
//| HMA.mq4                                                                   |
//| Copyright © 2006 WizardSerg <wizardserg@mail.ru>, ForexMagazine #104      |
//| wizardserg@mail.ru                                                        |
//| Revised by IgorAD,igorad2003@yahoo.co.uk                                  |   
//| Personalized by iGoR AKA FXiGoR for the Trend Slope Trading method (T_S_T)|
//| Link:                                                                     |
//| contact: thefuturemaster@hotmail.com                                      |                                
//+---------------------------------------------------------------------------+
#property copyright "MT4 release WizardSerg <wizardserg@mail.ru>, ForexMagazine #104"
#property link      "wizardserg@mail.ru"
//----
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 Red
//---- input parameters 
extern int    period = 0;
extern int    method = 3;                        
extern int    price = 0;                           
//---- buffers 
double Uptrend[];
double Dntrend[];
double ExtMapBuffer[];
//+------------------------------------------------------------------+ 
//| Custom indicator initialization function                         | 
//+------------------------------------------------------------------+ 
int init()
  {
   IndicatorBuffers(3);
   SetIndexBuffer(0, Uptrend);
   //Ar SetAsSeries(Uptrend, true); 
   SetIndexBuffer(1, Dntrend);
   //Ar SetAsSeries(Dntrend, true); 
   SetIndexBuffer(2, ExtMapBuffer);
   Ar SetAsSeries(ExtMapBuffer, true);
//----
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);
//----
   IndicatorShortName("Signal Line("+period+")");
   return(0);
  }
//+------------------------------------------------------------------+ 
//| Custor indicator deinitialization function                       | 
//+------------------------------------------------------------------+ 
int deinit()
  { 
   return(0);
  } 
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double WMA(int x, int p)
  {
   return(iMA(NULL, 0, p, 0, method, price, x));
  }
//+------------------------------------------------------------------+ 
//| Custom indicator iteration function                              | 
//+------------------------------------------------------------------+ 
int start()
  {
   int counted_bars=IndicatorCounted();
   if(counted_bars < 0)
      return(-1);
//----
   int x=0;
   int p=MathSqrt(period);
   int e=Bars - counted_bars + period + 1;
//----
   double vect[], trend[];
//----
   if(e > Bars)
      e=Bars;
//----
   Ar Resize(vect, e);
   Ar SetAsSeries(vect, true);
   Ar Resize(trend, e);
   Ar SetAsSeries(trend, true);
//----
   for(x=0; x < e; x++)
     {
      vect[x]=2*WMA(x, period/2) - WMA(x, period);
      }
   for(x=0; x < e-period; x++)
//----
      ExtMapBuffer[x]=MathFloor((iMAOnAr (vect, 0, p, 0, method, x))*100)/100;
   for(x=e-period; x>=0; x--)
     {
      trend[x]=trend[x+1];
      if (ExtMapBuffer[x]> ExtMapBuffer[x+1]) trend[x] =1;
      if (ExtMapBuffer[x]< ExtMapBuffer[x+1]) trend[x] =-1;
      if (trend[x]>0)
        { 
         Uptrend[x]=ExtMapBuffer[x];
         if (trend[x+1]<0) Uptrend[x+1]=ExtMapBuffer[x+1];
         Dntrend[x]=EMPTY_VALUE;
        }
      else
         if (trend[x]<0)
           {
            Dntrend[x]=ExtMapBuffer[x];
            if (trend[x+1]>0) Dntrend[x+1]=ExtMapBuffer[x+1];
            Uptrend[x]=EMPTY_VALUE;
           }
      }
   return(0);
  }
//+------------------------------------------------------------------+