DTS-Fractales

Author: Copyright � 2005, MetaQuotes Software Corp.
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
DTS-Fractales
//+------------------------------------------------------------------+
//| rutina: Sapucay-Fractales.mq4.mq4 
//| Acción: Sugerencias de cambios de tendencia
//| Adaptado: Ruben Dieminger // MasterWhite
//| 
//| Versión 1.1 - Julio 2009 
//| 
//|         - Se incluyo la refencia de lineas punteadas y continuas
//|           a modo de soporte y resistencia, estas lineas se adaptan
//|           al timeframe y se van completando, tienen un ancho regulable
//|           que es manejado de manera diferente para cada timeframe por
//|           las variables que indican "CANTIDAD DE VELAS"
//|           
//|           AnchoLinea_M5=20 
//|           AnchoLinea_M15=20;
//|           AnchoLinea_M30=25;
//|           AnchoLinea_H1=30;
//|           AnchoLinea_H4=40;
//| 
//| Versión 1.1 - Julio 2009 
//| 
//|           # MasterWhite
//| 
//|         - Se ha incluido Tamaño del Fractal 
//|           TamañoDelasEstrellas X Defecto es 0
//| 
//|         - Se ha incluido la distancia del fractal a la vela// MasterWhite
//|           DistanciaFractalVela x Defecto = 2
//| 
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 Sienna   // M15
#property indicator_color2 Sienna   // M15
#property indicator_color3 Blue     // H1
#property indicator_color4 Blue     // H1
#property indicator_color5 Green    // H4
#property indicator_color6 Green    // H4
#property indicator_color7 Lime     // D1
#property indicator_color8 Lime     // D1

extern bool Esquina_Superior_derecha=true;

double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];
double ExtMapBuffer7[];
double ExtMapBuffer8[];

//color M15Color=Sienna;
//color H1Color=Red;
//color H4Color=Blue;
//color D1Color=Sienna;

color M15Color=DimGray;
color H1Color=Blue;
color H4Color=Green;
color D1Color=Lime;

double      iFractalValue=0;
int         LineasCntVelas=20;
int _velas=0;

extern string Ayudas1="---- Linea horizontal del fractal";
extern int  AnchoLinea_M5=20;
extern int  AnchoLinea_M15=20;
extern int  AnchoLinea_M30=25;
extern int  AnchoLinea_H1=30;
extern int  AnchoLinea_H4=40;

extern string Ayudas2="---- Cantidad de Fractales";
extern int  CntBarrasEstudiar_M5=100;
extern int  CntBarrasEstudiar_M15=100;
extern int  CntBarrasEstudiar_M30=80;
extern int  CntBarrasEstudiar_H1=50;
extern int  CntBarrasEstudiar_H4=20;

extern string Ayudas3="---- Tamaño de las estrellas";
extern int  TamañoDelasEstrellas=0;
extern int  DistanciaFractalVela=2;



// ==================================================================
//     Funcion: init
// ------------------------------------------------------------------
//    Objetivo: inicializar buffers, etc
// Programador: MasterWhite
//        Year: Julio 2009
// ==================================================================
int init()
{
   SetIndexStyle(0,DRAW_ARROW,EMPTY,TamañoDelasEstrellas);
   SetIndexArrow(0,217);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexEmptyValue(0,0.0);
   SetIndexStyle(1,DRAW_ARROW,EMPTY,TamañoDelasEstrellas);
   SetIndexArrow(1,218);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexEmptyValue(1,0.0);
   SetIndexStyle(2,DRAW_ARROW,EMPTY,TamañoDelasEstrellas);
   SetIndexArrow(2,217);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexEmptyValue(2,0.0);
   SetIndexStyle(3,DRAW_ARROW,EMPTY,TamañoDelasEstrellas);
   SetIndexArrow(3,218);
   SetIndexBuffer(3,ExtMapBuffer4);
   SetIndexEmptyValue(3,0.0);
   SetIndexStyle(4,DRAW_ARROW,EMPTY,TamañoDelasEstrellas);
   SetIndexArrow(4,217);
   SetIndexBuffer(4,ExtMapBuffer5);
   SetIndexEmptyValue(4,0.0);
   SetIndexStyle(5,DRAW_ARROW,EMPTY,TamañoDelasEstrellas);
   SetIndexArrow(5,218);
   SetIndexBuffer(5,ExtMapBuffer6);
   SetIndexEmptyValue(5,0.0);
   SetIndexStyle(6,DRAW_ARROW,EMPTY,TamañoDelasEstrellas);
   SetIndexArrow(6,217);
   SetIndexBuffer(6,ExtMapBuffer7);
   SetIndexEmptyValue(6,0.0);
   SetIndexStyle(7,DRAW_ARROW,EMPTY,TamañoDelasEstrellas);
   SetIndexArrow(7,218);
   SetIndexBuffer(7,ExtMapBuffer8);
   SetIndexEmptyValue(7,0.0);

   // poner titulos explicativos
   Titulos();

   return(0);
}


// ==================================================================
//     Funcion: deinit
// ------------------------------------------------------------------
//    Objetivo: Cierre del indicador
// Programador: MasterWhite
//        Year: Julio 2009
// ==================================================================
int deinit()
{
   
   int D1=1440, H4=240, H1=60, M15=15,B;
  
   if (Period()==5)  B=CntBarrasEstudiar_M5; //Bars;
   if (Period()==15) B=CntBarrasEstudiar_M15; //Bars;
   if (Period()==30) B=CntBarrasEstudiar_M30; //Bars;
   if (Period()==60) B=CntBarrasEstudiar_H1; //Bars;
   if (Period()==240)B=CntBarrasEstudiar_H4; //Bars;
      
   for (int shift=B;shift>0;shift--)
   {
      ObjectsDeleteAll(StringConcatenate("Fra_",H1,"_L",shift),OBJ_TREND);
   }      
   return(0);
}


// ==================================================================
//     Funcion: Fractal
// ------------------------------------------------------------------
//    Objetivo: Calcular los fractales
// Programador: MasterWhite
//        Year: Julio 2009
// ==================================================================
bool Fractal (string F,int Per, int shift)
  {
   if (Period()>Per) return(-1);
   Per=Per/Period()*2+MathCeil(Per/Period()/2);
   if (shift<Per)return(-1);
   if (shift>Bars-Per)return(-1); 
   for (int i=1;i<=Per;i++)
     {
      if (F=="U")
        {
         // Upper - Arriba
         if (High[shift+i]>High[shift])return(-1);
         if (High[shift-i]>=High[shift])return(-1);     
        }
      if (F=="L")
        {
         // Lower - Abajo
         if (Low[shift+i]<Low[shift])return(-1);
         if (Low[shift-i]<=Low[shift])return(-1);
        }        
     }
   return(1);   
}  


//------------------------------------------------------------------
//     Funcion: start
// Programador: MasterWhite
//        Year: Julio 2009
//------------------------------------------------------------------
int start()
{
   if (Period()==5) LineasCntVelas=AnchoLinea_M5;
   if (Period()==15) LineasCntVelas=AnchoLinea_M15;
   if (Period()==30) LineasCntVelas=AnchoLinea_M30;
   if (Period()==60) LineasCntVelas=AnchoLinea_H1;
   if (Period()==240) LineasCntVelas=AnchoLinea_H4;
   
   // ------------------------------------------------------
   // Establecer cantidad de barras en funcion del TimeFrame
   // ------------------------------------------------------
   int B;
   if (Period()==5)  B=CntBarrasEstudiar_M5; //Bars;
   if (Period()==15) B=CntBarrasEstudiar_M15; //Bars;
   if (Period()==30) B=CntBarrasEstudiar_M30; //Bars;
   if (Period()==60) B=CntBarrasEstudiar_H1; //Bars;
   if (Period()==240)B=CntBarrasEstudiar_H4; //Bars;
      
   int D1=1440, H4=240, H1=60, M15=15;
   double P;
   bool prim;
   if (Period()==D1)P=15*Point;
   if (Period()==H4)P=7*Point;
   if (Period()==H1)P=4*Point;
   if (Period()==30)P=3*Point;
   if (Period()==M15)P=2*Point;
   if (Period()==5)P=1*Point;
   if (Period()==1)P=0.5*Point;   

   for (int shift=B;shift>0;shift--)
   {
  
   
      // -------------------------------------------------------------------- 
      // Distancia de velas
      // -------------------------------------------------------------------- 
      if (shift>LineasCntVelas) 
      {  
         // si
         _velas = LineasCntVelas;
      }
      else
      {
         // No
         _velas = shift;
      }

            
      // -------------------------------------------------------------------- 
      // D1  - Fractal
      // -------------------------------------------------------------------- 
      prim =true;
      if (Fractal("U",D1,shift)==1) 
      {
         iFractalValue=High[shift]+P;
         ExtMapBuffer7[shift]=iFractalValue+DistanciaFractalVela*Point;
         if (prim)
         {
            ShowObject(StringConcatenate("Fra_",D1,"_U",shift),shift,D1Color,"SOLID");
            prim = false;     
         }
      }
      else 
      {
         ExtMapBuffer7[shift]=0;
      }

      if (Fractal("L",D1,shift)==1) 
      {
         iFractalValue=Low[shift]-P;
         ExtMapBuffer8[shift]=iFractalValue-DistanciaFractalVela*Point;
         if (prim)
         {
            ShowObject(StringConcatenate("Fra_",D1,"_L",shift),shift,D1Color,"SOLID");
            prim = false;     
         }
      }
      else 
      {
         ExtMapBuffer8[shift]=0;
      }


      // -------------------------------------------------------------------- 
      // H4  - Fractal
      // -------------------------------------------------------------------- 

      if (Fractal("U",H4,shift)==1) 
      {
         iFractalValue =High[shift]+P;
         ExtMapBuffer5[shift]=iFractalValue+DistanciaFractalVela*Point; 
         if (prim)
         {
            ShowObject(StringConcatenate("Fra_",H4,"_U",shift),shift,H4Color,"SOLID");
            prim = false;     
         }
      }
      else 
      {
         ExtMapBuffer5[shift]=0;
      }

      if (Fractal("L",H4,shift)==1) 
      {
         iFractalValue =Low[shift]-P;
         ExtMapBuffer6[shift]=iFractalValue-DistanciaFractalVela*Point;
         if (prim)
         {
            ShowObject(StringConcatenate("Fra_",H4,"_L",shift),shift,H4Color,"SOLID");
            prim = false;     
         }
      }
      else 
      {
         ExtMapBuffer6[shift]=0;
      }


      // -------------------------------------------------------------------- 
      // H1  - Fractal
      // -------------------------------------------------------------------- 
       
      if (Fractal("U",H1,shift)==1) 
      {
         iFractalValue=High[shift]+P;
         ExtMapBuffer3[shift]=iFractalValue+DistanciaFractalVela*Point;
         if (prim)
         {
            ShowObject(StringConcatenate("Fra_",H1,"_U",shift),shift,H1Color,"DOT");
            prim = false;     
         }
      }
      else 
      {
         ExtMapBuffer3[shift]=0;
      }
      if (Fractal("L",H1,shift)==1) 
      {
         iFractalValue =Low[shift]-P;
         ExtMapBuffer4[shift]=iFractalValue-DistanciaFractalVela*Point;
         if (prim)
         {
            ShowObject(StringConcatenate("Fra_",H1,"_L",shift),shift,H1Color,"DOT");
            prim = false;     
         }
      }
      else 
      {
         ExtMapBuffer4[shift]=0;
      }
       
      // -------------------------------------------------------------------- 
      // M15  - Fractal
      // -------------------------------------------------------------------- 

      if (Fractal("U",M15,shift)==1) 
      {
         iFractalValue= High[shift]+P;
         ExtMapBuffer1[shift]=iFractalValue+DistanciaFractalVela*Point;
         if (prim)
         {
            ShowObject(StringConcatenate("Fra_",M15,"_U",shift),shift,M15Color,"DOT");
            prim = false;     
         }
      }  
      else 
      {
         ExtMapBuffer1[shift]=0;
      }
      if (Fractal("L",M15,shift)==1) 
      {
         iFractalValue=Low[shift]-P;
         ExtMapBuffer2[shift]=iFractalValue-DistanciaFractalVela*Point;
         if (prim)
         {
            ShowObject(StringConcatenate("Fra_",M15,"_L",shift),shift,M15Color,"DOT");
            prim = false;     
         }
      }
      else 
      {
         ExtMapBuffer2[shift]=0;
      }

   }
   
   
   return(0);
}


//------------------------------------------------------------------
//     Funcion: Titulos
// Programador: MasterWhite
//        Year: Julio 2009
//------------------------------------------------------------------
int Titulos()
{

   // Titulo
   // 70 50 30 10
   // indicator_color1 Sienna   // M15
   // indicator_color3 Blue     // H1
   // indicator_color5 Green    // H4
   // indicator_color7 Lime     // D1
   ObjectCreate("Fractales", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("Fractales", "SAPUCAY FRACTALES", 09, "Arial Narrow", Yellow);
   ObjectSet("Fractales", OBJPROP_CORNER, Esquina_Superior_derecha);
   ObjectSet("Fractales", OBJPROP_XDISTANCE, 10);
   ObjectSet("Fractales", OBJPROP_YDISTANCE, 180);
   
   ObjectCreate("FraM15", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("FraM15", "M15", 6, "Tahoma Narrow", indicator_color1);
   ObjectSet("FraM15", OBJPROP_CORNER, Esquina_Superior_derecha);
   ObjectSet("FraM15", OBJPROP_XDISTANCE, 70);
   ObjectSet("FraM15", OBJPROP_YDISTANCE, 200); 

   ObjectCreate("FraH1", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("FraH1", "H1", 6, "Tahoma Narrow", indicator_color3);
   ObjectSet("FraH1", OBJPROP_CORNER, Esquina_Superior_derecha);
   ObjectSet("FraH1", OBJPROP_XDISTANCE, 50);
   ObjectSet("FraH1", OBJPROP_YDISTANCE, 200); 

   ObjectCreate("FraH4", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("FraH4", "H4", 6, "Tahoma Narrow", indicator_color5);
   ObjectSet("FraH4", OBJPROP_CORNER, Esquina_Superior_derecha);
   ObjectSet("FraH4", OBJPROP_XDISTANCE, 30);
   ObjectSet("FraH4", OBJPROP_YDISTANCE, 200); 

   ObjectCreate("FraD1", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("FraD1", "D1", 6, "Tahoma Narrow", indicator_color7);
   ObjectSet("FraD1", OBJPROP_CORNER, Esquina_Superior_derecha);
   ObjectSet("FraD1", OBJPROP_XDISTANCE, 10);
   ObjectSet("FraD1", OBJPROP_YDISTANCE, 200); 
   

   // 65 45 25 10
   // indicator_color1 Sienna   // M15
   // indicator_color3 Blue     // H1
   // indicator_color5 Green    // H4
   // indicator_color7 Lime     // D1
   
   // Barras 
   ObjectCreate("FraBM15", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("FraBM15", ".", 45, "Tahoma Narrow", indicator_color1);
   ObjectSet("FraBM15", OBJPROP_CORNER, Esquina_Superior_derecha);
   ObjectSet("FraBM15", OBJPROP_XDISTANCE, 65);
   ObjectSet("FraBM15", OBJPROP_YDISTANCE, 165); 

   ObjectCreate("FraBH1", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("FraBH1", ".", 45, "Tahoma Narrow", indicator_color3);
   ObjectSet("FraBH1", OBJPROP_CORNER, Esquina_Superior_derecha);
   ObjectSet("FraBH1", OBJPROP_XDISTANCE, 45);
   ObjectSet("FraBH1", OBJPROP_YDISTANCE, 165); 

   ObjectCreate("FraBH4", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("FraBH4", ".", 45, "Tahoma Narrow", indicator_color5);
   ObjectSet("FraBH4", OBJPROP_CORNER, Esquina_Superior_derecha);
   ObjectSet("FraBH4", OBJPROP_XDISTANCE, 25);
   ObjectSet("FraBH4", OBJPROP_YDISTANCE, 165); 

   ObjectCreate("FraBD1", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("FraBD1", ".", 45, "Tahoma Narrow", indicator_color7);
   ObjectSet("FraBD1", OBJPROP_CORNER, Esquina_Superior_derecha);
   ObjectSet("FraBD1", OBJPROP_XDISTANCE, 5);
   ObjectSet("FraBD1", OBJPROP_YDISTANCE, 165); 
}


//------------------------------------------------------------------
//     Funcion: ShowObject
// Programador: MasterWhite
//        Year: Julio 2009
//------------------------------------------------------------------
int ShowObject(string _ObjName,int _shift,color _queColor, string _MyEstilo)
{
   ObjectCreate(_ObjName,OBJ_TREND,0,Time[_shift],iFractalValue,Time[_shift-_velas],iFractalValue);
   ObjectSet(_ObjName,OBJPROP_RAY,0);
   ObjectSet(_ObjName,OBJPROP_COLOR,_queColor); 
   if (_MyEstilo=="DOT") ObjectSet(_ObjName,OBJPROP_STYLE,STYLE_DOT);
   if (_MyEstilo=="SOLID") ObjectSet(_ObjName,OBJPROP_STYLE,STYLE_SOLID);
   
}

Comments