¿Cómo codificar? - página 325

 

Código

cja:
Hola mladen

¿Hay tiempo para echar un vistazo a esto?

Saludos cordiales CJA

Hola mladen,

Sólo una nota rápida para hacerte saber que he conseguido la solución a mi solicitud de código de arrastre para que puedas quitar esto de tu lista de tareas.

Saludos CJA

 

Me alegro de que hayas resuelto el problema

Feliz codificación y comercio

cja:
Hola mladen,

Sólo una nota rápida para hacerle saber que he conseguido la solución a mi solicitud de código de arrastre para que pueda tomar esto de su lista de tareas.

Saludos CJA
 

Hola,

necesito comprobar si la última orden cerrada de mi EA estaba en beneficios o en pérdidas.

He pensado en comprobar las dos últimas órdenes cerradas con beneficios del EA y sumarlas.

El problema es que tengo varios EA en la misma cuenta por lo que es necesario comprobar la orden del historial con un MagicNumber específico. Lo he intentado en varios modos pero sin éxito.

¿Pueden ayudarme?

Gracias

 

dasio

Esta función devuelve el beneficio de las últimas órdenes cerradas (como puedes ver, puedes especificar el número mágico como parámetro también, así que resuelve tu problema con múltiples instancias):

double lastOrderProfit(int magicNumber=0)

{

datetime lastTime = 0;

double lastProfit = 0;

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

{

if (OrderSelect(i,SELECT_BY_POS, MODE_HISTORY)==false) break;

if (magicNumber!=0)

if (OrderMagicNumber() != magicNumber) continue;

if (OrderSymbol() != Symbol()) continue;

if (OrderCloseTime() <= lastTime) continue;

lastTime = OrderCloseTime();

lastProfit = OrderProfit()+OrderSwap()+OrderCommission();

}

return(lastProfit);

}

Sólo tienes que comprobar si el retorno de la función fue positivo o negativo

dasio:
Hola,

necesito comprobar si la última orden cerrada de mi ea estaba en beneficios o en pérdidas.

He pensado en comprobar las dos últimas órdenes cerradas en beneficios del EA y sumarlas.

El problema es que tengo varios EA en la misma cuenta por lo que es necesario comprobar la orden del historial con un número mágico específico. Lo he intentado en varios modos pero sin éxito.

¿Pueden ayudarme?

Gracias.
 
mladen:
dasio

Esta función devuelve el beneficio de las últimas órdenes cerradas (como puede ver, puede especificar el número mágico como parámetro a él también, por lo que resuelve su problema con múltiples instancias):

double lastOrderProfit(int magicNumber=0)

{

datetime lastTime = 0;

double lastProfit = 0;

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

{

if (OrderSelect(i,SELECT_BY_POS, MODE_HISTORY)==false) break;

if (magicNumber!=0)

if (OrderMagicNumber() != magicNumber) continue;

if (OrderSymbol() != Symbol()) continue;

if (OrderCloseTime() <= lastTime) continue;

lastTime = OrderCloseTime();

lastProfit = OrderProfit()+OrderSwap()+OrderCommission();

}

return(lastProfit);

}
Solo tienes que comprobar si el retorno de la función fue positivo o negativo

Así que sólo tengo que recordar la función con mi magicnumber y me resulta el beneficio de la última orden cerrada de mi ea? derecho?

 

Si, es correcto

dasio:
Así que sólo tengo que recordar la función con mi magicnumber y me resulta el beneficio de la última orden cerrada de mi ea? derecho?
 
mladen:
Sí, es correcto

Gracias.

Pero si inicio el ea y no hay orden en el historial, ¿cómo puedo recuperar la función sólo si mi ea cerrar una posición?

 

Entonces use esta función primero:

int closedSoFarForMagic(int magicNumber=0)

{

int closedSoFar=0;

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

{

if (OrderSelect(i,SELECT_BY_POS, MODE_HISTORY)==false) break;

if (magicNumber!=0)

if (OrderMagicNumber() != magicNumber) continue;

if (OrderSymbol() != Symbol()) continue;

closedSoFar++;

}

return(closedSoFar);

}

Si closedSoFarForMagic() > 0 entonces usted sabe que ya hay órdenes cerradas para un número mágico específico en la historia y entonces usted puede comprobar el beneficio de la última orden

dasio:
Gracias, pero si inicio el ea y no hay orden en el historial, ¿cómo puedo recuperar la función sólo si mi ea cierra una posición?
 

vma cross fantail

Hola, estoy intentando hacer un indicador que muestre flechas cuando dos vma se cruzan. Soy un principiante en mql y mi indicador obviamente no funciona, estoy atascado. ¿Alguien me puede ayudar?

El indicador original es MA - fantail vma 3

#property copyright "Copyright © 2007, Forex-TSD.com "

#property link "https://www.forex-tsd.com/"

#property indicator_chart_window

#property indicator_buffers 1

#property indicator_color1 Black

#property indicator_width1 2

//#property indicator_color2 Red

//#property indicator_width2 2

//---- input parameters

//For both user settings, 2 is fast, 8 is slow.Weight=2.3 gives late entry.

extern int ADX_Length=2;

extern double Weighting=2.0;

extern int MA_Length=1;//This must be =1 so that the VMA base line does not get averaged.

extern int MA_Mode=1;

//---- buffers

double MA[];

double VMA[];

double VarMA[];

double ADX[];

double ADXR[];

double sPDI[];

double sMDI[];

double STR[];

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

//| Custom indicator initialization function |

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

int init()

{

//---- indicators

IndicatorBuffers(8);

SetIndexStyle(0,DRAW_LINE);

SetIndexBuffer(0,MA);

SetIndexBuffer(1,VMA);

// SetIndexStyle(2,DRAW_LINE);

SetIndexBuffer(2,VarMA);

SetIndexBuffer(3,ADX);

SetIndexBuffer(4,ADXR);

SetIndexBuffer(5,sPDI);

SetIndexBuffer(6,sMDI);

SetIndexBuffer(7,STR);

//---- name for DataWindow and indicator subwindow label

string short_name="MA - Fantail vma 3";

IndicatorShortName(short_name);

SetIndexLabel(0,"MA - Fantail vma 3");

//----

SetIndexDrawBegin(0,2*MA_Length+40);

// SetIndexDrawBegin(1,2*MA_Length+40);//Used for displaying internal signals.

//---- Safety limits for user settings

if (ADX_Length<2)ADX_Length=2;

if (ADX_Length>8)ADX_Length=8;

if (Weighting<1)Weighting=1;

if (Weighting>8)Weighting=8;

return(0);

}

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

//| Custom indicator iteration function |

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

int start()

{

int limit, i, j, counted_bars=IndicatorCounted();

//----

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

if ( counted_bars ==0 ) limit=Bars-1;

if ( counted_bars < 1 )

for(i=1;i<2*(MA_Length+ADX_Length+10);i++)

{

VMA=Close;

VarMA=Close;

MA=Close;

STR = High-Low;

sPDI = 0;

sMDI = 0;

ADX=0;

ADXR=0;

}

if(counted_bars>0) limit=Bars-counted_bars;

limit--;

for(i=limit; i>=0; i--)

{

double Hi = High;

double Hi1 = High;

double Lo = Low;

double Lo1 = Low;

double Close1= Close;

double Bulls = 0.5*(MathAbs(Hi-Hi1)+(Hi-Hi1));

double Bears = 0.5*(MathAbs(Lo1-Lo)+(Lo1-Lo));

if (Bulls > Bears) Bears = 0;

else

if (Bulls < Bears) Bulls = 0;

else

if (Bulls == Bears) {Bulls = 0;Bears = 0;}

sPDI = (Weighting*sPDI + Bulls)/(Weighting+1);//ma weighting

sMDI = (Weighting*sMDI + Bears)/(Weighting+1);//ma weighting

double TR = MathMax(Hi-Lo,Hi-Close1);

STR = (Weighting*STR + TR)/(Weighting+1);//ma weighting

if(STR>0 )

{

double PDI = sPDI/STR;

double MDI = sMDI/STR;

}

if((PDI + MDI) > 0)

double DX = MathAbs(PDI - MDI)/(PDI + MDI);

else DX = 0;

ADX = (Weighting*ADX + DX)/(Weighting+1);//ma weighting

double vADX = ADX;

double ADXmin = 1000000;

for (j=0; j<=ADX_Length-1;j++) ADXmin = MathMin(ADXmin,ADX);

double ADXmax = -1;

for (j=0; j<=ADX_Length-1;j++) ADXmax = MathMax(ADXmax,ADX);

double Diff = ADXmax - ADXmin;

if(Diff > 0) double Const = (vADX- ADXmin)/Diff; else Const = 0;

VarMA=((2-Const)*VarMA+Const*Close)/2;//Same equation but one less array, mod 10 Sept 2007.

}

for(j=limit; j>=0; j--) MA[j] = iMAOnArray(VarMA,0,MA_Length,0,MA_Mode,j);

//----

return(0);

}

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

[/PHP]

and this is mine

[PHP]

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

//| VMA cross arrows.mq4 |

//| thefxpros@katamail.com |

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

#property copyright "thefxpros"

#property link "thefxpros@katamail.com"

#property indicator_chart_window

#property indicator_buffers 4

#property indicator_color1 C'255,198,198'

#property indicator_color2 C'198,255,198'

#property indicator_color3 Crimson

#property indicator_color4 DarkGreen

#property indicator_width1 3

#property indicator_width2 3

#property indicator_width3 2

#property indicator_width4 2

//--------------------------------------------------------

extern int VMA1_ADXLenght = 2;

extern double VMA1_Weighting = 2.0;

extern int VMA1_Length = 1;

extern int VMA1_Mode = 1;

extern int VMA2_ADXLenght = 2;

extern double VMA2_Weighting = 3.0;

extern int VMA2_Length = 3;

extern int VMA2_Mode = 2;

//--------------------------------------------------------

double buffer1[];

double buffer2[];

double buffer3[];

double buffer4[];

//--------------------------------------------------------

int init()

{

SetIndexStyle (0,DRAW_HISTOGRAM);

SetIndexStyle (1,DRAW_HISTOGRAM);

SetIndexBuffer (0,buffer3);

SetIndexBuffer (1,buffer4);

SetIndexBuffer (2,buffer1);

SetIndexBuffer (3,buffer2);

return(0);

}

int deinit()

{

return(0);

}

//--------------------------------------------------------

int start()

{

int counted_bars=IndicatorCounted();

int limit,i;

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

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

//--------------------------------------------------------

for(i=limit; i>=0; i--)

{

buffer1 = iCustom(NULL, 0, "MA - fatail vma 3", VMA1_ADXLenght, VMA1_Weighting, VMA1_Length, VMA1_Mode, i);

buffer2 = iCustom(NULL, 0, "MA - fatail vma 3", VMA1_ADXLenght, VMA2_Weighting, VMA2_Length, VMA2_Mode, i);

buffer3 = buffer1;

buffer4 = buffer2;

}

return(0);

}

 

losfxpros,

Compruebe primero el nombre del indicador :

"MA - fatailvma 3"

Ahí debería estar "fantail"

Además, en la llamada al indicador iCustom() te falta el número del buffer. Sólo supongo que esto es lo que estabas tratando de lograr

buffer1 = iCustom(NULL, 0, "MA - fatail vma 3", VMA1_ADXLenght, VMA1_Weighting, VMA1_Length, VMA1_Mode,0, i);

buffer2 = iCustom(NULL, 0, "MA - fatail vma 3", VMA1_ADXLenght, VMA2_Weighting, VMA2_Length, VMA2_Mode,1, i);[/PHP]

thefxpros:
Hi, i'm trying to make an indicator that shows arrows when two vma crosses. I'm a mql beginner and my indicator obviously does not work, I'm stuck. Somebody can help me?

The original indicator is MA - fantail vma 3

#property copyright "Copyright © 2007, Forex-TSD.com "

#property link "https://www.forex-tsd.com/"

#property indicator_chart_window

#property indicator_buffers 1

#property indicator_color1 Black

#property indicator_width1 2

//#property indicator_color2 Red

//#property indicator_width2 2

//---- input parameters

//For both user settings, 2 is fast, 8 is slow.Weight=2.3 gives late entry.

extern int ADX_Length=2;

extern double Weighting=2.0;

extern int MA_Length=1;//This must be =1 so that the VMA base line does not get averaged.

extern int MA_Mode=1;

//---- buffers

double MA[];

double VMA[];

double VarMA[];

double ADX[];

double ADXR[];

double sPDI[];

double sMDI[];

double STR[];

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

//| Custom indicator initialization function |

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

int init()

{

//---- indicators

IndicatorBuffers(8);

SetIndexStyle(0,DRAW_LINE);

SetIndexBuffer(0,MA);

SetIndexBuffer(1,VMA);

// SetIndexStyle(2,DRAW_LINE);

SetIndexBuffer(2,VarMA);

SetIndexBuffer(3,ADX);

SetIndexBuffer(4,ADXR);

SetIndexBuffer(5,sPDI);

SetIndexBuffer(6,sMDI);

SetIndexBuffer(7,STR);

//---- name for DataWindow and indicator subwindow label

string short_name="MA - Fantail vma 3";

IndicatorShortName(short_name);

SetIndexLabel(0,"MA - Fantail vma 3");

//----

SetIndexDrawBegin(0,2*MA_Length+40);

// SetIndexDrawBegin(1,2*MA_Length+40);//Used for displaying internal signals.

//---- Safety limits for user settings

if (ADX_Length<2)ADX_Length=2;

if (ADX_Length>8)ADX_Length=8;

if (Weighting<1)Weighting=1;

if (Weighting>8)Weighting=8;

return(0);

}

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

//| Custom indicator iteration function |

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

int start()

{

int limit, i, j, counted_bars=IndicatorCounted();

//----

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

if ( counted_bars ==0 ) limit=Bars-1;

if ( counted_bars < 1 )

for(i=1;i<2*(MA_Length+ADX_Length+10);i++)

{

VMA=Close;

VarMA=Close;

MA=Close;

STR = High-Low;

sPDI = 0;

sMDI = 0;

ADX=0;

ADXR=0;

}

if(counted_bars>0) limit=Bars-counted_bars;

limit--;

for(i=limit; i>=0; i--)

{

double Hi = High;

double Hi1 = High;

double Lo = Low;

double Lo1 = Low;

double Close1= Close;

double Bulls = 0.5*(MathAbs(Hi-Hi1)+(Hi-Hi1));

double Bears = 0.5*(MathAbs(Lo1-Lo)+(Lo1-Lo));

if (Bulls > Bears) Bears = 0;

else

if (Bulls < Bears) Bulls = 0;

else

if (Bulls == Bears) {Bulls = 0;Bears = 0;}

sPDI = (Weighting*sPDI + Bulls)/(Weighting+1);//ma weighting

sMDI = (Weighting*sMDI + Bears)/(Weighting+1);//ma weighting

double TR = MathMax(Hi-Lo,Hi-Close1);

STR = (Weighting*STR + TR)/(Weighting+1);//ma weighting

if(STR>0 )

{

double PDI = sPDI/STR;

double MDI = sMDI/STR;

}

if((PDI + MDI) > 0)

double DX = MathAbs(PDI - MDI)/(PDI + MDI);

else DX = 0;

ADX = (Weighting*ADX + DX)/(Weighting+1);//ma weighting

double vADX = ADX;

double ADXmin = 1000000;

for (j=0; j<=ADX_Length-1;j++) ADXmin = MathMin(ADXmin,ADX);

double ADXmax = -1;

for (j=0; j<=ADX_Length-1;j++) ADXmax = MathMax(ADXmax,ADX);

double Diff = ADXmax - ADXmin;

if(Diff > 0) double Const = (vADX- ADXmin)/Diff; else Const = 0;

VarMA=((2-Const)*VarMA+Const*Close)/2;//Same equation but one less array, mod 10 Sept 2007.

}

for(j=limit; j>=0; j--) MA[j] = iMAOnArray(VarMA,0,MA_Length,0,MA_Mode,j);

//----

return(0);

}

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

and this is mine

[PHP]

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

//| VMA cross arrows.mq4 |

//| thefxpros@katamail.com |

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

#property copyright "thefxpros"

#property link "thefxpros@katamail.com"

#property indicator_chart_window

#property indicator_buffers 4

#property indicator_color1 C'255,198,198'

#property indicator_color2 C'198,255,198'

#property indicator_color3 Crimson

#property indicator_color4 DarkGreen

#property indicator_width1 3

#property indicator_width2 3

#property indicator_width3 2

#property indicator_width4 2

//--------------------------------------------------------

extern int VMA1_ADXLenght = 2;

extern double VMA1_Weighting = 2.0;

extern int VMA1_Length = 1;

extern int VMA1_Mode = 1;

extern int VMA2_ADXLenght = 2;

extern double VMA2_Weighting = 3.0;

extern int VMA2_Length = 3;

extern int VMA2_Mode = 2;

//--------------------------------------------------------

double buffer1[];

double buffer2[];

double buffer3[];

double buffer4[];

//--------------------------------------------------------

int init()

{

SetIndexStyle (0,DRAW_HISTOGRAM);

SetIndexStyle (1,DRAW_HISTOGRAM);

SetIndexBuffer (0,buffer3);

SetIndexBuffer (1,buffer4);

SetIndexBuffer (2,buffer1);

SetIndexBuffer (3,buffer2);

return(0);

}

int deinit()

{

return(0);

}

//--------------------------------------------------------

int start()

{

int counted_bars=IndicatorCounted();

int limit,i;

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

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

//--------------------------------------------------------

for(i=limit; i>=0; i--)

{

buffer1 = iCustom(NULL, 0, "MA - fatail vma 3", VMA1_ADXLenght, VMA1_Weighting, VMA1_Length, VMA1_Mode, i);

buffer2 = iCustom(NULL, 0, "MA - fatail vma 3", VMA1_ADXLenght, VMA2_Weighting, VMA2_Length, VMA2_Mode, i);

buffer3 = buffer1;

buffer4 = buffer2;

}

return(0);

}

Razón de la queja: