Ayuda a la codificación - página 62

 

...

Tienes que hacer 2 cosas
:- declarar la variable "periodo" como doble (MQL a veces se comporta de forma extraña cuando en la división se utiliza una variable de tipo entero)

- inicializar esa variable "periodo" (ahora mismo está sin inicializar y por eso el último paso no ha funcionado)

Después de eso obtendrá algo como esto :

Que tengas un buen fin de semana

chenairbin:
#property indicator_separate_window

#propiedad indicador_buffers 1

#propiedad indicador_color1 Rojo

#propiedad indicador_máximo 100

#propiedad indicador_nivel1 70

#propiedad indicador_nivel2 50

#propiedad indicador_nivel3 30

#propiedad indicador_mínimo 0

//---- parámetros de entrada

extern int rsiperiod = 14 ;

extern int Shortperiod = 5 ;

extern int Middleperiod = 8

extern int Longperiod = 13;

extern int mamode = 2 ;

//---- buffers

double RSI[];

double ShortRSI[];

double MiddleRSI[];

double LongRSI[];

double SMRSI[];

int periodo ;

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

//| Función de inicialización del indicador personalizada ||.

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

int init()

{

//---- indicadores

IndicatorBuffers(5);

SetIndexBuffer(0,SMRSI);

SetIndexBuffer(1,RSI);

SetIndexBuffer(2,ShortRSI);

SetIndexBuffer(3,MiddleRSI);

SetIndexBuffer(4,LongRSI);

//---- nombre para la etiqueta de la DataWindow y la subventana del indicador

IndicatorShortName("SMRSI("+rsiperiod+", "+Shortperiod+", "+Middleperiod+", "+Longperiod+", "+mamode+")";

SetIndexDrawBegin(0,rsiperiod+Longperiod);

period=PeriodoCorto+PeriodoMedio+PeriodoLargo;

return(0);

}

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

//| Función de iteración del indicador personalizada ||.

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

int inicio()

{

int barras_contadas=IndicadorContado();

int i,limit;

if(counted_bars<0) return(-1);

if(barras_contadas>0) barras_contadas--;

limit = Bares-contados_bars;

for( i=limit; i>=0; i--) RSI=iRSI(NULL,0,rsiperiod,0,i);

for( i=limit; i>=0; i--) ShortRSI=iMAOnArray(RSI,0,Shortperiod,0,mamode,i);

for( i=limit; i>=0; i--) MiddleRSI=iMAOnArray(RSI,0,Middleperiod,0,mamode,i);

for( i=limit; i>=0; i--) LongRSI=iMAOnArray(RSI,0,Longperiod,0,mamode,i);

for( i=limit; i>=0; i--) { if(period!=0) SMRSI=(Shortperiod/period)*ShortRSI+(Middleperiod/period)*MiddleRSI+(Longperiod/period)*LongRSI;}

return(0);

}

//+------------------------------------------------------------------+
Archivos adjuntos:
smrsi.gif  33 kb
_test0.mq4  3 kb
 

n_n

mladen:
Tienes que hacer 2 cosas
:- declarar la variable "periodo" como doble (MQL a veces se comporta de forma extraña cuando en la división se utiliza una variable de tipo entero)

- inicializar esa variable "periodo" (ahora mismo está sin inicializar y por eso el último paso no ha funcionado)

Después de eso obtendrá algo como esto :

Que tengas un buen fin de semana

¡Gracias !

 

Hola,

He descargado el indicador adjunto en el sitio web mql4. Intento hacer un EA basado en este indicador pero cuando empiezo el backtest después de algunos segundos las plataformas se caen y creo que es un fallo del indicador porque está usando mucha cpu.

Así que estoy preguntando si es posible aligerar el código para resolver este problema.

Gracias por su disponibilidad.

cronex_taichi.mq4

Archivos adjuntos:
 

dasio

Lo he probado con este snippet y funciona bien. No sé los parámetros que has utilizado por lo que esto es sólo llamar a un indicador por defecto, pero no hay ningún problema de esta manera

int init()

{

return(0);

}

int start()

{

Comment(iCustom(NULL,0,"Cronex Taichi",0,0));

return(0);

}

dasio:
Hola,

He descargado el indicador adjunto en la web de mql4. Intento hacer un EA basado en este indicador pero cuando empiezo el backtest después de algunos segundos las plataformas se caen y creo que es un fallo del indicador porque está usando mucha cpu.

Así que estoy preguntando si es posible aligerar el código para resolver este problema.

Gracias por su disponibilidad.

cronex_taichi.mq4
 
mladen:
dasio

Lo he probado con este snippet y funciona bien. No sé los parámetros que has utilizado por lo que esto es sólo llamar a un indicador por defecto, pero no hay ningún problema de esta manera

int init()

{

return(0);

}

int start()

{

Comment(iCustom(NULL,0,"Cronex Taichi",0,0));

return(0);

}

Gracias, por tu respuesta,

lo que veo es que en el historial el indicador se cargó repetidamente por lo que muevo el código de icustom sólo en un evento de vela nueva pero el problema aún persiste.

No sé por qué.

No obstante gracias por tu disponibilidad.

 

Hola,

He encontrado el problema. Ahora todo está bien.

Tengo otro problema con otro ea.

Tengo estos dos códigos y la función Lotti() me devolvería el número de lote para un pedido.

Cuando lo compilo recibo Posizioni Internal Error. ¿Qué pasa? Gracias;

int OTBM(int intMagic)//OrdersTotalByMagic

{

int intCount=0;

int intPOS=0;

bool boolTerm=false;

while(boolTerm==false)

{

if(OrderSelect(intPOS,SELECT_BY_POS))

{

if(OrderMagicNumber()==intMagic) intCount++;

intPOS++;

}

else

boolTerm=true;

}

return(intCount);

}

[/PHP]

[PHP]int Lotti(){

int Lotti;

int Posizioni=OTBM(MagicNumber);

switch (Posizioni)

{

case 0 : Lotti=0.1; break;

case 1 : Lotti=0.2; break;

case 2 : Lotti=0.4; break;

case 3 : Lotti=0.8; break;

case 4 : Lotti=1.6; break;

case 5 : Lotti=3.2; break;

case 6 : Lotti=6.4; break;

case 7 : Lotti=12.8; break;

}

return(Lotti);

}
 

Pruebe a sustituir OTBM() por este :

int OTBM(int intMagic)//OrdersTotalByMagic

{

int intCount=0;

for (int i=OrdersTotal()-1; i>=0; i--)

{

if(OrderSelect(i,SELECT_BY_POS))

{

if(OrderMagicNumber()==intMagic) intCount++;

}

}

return(intCount);

}

[/PHP]

dasio:
Hi,

i found the problem. Now all its ok.

I have another problem with another ea.

I have this two code and the function Lotti() would be return me the number of lot for an ordersend.

When i compile it i receive Posizioni Internal Error. What's wrong? Thank you;

int OTBM(int intMagic)//OrdersTotalByMagic

{

int intCount=0;

int intPOS=0;

bool boolTerm=false;

while(boolTerm==false)

{

if(OrderSelect(intPOS,SELECT_BY_POS))

{

if(OrderMagicNumber()==intMagic) intCount++;

intPOS++;

}

else

boolTerm=true;

}

return(intCount);

}

[PHP]int Lotti(){

int Lotti;

int Posizioni=OTBM(MagicNumber);

switch (Posizioni)

{

case 0 : Lotti=0.1; break;

case 1 : Lotti=0.2; break;

case 2 : Lotti=0.4; break;

case 3 : Lotti=0.8; break;

case 4 : Lotti=1.6; break;

case 5 : Lotti=3.2; break;

case 6 : Lotti=6.4; break;

case 7 : Lotti=12.8; break;

}

return(Lotti);

}
 

Hola, -.-"

No encuentro paz con estos códigos eheheh.

Tengo un problema con una función que me tiene que dar como resultado la ganancia de todos los openorder pero creo que no funciona porque la condición nunca se ha respetado. Abajo el código:

.....

if(Profit()>=0.....[/PHP]

[PHP]double Profit()

{

int total=OrdersTotal();

double profit=0;

for(int i=0; i<total; i++)

{

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) continue;

profit+=OrderProfit();

}

return(profit);

}
 

dasio

Prueba así :

.....

if(Profit()>=0.....[/PHP]

double Profit()

{

int total=OrdersTotal();

double profit=0;

for(int i=0; i<total-1; i++)

{

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=MagicNumber) continue;

profit+=OrderProfit();

}

return(profit);

}[/PHP]

dasio:
Hi, -.-"

I do not find peace with these codes eheheh.

I have a problem with a function that have to result me the profit of all openorder but i think it's not work because the condition never been respected. Below the code:

[PHP].....

if(Profit()>=0.....

[PHP]double Profit()

{

int total=OrdersTotal();

double profit=0;

for(int i=0; i<total; i++)

{

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) continue;

profit+=OrderProfit();

}

return(profit);

}
 
mladen:
dasio

Pruebe así:

.....

if(Profit()>=0.....[/PHP]

[PHP]double Profit()

{

int total=OrdersTotal();

double profit=0;

for(int i=0; i<total-1; i++)

{

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=MagicNumber) continue;

profit+=OrderProfit();

}

return(profit);

}

De esta forma compruebo las órdenes que no se han abierto con el número mágico especificado, ¿verdad? Necesito comprobar la orden con el símbolo específico y el número mágico. No sé si es importante pero he encontrado el error en el probador de estrategias