Página 1 de 1

Indicador Heiken Ashi en varios time con 1 error

Publicado: 22 Abr 2014 00:50
por rau
Hola, llevo tiempo buscando este indicador y ahora que lo he conseguido no deja copilar por que tiene un error el cual no tengo ni idea de solucionar. Si alguien tiene este indicador en perfecto estado o puede solucionar el problema me haría un gran favor.

Gracias.

Código: Seleccionar todo

//+------------------------------------------------------------------+
//|                                               Freebie MTF HA.mq4 |
//|                                     Copyright © 2013, Dredding82 |
//+------------------------------------------------------------------+

#property copyright "Copyright © 2013, Dredding82"

//----

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 5
#property indicator_buffers 8

//----

#property indicator_color1 Red
#property indicator_color2 SpringGreen
#property indicator_color3 Red
#property indicator_color4 SpringGreen
#property indicator_color5 Red
#property indicator_color6 SpringGreen
#property indicator_color7 Red
#property indicator_color8 SpringGreen

//---- parameters

extern bool Pop_Up_Alert = true;
extern string SoundFile = "alert.wav";
extern bool Email_Alert = false;
extern int MaxBars = 300;


color BarColorUp=SpringGreen;
color BarColorDown=Red;
color TextColor=White;

double Gap=1; // Gap between the lines of bars
//---- buffers
double buf4_up[];
double buf4_down[];
double buf3_up[];
double buf3_down[];
double buf2_up[];
double buf2_down[];
double buf1_up[];
double buf1_down[];
double HAopen;
double HAclose;

bool allUp;
bool allDn;
datetime lastAudioAlert = 0;
datetime lastEmailAlert = 0;
string shortname;
//----
int ArrSize=110;//159 for dots
 int BarWidth=0;
int UniqueNum=2282;
int periods[] = {1, 5, 15, 30, 60, 240, 1440, 10080, 43200};
int currentIndex;
int Period_1, Period_2, Period_3, Period_4, PeriodStart;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   SetIndexStyle(0,DRAW_ARROW,0,BarWidth,BarColorUp);
   SetIndexArrow(0,ArrSize);
   SetIndexBuffer(0,buf1_up);
   SetIndexEmptyValue(0,0.0);
   SetIndexStyle(1,DRAW_ARROW,0,BarWidth,BarColorDown);
   SetIndexArrow(1,ArrSize);
   SetIndexBuffer(1,buf1_down);
   SetIndexEmptyValue(1,0.0);
   SetIndexStyle(2,DRAW_ARROW,0,BarWidth,BarColorUp);
   SetIndexArrow(2,ArrSize);
   SetIndexBuffer(2,buf2_up);
   SetIndexEmptyValue(2,0.0);
   SetIndexStyle(3,DRAW_ARROW,0,BarWidth,BarColorDown);
   SetIndexArrow(3,ArrSize);
   SetIndexBuffer(3,buf2_down);
   SetIndexEmptyValue(3,0.0);
   SetIndexStyle(4,DRAW_ARROW,0,BarWidth,BarColorUp);
   SetIndexArrow(4,ArrSize);
   SetIndexBuffer(4,buf3_up);
   SetIndexEmptyValue(4,0.0);
   SetIndexStyle(5,DRAW_ARROW,0,BarWidth,BarColorDown);
   SetIndexArrow(5,ArrSize);
   SetIndexBuffer(5,buf3_down);
   SetIndexEmptyValue(5,0.0);
   SetIndexStyle(6,DRAW_ARROW,0,BarWidth,BarColorUp);
   SetIndexArrow(6,ArrSize);
   SetIndexBuffer(6,buf4_up);
   SetIndexEmptyValue(6,0.0);
   SetIndexStyle(7,DRAW_ARROW,0,BarWidth,BarColorDown);
   SetIndexArrow(7,ArrSize);
   SetIndexBuffer(7,buf4_down);
   SetIndexEmptyValue(7,0.0);
//----
   SetIndexLabel(0,NULL);
   SetIndexLabel(1,NULL);
   SetIndexLabel(2,NULL);
   SetIndexLabel(3,NULL);
   SetIndexLabel(4,NULL);
   SetIndexLabel(5,NULL);
   SetIndexLabel(6,NULL);
   SetIndexLabel(7,NULL);
   IndicatorDigits(0);
   getPeriod();
//----
   shortname = "Freebie MTF HA ("+Period_1+","+Period_2+","+Period_3+","+Period_4+")";
   IndicatorShortName(shortname);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- the last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;
   int i,tf;
//-------------------------------1----------------------------------------   
   double dif=Time[0] - Time[1];
   for( i=ObjectsTotal()-1; i>-1; i--)
     {
      if (StringFind(ObjectName(i),"FF_"+UniqueNum+"_")>=0)  ObjectDelete(ObjectName(i));
     }

   for( tf=1; tf<=4; tf++)
     {
      string txt="??";
      double gp;
      switch(tf)
        {
         case 1: txt=tf2txt(Period_1);  gp=1 + 3 + 0.50; break;
         case 2: txt=tf2txt(Period_2);  gp=1 + 2 + 0.50; break;
         case 3: txt=tf2txt(Period_3);  gp=1 + 1 + 0.50; break;
         case 4: txt=tf2txt(Period_4);  gp=1 + 0.50; break;
        }
      string name="FF_"+UniqueNum+"_"+tf+"_"+txt;
      ObjectCreate(name, OBJ_TEXT, WindowFind(shortname), iTime(NULL,0,0)+dif*3, gp);
      ObjectSetText(name, txt,8,"Arial", TextColor);
     }
//-------------------------------2----------------------------------------
   datetime TimeArray_4[], TimeArray_3[], TimeArray_2[], TimeArray_1[];
   ArrayCopySeries(TimeArray_1,MODE_TIME,Symbol(),Period_1);
   ArrayCopySeries(TimeArray_2,MODE_TIME,Symbol(),Period_2);
   ArrayCopySeries(TimeArray_3,MODE_TIME,Symbol(),Period_3);
   ArrayCopySeries(TimeArray_4,MODE_TIME,Symbol(),Period_4);
   int  i1=0, i2=0, i3=0, i4=0, yy;
   // for(i=0, i1=0,  i2=0,  i3=0,  i4=0;i<MaxBars;i++)
   for(i=0, i1=0,  i2=0,  i3=0,  i4=0;i<limit;i++)
     {
      if (Time[i]<TimeArray_1[i1]) i1++;
      if (Time[i]<TimeArray_2[i2]) i2++;
      if (Time[i]<TimeArray_3[i3]) i3++;
      if (Time[i]<TimeArray_4[i4]) i4++;
//----
      allUp = true;
      allDn = true;
      for( tf=1; tf<=4; tf++)
        {
         int prd;
         switch(tf)
           {
            case 1: 
               HAopen = iCustom (Symbol(), Period_1, "Heiken Ashi", 2, i1);
               HAclose = iCustom (Symbol(), Period_1, "Heiken Ashi", 3, i1);         
               if (HAclose > HAopen) 
               {
                   buf1_up[i]=1 + Gap * 3;
                   allDn = false;
               } 
               else if (HAclose < HAopen) 
               {
                   buf1_down[i]=1 + Gap * 3;
                   allUp = false;
               }    
               break;
            case 2: 
               HAopen = iCustom (Symbol(), Period_2, "Heiken Ashi", 2, i2);
               HAclose = iCustom (Symbol(), Period_2, "Heiken Ashi", 3, i2);         
               if (HAclose > HAopen) 
               {
                   buf2_up[i]=1 + Gap * 2;
                   allDn = false;
               } 
               else if (HAclose < HAopen) 
               {
                   buf2_down[i]=1 + Gap * 2;
                   allUp = false;
               }        
               break;
            case 3: 
               HAopen = iCustom (Symbol(), Period_3, "Heiken Ashi", 2, i3);
               HAclose = iCustom (Symbol(), Period_3, "Heiken Ashi", 3, i3);         
               if (HAclose > HAopen) 
               {
                   buf3_up[i]=1 + Gap * 1;
                   allDn = false;
               } 
               else if (HAclose < HAopen) 
               {
                   buf3_down[i]=1 + Gap * 1;
                   allUp = false;
               }     
               break;
            case 4: 
               HAopen = iCustom (Symbol(), Period_4, "Heiken Ashi", 2, i4);
               HAclose = iCustom (Symbol(), Period_4, "Heiken Ashi", 3, i4);         
               if (HAclose > HAopen) 
               {
                   buf4_up[i]=1;
               } 
               else if (HAclose < HAopen) 
               {
                   buf4_down[i]=1;
               }     
               break;
           }
        }
}

//---------------Sound / Pop Up Alert / Email Alert
   
double HAopen1  = iCustom (Symbol(), 0, "Heiken Ashi",2,1);
double HAclose1 = iCustom (Symbol(), 0, "Heiken Ashi",3,1);  
 
double HAopen2  = iCustom (Symbol(), 0, "Heiken Ashi",2,2);
double HAclose2 = iCustom (Symbol(), 0, "Heiken Ashi",3,2);

   if (Pop_Up_Alert && HAclose1 > HAopen1 && HAclose2 < HAopen2 && allUp) {
    if (Time[0]>lastAudioAlert) {
         lastAudioAlert = Time[0];
         Alert("Freebie MTF HA Alert (", Symbol(), ", ", Period(), ")--Possible BUY ");
         PlaySound(SoundFile);
       if (Email_Alert)    
         SendMail("Freebie MTF HA Alert ", " " + Symbol() + " (" + Period() + ") -- Possible BUY"); 
       }
       else if (HAclose1 < HAopen1 && HAclose2 > HAopen2 && allDn) {
         lastAudioAlert = Time[0];
         Alert("Freebie MTF HA Alert (", Symbol(), ", ", Period(), ")--Possible SELL ");
         PlaySound(SoundFile); 
       if (Email_Alert)    
         SendMail("Freebie MTF HA Alert ", " " + Symbol() + " (" + Period() + ") -- Possible SELL");  
       }       
     }
   }
//----
   return(0);

//+------------------------------------------------------------------+
void getPeriod()
  {
    int periodsCount = ArraySize(periods);
    for (int i = 0; i < periodsCount; i++) 
    {
        if (Period() == periods[i]) 
        {
            currentIndex = i;
            break;
        }
    }
    PeriodStart = periods[currentIndex + 1];
    switch(PeriodStart)
     {
      case 1:
         Period_1=1; Period_2=5; Period_3=15; Period_4=30;
         break;
      case 5:
         Period_1=5; Period_2=15; Period_3=30; Period_4=60;
         break;
      case 15:
         Period_1=15; Period_2=30; Period_3=60; Period_4=240;
         break;
      case 30:
         Period_1=30; Period_2=60; Period_3=240; Period_4=1440;
         break;
      case 60:
         Period_1=60; Period_2=240; Period_3=1440; Period_4=10080;
         break;
      case 240:
         Period_1=240; Period_2=1440; Period_3=10080; Period_4=43200;
         break;
      case 1440:
         Period_1=1440; Period_2=10080; Period_3=43200; Period_4=43200;
         break;
      case 10080:
         Period_1=10080; Period_2=43200; Period_3=43200; Period_4=43200;
         break;
      case 43200:
         Period_1=43200; Period_2=43200; Period_3=43200; Period_4=43200;
         break;
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
string tf2txt(int tf)
  {
   if (tf==PERIOD_M1)    return("M1");
   if (tf==PERIOD_M5)    return("M5");
   if (tf==PERIOD_M15)   return("M15");
   if (tf==PERIOD_M30)   return("M30");
   if (tf==PERIOD_H1)    return("H1");
   if (tf==PERIOD_H4)    return("H4");
   if (tf==PERIOD_D1)    return("D1");
   if (tf==PERIOD_W1)    return("W1");
   if (tf==PERIOD_MN1)   return("MN");
   return("??");
  }

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

Re: Indicador Heiken Ashi en varios time con 1 error

Publicado: 22 Abr 2014 11:25
por X-Trader
Hola rau, dos posibles soluciones:

1. La fácil: ¿tienes una copia compilada en un Metatrader antiguo? Copiala en la carpeta de indicadores y reinicia Metatrader, debería funcionar (Metaquotes se ha comprometido a que todos los ex4 antiguos funcionen, no así los mq4)

2. La difícil: postea un pantallazo con los errores que te da y lo veo, a ver si no requiere mucho curro ;)

Saludos,
X-Trader

Re: Indicador Heiken Ashi en varios time con 1 error

Publicado: 22 Abr 2014 14:12
por rau
Hola X-Trader,

No creo porque la que me da error es la que tenía, hace algunos años que dejé este "mundillo" y parece que ahora no funciona.

Imagen

Re: Indicador Heiken Ashi en varios time con 1 error

Publicado: 22 Abr 2014 15:52
por X-Trader
Tendría que revisar el código pero diría por el error que tienes un corchete mal puesto o te sobra un return(0) ;)

Saludos,
X-Trader

Re: Indicador Heiken Ashi en varios time con 1 error

Publicado: 22 Abr 2014 16:48
por mascara
Como dice X, el tercer corchete que se ve ahí, está cerrando la rutina int start() así que el return(0) se queda fuera... debería estar antes del último corchete de esos tres...

Re: Indicador Heiken Ashi en varios time con 1 error

Publicado: 22 Abr 2014 18:57
por rau
Wow, lo metí antes del ultimo corchete y se ha solucionado un problema, como se nota que los que saben, saben jeje. No quiero parecer pesado pero aun tengo un par de problemas en el indicador y parecen estar juntos, os pego la captura si haceis el favor de arreglarlo.

Imagen

Re: Indicador Heiken Ashi en varios time con 1 error

Publicado: 22 Abr 2014 20:46
por mascara
rau escribió:Wow, lo metí antes del ultimo corchete y se ha solucionado un problema, como se nota que los que saben, saben jeje. No quiero parecer pesado pero aun tengo un par de problemas en el indicador y parecen estar juntos, os pego la captura si haceis el favor de arreglarlo.

Imagen
Si te refieres a los mensajes "amarillos", sólo son avisos, así que te debe funcionar igualmente. Yo no uso esto del mq4 ni he programado nunca con él, pero si son avisos tiene que funcionar...
En cualquier caso lo que te dicen es que tienes dos variables declaradas por ahí, que no usas... te valdrá con que busques en el código el nombre que te dice y las borres...
edito: En concreto las variables "prd" y "yy" las tienes en las líneas 177 y 164 aprox...

Re: Indicador Heiken Ashi en varios time con 1 error

Publicado: 23 Abr 2014 14:43
por rau
Cierto!! gracias ya esta funcioando el indicador ;)