Inicio Indicador técnico Publicación

Expansión Fibo FE: Un Indicador Esencial para MetaTrader 4

Archivos adjuntos
31891.zip (1.76 KB, Descargar 0 veces)

¡Hola a todos los traders!

Hoy vamos a hablar sobre el indicador de expansión de Fibonacci (FE) que he creado utilizando dos objetos (P[2]) en un array que representan sus propiedades para cada dirección: arriba o abajo.

A continuación, les muestro cómo se ve la clase:

class ___
  {
   public:
   int aa, bb, cc;
   double A, B, C;
                     ___():
                     aa(0), bb(0), cc(0),
                     A(0.0), B(0.0), C(0.0)
     {}
                    ~___() {}
  } P[2];

En cada dirección, necesitamos tener 3 precios: A, B y C, que representan el precio superior, inferior y un precio intermedio. Mientras tanto, aa, bb y cc son las ubicaciones de las barras para sus respectivos precios A, B y C.

Luego, utilicé la fórmula de fractales junto con algunas modificaciones para determinar los 3 puntos: superior, inferior y el precio intermedio, junto con sus direcciones.

Utilizo un bucle desde la ubicación de la barra más reciente:

//---
   int i=0;
   int m=0, n=0;
   bool stop=false;
   double hi=0.0, lo=0.0;
//---
   A=0.0;
   B=0.0;
   C=0.0;
   for(m=0, n=0, i=0; i<Bars-5 && !stop; i++)
     {
       hi=(
            iHigh(_Symbol,0,i+2)>=iHigh(_Symbol,0,i+0) &&
            iHigh(_Symbol,0,i+2)>=iHigh(_Symbol,0,i+1) &&
            iHigh(_Symbol,0,i+2)>=iHigh(_Symbol,0,i+3) &&
            iHigh(_Symbol,0,i+2)>=iHigh(_Symbol,0,i+4))
         ? iHigh(_Symbol,0,i+2):0.0;
       lo=(
            iLow(_Symbol,0,i+2)<=iLow(_Symbol,0,i+0) &&
            iLow(_Symbol,0,i+2)<=iLow(_Symbol,0,i+1) &&
            iLow(_Symbol,0,i+2)<=iLow(_Symbol,0,i+3) &&
            iLow(_Symbol,0,i+2)<=iLow(_Symbol,0,i+4))
         ? iLow(_Symbol,0,i+2):0.0;
      //---
      //---
      //--------------------------------------------------------------------------------------------------------------------
      //--------------------------------------------------------------------------------------------------------------------
      if(hi!=0.0)// ------------subida------------
        {
         if(P[1].C!=0.0)
           {
            if(n==2)
              {
               if(P[1].B<hi&&P[1].C<P[1].B)
                 {
                   P[1].B=hi;   //modifico B[1] antes de que A[1] exista
                 P[1].bb=i+2;
              }
            if(n==1)
          {
               if(P[1].C<hi)
                 {
                   P[1].B=hi;   //esto es B[1] bajando
                   P[1].bb=i+2;
                   n++;
                 }
               else
                 {
                   n--;
                   P[1].C=0.0;
                 }
              }
       }
       //---
       if(P[0].C==0.0)
         {
           if(m<1)
          {
               P[0].C=hi;   //inicial C[0] subiendo
               P[0].cc=i+2;
               m++;
          }
       }
       else
       {
           if(m==2)
          {
           if(P[0].C<hi)
                 {
                   P[0].A=hi;   //esto es A[0] subiendo
                   P[0].aa=i+2;
               m=0;
                 stop=true;
                 }
              }
            if(m==1)
          {
           if(P[0].C<hi)
                 {
                   P[0].C=hi;   //esto modifica C[0] antes de que exista B[0]
                 P[0].cc=i+2;
              }
          }
       }
      //---
      }
      //si no
      if(lo!=0.0)// ------------bajada------------
        {
         if(P[0].C!=0.0)
           {
            if(m==2)
              {
               if(P[0].B>lo&&P[0].C>P[0].B)
                 {
                   P[0].B=lo;   //modifico B[0] antes de que A[0] exista
                 P[0].bb=i+2;
                 }
            if(m==1)
          {
           if(P[0].C>lo)
                 {
                   P[0].B=lo;   //esto es B[0] subiendo
                   P[0].bb=i+2;
                   m++;
                 }
                 else
                 {
                   m--;
                   P[0].C=0.0;
                 }
              }
       }
       //---
       if(P[1].C==0.0)
         {
           if(n<1)
          {
               P[1].C=lo;   //inicial C[1] bajando
               P[1].cc=i+2;
               n++;
              }
          }
           else
           {
            if(n==2)
              {
               if(P[1].C>lo)
                 {
                   P[1].A=lo;   //esto es A[1] bajando
                   P[1].aa=i+2;
                 n=0;
                 stop=true;
                 }
              }
            if(n==1)
              {
               if(P[1].C>lo)
                 {
                   P[1].C=lo;   //esto modifica C[1] antes de que exista B[1]
                 P[1].cc=i+2;
                 }
              }
           }
       //---
       if((P[0].C==0.0&&P[1].C==0.0)||(hi==0.0&&lo==0.0))
        {
         continue;
        }
     }// bucle

Si se encuentran los 3 puntos en dirección arriba o abajo, el bucle se detiene.

Luego, necesito extraer los 3 puntos previamente definidos.

   if(P[0].A!=0.0&&P[0].B!=0.0&&P[0].C!=0.0)
     {
       DrawExpansion(tool,"FE ->",Time[P[0].aa],P[0].A,Time[P[0].bb],P[0].B,Time[P[0].cc],P[0].C,-1);
     }
//---
   if(P[1].A!=0.0&&P[1].B!=0.0&&P[1].C!=0.0)
     {
       DrawExpansion(tool,"FE ->",Time[P[1].aa],P[1].A,Time[P[1].bb],P[1].B,Time[P[1].cc],P[1].C,1);
     }

Y finalmente, dibujamos utilizando el objeto OBJ_EXPANSION y utilizo una única función DrawExpansion(...).

void DrawExpansion(string name,string label,datetime t1,double p1,datetime t2,double p2,datetime t3,double p3,int fl=0)
  {
//---
   ObjectDelete(name);
   color wrn=(fl>0)?clrSkyBlue:(fl<0)?clrTomato:clrWhite;
   if(ObjectFind(0,name)!=0)
      ObjectCreate(name,OBJ_EXPANSION,0,t1,p1,t2,p2,t3,p3);
   ObjectSet(name,OBJPROP_FIBOLEVELS,5);
   ObjectSet(name,OBJPROP_FIRSTLEVEL+0,0.618);
   ObjectSet(name,OBJPROP_FIRSTLEVEL+1,1.000);
   ObjectSet(name,OBJPROP_FIRSTLEVEL+2,1.618);
   ObjectSet(name,OBJPROP_FIRSTLEVEL+3,2.618);
   ObjectSet(name,OBJPROP_FIRSTLEVEL+4,4.236);
//---
   ObjectSet(name,OBJPROP_LEVELCOLOR,clrMediumPurple);
   ObjectSet(name,OBJPROP_LEVELWIDTH,1);
   ObjectSet(name,OBJPROP_LEVELSTYLE,0);
   ObjectSet(name,OBJPROP_COLOR,wrn);
//---
   ObjectSetFiboDescription(name,0,label+"  "+DoubleToStr(0.618*100,1)+"  ");
   ObjectSetFiboDescription(name,1,label+"  "+DoubleToStr(1.000*100,1)+"  ");
   ObjectSetFiboDescription(name,2,label+"  "+DoubleToStr(1.618*100,1)+"  ");
   ObjectSetFiboDescription(name,3,label+"  "+DoubleToStr(2.618*100,1)+"  ");
   ObjectSetFiboDescription(name,4,label+"  "+DoubleToStr(4.236*100,1)+"  ");
  //---
  }

Aquí, utilizo los niveles:

  • 0.618,
  • 1.000,
  • 1.618,
  • 2.618 y
  • 4.236.




Publicaciones relacionadas

Comentarios (0)