miércoles, 22 de julio de 2009

La funcion tipo de vela II.

Bueno, despues de revisar las velas he añadido alguna más a la función como cada vez se hace mas larga la función dejo un enlace ha dicha función.

En el archivo también se pueden encontrar otras funciones, las cuales calculan la tendencia previa, así como los patrones. De momento no las explico, por el hecho de que aún estoy retocándolas, y estas funciones formarán parte de un indicador general.

Además, aún me queda por comprobar el buen funcionamiento.

La función de las velas es:
int tipovela(int i)
{
//Dojis
if(Open[i] == Close[i])
{
if(Low[i] == Open[i])
{
Alert("Doji lapida");
return(4);
}
if((High[i]-Open[i]) == (Open[i]-Low[i]))
{
Alert("Doji clasico");
return(1);
}
if((High[i]-Open[i]) > (3*(Open[i]-Low[i])))
{
Alert("Doji larga sombra superior");
return(2);
}
if((Open[i]-Low[i]) > (3*(High[i]-Open[i])))
{
Alert("Doji larga sombra inferior");//Doji libelula
return(3);
}
Alert("Doji");
return(27);
}


//Marubozus
//Marubozu alcista
if((High[i] == Close[i]) && (Close[i] > Open[i]) &&
(Open[i] == Low[i]))
{
Alert("Marubozu alcista");
return(5);
}
//Marubozu bajista
if((High[i] == Open[i]) && (Open[i] > Close[i]) &&
(Close[i] == Low[i]))
{
Alert("Marubozu bajista");
return(6);
}
//Marubozu cerrado alcista
if((High[i] == Close[i]) && (Close[i] > Open[i]) &&
(Open[i] > Low[i]) &&
((Close[i]-Open[i]) > (3*(Open[i]-Low[i]))) )
{
Alert("Marubozu cerrado alcista");
return(10);
}
//Marubozu cerrado bajista
if((High[i] > Open[i]) && (Open[i] > Close[i]) &&
(Close[i] == Low[i]) &&
((Open[i]-Close[i]) > (3*(High[i]-Open[i]))))
{
Alert("Marubozu cerrado bajista");
return(13);
}
//Marubozu abierto alcista
if((High[i] > Close[i]) && (Close[i] > Open[i]) &&
(Open[i] == Low[i]) &&
((Close[i]-Open[i]) > (3*(High[i]-Close[i]))))
{
Alert("Marubozu abierto alcista");
return(16);
}
//Marubozu abierto bajista
if((High[i] == Open[i]) && (Open[i] > Close[i]) &&
(Close[i] > Low[i]) &&
((Open[i]-Close[i]) > (3*(Close[i]-Low[i]))))
{
Alert("Marubozu abierto bajista");
return(17);
}
//Martillo invertido alcista
if((High[i] > Close[i]) && (Close[i] > Open[i]) &&
(Open[i] == Low[i]) &&
((High[i]-Close[i]) > (2*(Close[i]-Open[i]))))
{
Alert("Martillo invertido alcista");
return(14);
}
//Martillo invertido bajista
if((High[i] > Open[i]) && (Open[i] > Close[i]) &&
(Close[i] == Low[i]) &&
((High[i]-Open[i]) > (2*(Open[i]-Close[i]))))
{
Alert("Martillo invertido bajista");
return(15);
}
//Martillo alcista
if((High[i] == Close[i]) && (Close[i] > Open[i]) &&
(Open[i] > Low[i]) &&
((Open[i]-Low[i]) > (2*(Close[i]-Open[i]))))
{
Alert("Martillo alcista");
return(12);
}
//Martillo bajista
if((High[i] == Open[i]) && (Open[i] > Close[i]) &&
(Close[i] > Low[i]) &&
((Close[i]-Low[i]) > (2*(Open[i]-Close[i]))))
{
Alert("Martillo bajista");
return(11);
}
//Larga sombra superior alcista
if((High[i] > Close[i]) && (Close[i] > Open[i]) &&
(Open[i] > Low[i]) &&
((High[i]-Close[i]) > (3*(Open[i]-Low[i]))) &&
((High[i]-Close[i]) > (3*(Close[i]-Open[i]))))
{
Alert("Larga sombra superior alcista");
return(19);
}
//Larga sombra superior bajista
if((High[i] > Open[i]) && (Open[i] > Close[i]) &&
(Close[i] > Low[i]) &&
((High[i]-Open[i]) > (3*(Close[i]-Low[i]))) &&
((High[i]-Open[i]) > (3*(Open[i]-Close[i]))))
{
Alert("Larga sombra superior bajista");
return(20);
}
//Larga sombra inferior alcista
if((High[i] > Close[i]) && (Close[i] > Open[i]) &&
(Open[i] > Low[i]) &&
((Open[i]-Low[i]) > (3*(Close[i]-Open[i]))) &&
((Open[i]-Low[i]) > (3*(High[i]-Close[i]))))
{
Alert("Larga sombra inferior alcista");
return(21);
}
//Larga sombra inferior bajista
if((High[i] > Open[i]) && (Open[i] > Close[i]) &&
(Close[i] > Low[i]) &&
((Close[i]-Low[i]) > (3*(Open[i]-Close[i]))) &&
((Close[i]-Low[i]) > (3*(High[i]-Open[i]))))
{
Alert("Larga sombra inferior bajista");
return(22);
}
//Onda alta alcista
if((High[i] > Close[i]) && (Close[i] > Open[i]) &&
(Open[i] > Low[i]) &&
((High[i]-Close[i]) > (3*(Close[i]-Open[i]))) &&
((Open[i]-Low[i]) > (3*(Close[i]-Open[i]))))
{
Alert("Onda alta alcista");
return(23);
}
//Onda alta bajista
if((High[i] > Open[i]) && (Open[i] > Close[i]) &&
(Close[i] > Low[i]) &&
((High[i]-Open[i]) > (3*(Open[i]-Close[i]))) &&
((Close[i]-Low[i]) > (3*(Open[i]-Close[i]))) )
{
Alert("Onda alta bajista");
return(24);
}
//Peonza alcista
if((High[i] > Close[i]) && (Close[i] > Open[i]) &&
(Open[i] > Low[i]) &&
// ((High[i]-Close[i]) < (Close[i]-Open[i])) && // ((Open[i]-Low[i]) < (Close[i]-Open[i])) && ((High[i]-Close[i]) == (Close[i]-Open[i])) && ((Open[i]-Low[i]) == (Close[i]-Open[i])) && ((MathAbs(Close[i]-Open[i])) < (MathAbs(Close[i+1]-Open[i+1]))) && ((MathAbs(Close[i]-Open[i])) < (MathAbs(Close[i+2]-Open[i+2]))) && ((MathAbs(Close[i]-Open[i])) < (MathAbs(Close[i+3]-Open[i+3]))) ) { Alert("Peonza alcista"); return(8); } //Peonza bajista if((High[i] > Open[i]) && (Open[i] > Close[i]) &&
(Close[i] > Low[i]) &&
((High[i]-Open[i]) < (Open[i]-Close[i])) && ((Close[i]-Low[i]) < (Open[i]-Close[i])) && ((High[i]-Open[i]) == (Close[i]-Low[i])) && ((MathAbs(Close[i]-Open[i])) < (MathAbs(Close[i+1]-Open[i+1]))) && ((MathAbs(Close[i]-Open[i])) < (MathAbs(Close[i+2]-Open[i+2]))) && ((MathAbs(Close[i]-Open[i])) < (MathAbs(Close[i+3]-Open[i+3]))) ) { Alert("Peonza bajista"); return(7); } //Gran vela alcista if((High[i] > Close[i]) && (Close[i] > Open[i]) &&
(Open[i] > Low[i]) &&
((Close[i]-Open[i]) > (3*(High[i]-Close[i]))) &&
((Close[i]-Open[i]) > (3*(Open[i]-Low[i]))) &&
((MathAbs(Close[i]-Open[i])) > (3*(MathAbs(Open[i+1]-Close[i+1])))) &&
((MathAbs(Close[i]-Open[i])) > (3*(MathAbs(Open[i+2]-Close[i+2])))) &&
((MathAbs(Close[i]-Open[i])) > (3*(MathAbs(Open[i+3]-Close[i+3])))) )
{
Alert("Gran vela alcista");
return(9);
}
//Larga vela alcista
if((High[i] > Close[i]) && (Close[i] > Open[i]) &&
(Open[i] > Low[i]) &&
((MathAbs(Close[i]-Open[i])) > (MathAbs(Close[i+1]-Open[i+1]))) &&
((MathAbs(Close[i]-Open[i])) > (MathAbs(Close[i+2]-Open[i+2]))) )
{
Alert("Larga vela alcista");
return(25);
}

//Gran vela bajista
if((High[i] > Open[i]) && (Open[i] > Close[i]) &&
(Close[i] > Low[i]) &&
((Open[i]-Close[i]) > (3*(High[i]-Open[i]))) &&
((Open[i]-Close[i]) > (3*(Close[i]-Low[i]))) &&
((MathAbs(Close[i]-Open[i])) > (3*(MathAbs(Open[i+1]-Close[i+1])))) &&
((MathAbs(Close[i]-Open[i])) > (3*(MathAbs(Open[i+2]-Close[i+2])))) &&
((MathAbs(Close[i]-Open[i])) > (3*(MathAbs(Open[i+3]-Close[i+3])))) )
{
Alert("Gran vela bajista");
return(18);
}
//Larga vela bajista
if((High[i] > Open[i]) && (Open[i] > Close[i]) &&
(Close[i] > Low[i]) &&
((MathAbs(Close[i]-Open[i])) > (MathAbs(Close[i+1]-Open[i+1]))) &&
((MathAbs(Close[i]-Open[i])) > (MathAbs(Close[i+2]-Open[i+2]))) )
{
Alert("Larga vela bajista");
return(26);
}
//Ultima comprobacion
//Vela bajista
if((High[i] >= Open[i]) && (Open[i] > Close[i]) &&
(Close[i] >= Low[i]))
{
Alert("Vela bajista");
return(28);
}
//Vela alcista
if((High[i] >= Close[i]) && (Close[i] > Open[i]) &&
(Open[i] >= Low[i]))
{
Alert("Vela alcista");
return(29);
}
return(0);

}
Saludos a todos y espero que os valga.

jueves, 9 de julio de 2009

La función tipo de vela.

Bien supongo que todos conoceis el libro de "Manual de candlestick", Velas japonesas, del señor Ustin.

En el libro se presentan diversos patrones de velas japonesas, supongo que habrá indicadores para metatrader que presenten los patrones de las velas japonesas, pero como a mi me gusta programar decidí hacer una función a la cual se le pasara el número de vela y me dijera el tipo de vela que es.

He tardado en publicar esta función por haber tenido problemas, ya que cuando tenía todo el código programado, se me borró del ordenador, cosas extrañas que pasan, por eso te recomiendo que realices copias de seguridad cada cierto tiempo.

Espero que os guste la función siguiente.

La función solo nos dice el tipo de vela que se ha formado, no identifica los patrones, eso lo haré mas adelante.

int tipovela(int i)
{
//Dojis
if(Open[i] == Close[i])
{
if(Low[i] == Open[i])
{
Alert("Doji lapida");
return(4);
}
if((High[i]-Open[i]) == (Open[i]-Low[i]))
{
Alert("Doji clasico");
return(1);
}
if((High[i]-Open[i]) > (3*(Open[i]-Low[i])))
{
Alert("Doji larga sombra superior");
return(2);
}
if((Open[i]-Low[i]) > (3*(High[i]-Open[i])))
{
Alert("Doji larga sombra inferior");//Doji libelula
return(3);
}
}

//Marubozus
//Marubozu alcista
if((High[i] == Close[i]) && (Close[i] > Open[i]) &&
(Open[i] == Low[i]))
{
Alert("Marubozu alcista");
return(5);
}
//Marubozu bajista
if((High[i] == Open[i]) && (Open[i] > Close[i]) &&
(Close[i] == Low[i]))
{
Alert("Marubozu bajista");
return(6);
}
//Marubozu cerrado alcista
if((High[i] == Close[i]) && (Close[i] > Open[i]) &&
(Open[i] > Low[i]) &&
((Close[i]-Open[i]) > (3*(Open[i]-Low[i]))) )
{
Alert("Marubozu cerrado alcista");
return(10);
}
//Marubozu cerrado bajista
if((High[i] > Open[i]) && (Open[i] > Close[i]) &&
(Close[i] == Low[i]) &&
((Open[i]-Close[i]) > (3*(High[i]-Open[i]))))
{
Alert("Marubozu cerrado bajista");
return(13);
}
//Marubozu abierto alcista
if((High[i] > Close[i]) && (Close[i] > Open[i]) &&
(Open[i] == Low[i]) &&
((Close[i]-Open[i]) > (3*(High[i]-Close[i]))))
{
Alert("Marubozu abierto alcista");
return(16);
}
//Marubozu abierto bajista
if((High[i] == Open[i]) && (Open[i] > Close[i]) &&
(Close[i] > Low[i]) &&
((Open[i]-Close[i]) > (3*(Close[i]-Low[i]))))
{
Alert("Marubozu abierto bajista");
return(17);
}
//Martillo invertido alcista
if((High[i] > Close[i]) && (Close[i] > Open[i]) &&
(Open[i] == Low[i]) &&
((High[i]-Close[i]) > (2*(Close[i]-Open[i]))))
{
Alert("Martillo invertido alcista");
return(14);
}
//Martillo invertido bajista
if((High[i] > Open[i]) && (Open[i] > Close[i]) &&
(Close[i] == Low[i]) &&
((High[i]-Open[i]) > (2*(Open[i]-Close[i]))))
{
Alert("Martillo invertido bajista");
return(15);
}
//Martillo alcista
if((High[i] == Close[i]) && (Close[i] > Open[i]) &&
(Open[i] > Low[i]) &&
((Open[i]-Low[i]) > (2*(Close[i]-Open[i]))))
{
Alert("Martillo alcista");
return(12);
}
//Martillo bajista
if((High[i] == Open[i]) && (Open[i] > Close[i]) &&
(Close[i] > Low[i]) &&
((Close[i]-Low[i]) > (2*(Open[i]-Close[i]))))
{
Alert("Martillo bajista");
return(11);
}
//Larga sombra superior alcista
if((High[i] > Close[i]) && (Close[i] > Open[i]) &&
(Open[i] > Low[i]) &&
((High[i]-Close[i]) > (3*(Close[i]-Open[i]))) &&
((Open[i]-Low[i]) < (Close[i]-Open[i]))) { Alert("Larga sombra superior alcista"); return(19); } //Larga sombra superior bajista if((High[i] > Open[i]) && (Open[i] > Close[i]) &&
(Close[i] > Low[i]) &&
((High[i]-Open[i]) > (3*(Open[i]-Close[i]))) &&
((Close[i]-Low[i]) < (Open[i]-Close[i]))) { Alert("Larga sombra superior bajista"); return(20); } //Larga sombra inferior alcista if((High[i] > Close[i]) && (Close[i] > Open[i]) &&
(Open[i] > Low[i]) &&
((High[i]-Close[i]) < (Close[i]-Open[i])) && ((Open[i]-Low[i]) > (3*(Close[i]-Open[i]))))
{
Alert("Larga sombra inferior alcista");
return(21);
}
//Larga sombra inferior bajista
if((High[i] > Open[i]) && (Open[i] > Close[i]) &&
(Close[i] > Low[i]) &&
((High[i]-Open[i]) < (Open[i]-Close[i])) && ((Close[i]-Low[i]) > (3*(Open[i]-Close[i]))))
{
Alert("Larga sombra inferior bajista");
return(22);
}
//Onda alta alcista
if((High[i] > Close[i]) && (Close[i] > Open[i]) &&
(Open[i] > Low[i]) &&
((High[i]-Close[i]) > (3*(Close[i]-Open[i]))) &&
((Open[i]-Low[i]) > (3*(Close[i]-Open[i]))))
{
Alert("Onda alta alcista");
return(23);
}
//Onda alta bajista
if((High[i] > Open[i]) && (Open[i] > Close[i]) &&
(Close[i] > Low[i]) &&
((High[i]-Open[i]) > (3*(Open[i]-Close[i]))) &&
((Close[i]-Low[i]) > (3*(Open[i]-Close[i]))) )
{
Alert("Onda alta bajista");
return(24);
}
//Peonza alcista
if((High[i] > Close[i]) && (Close[i] > Open[i]) &&
(Open[i] > Low[i]) &&
((High[i]-Close[i]) < (Close[i]-Open[i])) && ((Open[i]-Low[i]) < (Close[i]-Open[i])) && ((MathAbs(Close[i]-Open[i])) < (MathAbs(Close[i+1]-Open[i+1]))) && ((MathAbs(Close[i]-Open[i])) < (MathAbs(Close[i+2]-Open[i+2]))) && ((MathAbs(Close[i]-Open[i])) < (MathAbs(Close[i+3]-Open[i+3]))) ) { Alert("Peonza alcista"); return(8); } //Peonza bajista if((High[i] > Open[i]) && (Open[i] > Close[i]) &&
(Close[i] > Low[i]) &&
((High[i]-Open[i]) < (Open[i]-Close[i])) && ((Close[i]-Low[i]) < (Open[i]-Close[i])) && ((MathAbs(Close[i]-Open[i])) < (MathAbs(Close[i+1]-Open[i+1]))) && ((MathAbs(Close[i]-Open[i])) < (MathAbs(Close[i+2]-Open[i+2]))) && ((MathAbs(Close[i]-Open[i])) < (MathAbs(Close[i+3]-Open[i+3]))) ) { Alert("Peonza bajista"); return(7); } //Gran vela alcista if((High[i] > Close[i]) && (Close[i] > Open[i]) &&
(Open[i] > Low[i]) &&
((Close[i]-Open[i]) > (3*(High[i]-Close[i]))) &&
((Close[i]-Open[i]) > (3*(Open[i]-Low[i]))) &&
((MathAbs(Close[i]-Open[i])) > (3*(MathAbs(Open[i+1]-Close[i+1])))) &&
((MathAbs(Close[i]-Open[i])) > (3*(MathAbs(Open[i+2]-Close[i+2])))) &&
((MathAbs(Close[i]-Open[i])) > (3*(MathAbs(Open[i+3]-Close[i+3])))) )
{
Alert("Gran vela alcista");
return(9);
}
//Gran vela bajista
if((High[i] > Open[i]) && (Open[i] > Close[i]) &&
(Close[i] > Low[i]) &&
((Open[i]-Close[i]) > (3*(High[i]-Open[i]))) &&
((Open[i]-Close[i]) > (3*(Close[i]-Low[i]))) &&
((MathAbs(Close[i]-Open[i])) > (3*(MathAbs(Open[i+1]-Close[i+1])))) &&
((MathAbs(Close[i]-Open[i])) > (3*(MathAbs(Open[i+2]-Close[i+2])))) &&
((MathAbs(Close[i]-Open[i])) > (3*(MathAbs(Open[i+3]-Close[i+3])))) )
{
Alert("Gran vela bajista");
return(18);
}

return(0);
}


Como puedes observar en el código la función da una alerta cada vez que se produce una de las velas conocidas.

Esta función se debe de añadir en el código de nuestro indicador o de nuestro expert advisor, además se debería llamar a la función cada vez que se produce una nueva vela, pero también se puede obtener una vela determinada.

Este es una primera versión de la función, aún estoy comprobando dicha función en tiempo real, y me falta añadira alguna que otra cosa.

Saludos a todos.