Comment coder ? - page 325

 

Code

cja:
Bonjour mladen,

Vous avez le temps d'y jeter un coup d'œil ?

Amicalement, CJA

Bonjour mladen,

Juste une note rapide pour vous faire savoir que j'ai obtenu la solution à ma demande de code de suivi, de sorte que vous pouvez retirer cette question de votre liste de tâches.

Salutations CJA

 

Heureux que vous ayez résolu le problème

Bonne continuation dans le codage et le trading

cja:
Salut mladen,

Juste une note rapide pour vous faire savoir que j'ai obtenu la solution à ma demande de code de suivi afin que vous puissiez le retirer de votre liste de tâches.

Salutations CJA
 

Bonjour,

J'ai besoin de vérifier si le dernier ordre fermé de mon EA était en profit ou en perte.

J'ai pensé à vérifier les deux derniers ordres de profit fermés de l'EA et à les additionner.

Le problème est que j'ai plusieurs EA sur le même compte et qu'il est nécessaire de vérifier l'historique des ordres avec un MagicNumber spécifique. J'ai essayé dans plusieurs modes mais sans succès.

Pouvez-vous m'aider ?

Je vous remercie

 

dasio

Cette fonction renvoie le bénéfice des derniers ordres fermés (comme vous pouvez le voir, vous pouvez également spécifier le nombre magique comme paramètre, ce qui résout le problème des instances multiples) :

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);

}

Vous devez seulement vérifier si le retour de la fonction était positif ou négatif.

dasio:
Bonjour,

j'ai besoin de vérifier si le dernier ordre fermé de mon ea était en profit ou en perte.

J'ai pensé à vérifier les deux derniers ordres de profit fermés de l'EA et à les additionner.

Le problème est que j'ai plusieurs EA sur le même compte et qu'il est donc nécessaire de vérifier l'historique des ordres avec un MagicNumber spécifique. J'ai essayé dans plusieurs modes mais sans succès.

Pouvez-vous m'aider ?

Merci.
 
mladen:
dasio

Cette fonction renvoie le profit des derniers ordres fermés (comme vous pouvez le voir, vous pouvez également spécifier le numéro magique comme paramètre, ce qui résout le problème des instances multiples) :

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);

}
Il suffit de vérifier si le retour de la fonction est positif ou négatif.

Donc il me suffit de rappeler la fonction avec mon numéro magique et elle me donne le profit du dernier ordre fermé de mon ea, n'est-ce pas ?

 

Oui, c'est vrai.

dasio:
Donc il me suffit de rappeler la fonction avec mon numéro magique et il me résulte le profit du dernier ordre fermé de mon ea ? n'est-ce pas ?
 
mladen:
Oui, c'est bien cela

Merci.

Mais si je démarre l'ea et qu'il n'y a pas d'ordre dans l'historique, comment puis-je rappeler la fonction seulement si mon ea ferme une position ?

 

Alors utilisez d'abord cette fonction :

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 alors vous savez qu'il y a déjà des ordres fermés pour un nombre magique spécifique dans l'historique et ensuite vous pouvez vérifier le profit du dernier ordre.

dasio:
Merci, mais si je lance l'application et qu'il n'y a pas d'ordre dans l'historique, comment puis-je rappeler la fonction seulement si mon application ferme une position ?
 

Indicateur de croisement de vma

Bonjour, j'essaie de créer un indicateur qui affiche des flèches lorsque deux vma se croisent. Je suis un débutant en mql et mon indicateur ne fonctionne évidemment pas, je suis coincé. Quelqu'un peut m'aider ?

L'indicateur original est 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);

}

 

thefxpros,

Vérifiez d'abord le nom de l'indicateur :

"MA - fatailvma 3"

Il devrait être "fantail" ici

De plus, dans l'appel à l'indicateur iCustom(), il manque le numéro de tampon. Je suppose que c'est ce que vous essayez d'obtenir.

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);

}

Raison: