Comment coder ? - page 163

 

Question sur l'iCCI

Je suis nouveau dans MQL4 et j'essaie d'obtenir la valeur CCI précédente. J'ai essayé d'utiliser la fonction iCCI avec une valeur Shift de 1, mais cela ne me donne pas la valeur précédente. Comment puis-je le faire sans enregistrer la valeur actuelle dans une variable ? J'essaie de déterminer la direction que prend l'ICC.

Je vous remercie pour votre aide.

 

Le code est basé sur le tic-tac, donc s'il n'y a pas de tic-tac à ce moment-là, le code manquera la vérification du temps. Je ne pense pas que vous puissiez l'obtenir à la seconde près sans une sorte de boucle qui tourne en permanence.

 

Aide pour l'édition de l'EA

J'essaie de résoudre ce problème... pouvez-vous m'aider ?

MB Trading - Stocks Options Futures Forex Online Discount Trading

J'ai modifié ceci :

OrderSend(Symbol(),OP_SELL,mylotsi, SellPrice,slippage,sl,tp, "MyMEFx EA "+MagicNumber,MagicNumber,0,Arrow sColor) ;

retour(0) ;

Vers :

int ticket = OrderSend(Symbol(),OP_SELL,mylotsi, SellPrice,slippage,0,0, "MyMEFx EA "+MagicNumber,MagicNumber,0,Arrow sColor) ;

Sleep(1500) ;

OrderModify(ticket,OrderOpenPrice() ,sl,tp,0,ArrowsColor) ;

=================================== ======

J'obtiens ces erreurs :

2009.02.28 17:32:59 2009.01.01 20:42 EATest AUDJPY,H1 : ticket invalide pour la fonction OrderModify

2009.02.28 17:32:59 2009.01.01 20:42 EATest AUDJPY,H1 : erreur OrderSend 131

28.02.2009 17:32:59 2009.01.01 20:42 EATest AUDJPY,H1 : Erreur OrderModify 4051

=====================

 
coach3131:
J'essaie de comprendre ce problème... pouvez-vous m'aider ?

MB Trading - Stocks Options Futures Forex Online Discount Trading

J'ai changé ceci :

OrderSend(Symbol(),OP_SELL,mylotsi, SellPrice,slippage,sl,tp, "MyMEFx EA "+MagicNumber,MagicNumber,0,Arrow sColor) ;

retour(0) ;

Vers :

int ticket = OrderSend(Symbol(),OP_SELL,mylotsi, SellPrice,slippage,0,0, "MyMEFx EA "+MagicNumber,MagicNumber,0,Arrow sColor) ;

Sleep(1500) ;

OrderModify(ticket,OrderOpenPrice() ,sl,tp,0,ArrowsColor) ;

=================================== ======

J'obtiens ces erreurs :

2009.02.28 17:32:59 2009.01.01 20:42 EATest AUDJPY,H1 : ticket invalide pour la fonction OrderModify

2009.02.28 17:32:59 2009.01.01 20:42 EATest AUDJPY,H1 : erreur OrderSend 131

28.02.2009 17:32:59 01.01.2009 20:42 EATest AUDJPY,H1 : Erreur OrderModify 4051

=====================

Votre problème se situe au niveau de la taille de votre lot (volume) dans votre déclaration d'envoi d'ordre qui renvoie un -1 à cause de l'erreur. Le vérifiable du ticket ne contient pas de numéro de ticket, il contient le drapeau d'erreur de -1 qui a déclenché les autres erreurs avec la fonction ordermodify. Vous devez corriger la variable de taille de lot mylotsi, pour qu'elle contienne une valeur acceptable. Ensuite, vous devez vérifier la valeur de retour dans la variable ticket pour voir si elle ne contient pas un drapeau d'erreur avant d'appeler la routine ordermodify.

keit

 

Position maximale de l'EA

quelqu'un peut-il ajouter des positions maximales pour cet EA

ou le laisser exécuter une seule position ?

Merci d'avance

 

Vous feriez mieux d'utiliser

MathAbs(NormalizeDouble(Bid,4)-NormalizeDouble(pivot,4))<Delta*Point,

Où Delta=2...5

 
jdun:
Quelqu'un pourrait-il me dire le code pour le stop loss et le tp. J'ai besoin de les ajouter à cet EA.

ce SL et TP cachés

int TakeProfit=20; // 20 pips take profit

int StopLoss =40; // 40 pips stoploss

int Slippage = 3;

int MagicNumber=1;

int i;

int start(){

//----- exit @ TP

if((ScanTrades()>=1)&& (ProfitInPips()>=TakeProfit)){

//----- This part will close all open orders and delete pending trades

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

{ OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

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

{

if (OrderType()==OP_BUY)OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Plum);

if (OrderType()==OP_SELL) OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Plum);

if (OrderType() == OP_SELLLIMIT) OrderDelete(OrderTicket());

if (OrderType() == OP_BUYLIMIT) OrderDelete(OrderTicket());

if (OrderType() == OP_BUYSTOP) OrderDelete(OrderTicket());

if (OrderType() == OP_SELLSTOP) OrderDelete(OrderTicket());

}

}

}

//------exit @ SL

if((ScanTrades()>=1)&& (ProfitInPips()<= -StopLoss)){

//----- This part will close all open orders and delete pending trades

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

{ OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

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

{

if (OrderType()==OP_BUY)OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Plum);

if (OrderType()==OP_SELL) OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Plum);

if (OrderType() == OP_SELLLIMIT) OrderDelete(OrderTicket());

if (OrderType() == OP_BUYLIMIT) OrderDelete(OrderTicket());

if (OrderType() == OP_BUYSTOP) OrderDelete(OrderTicket());

if (OrderType() == OP_SELLSTOP) OrderDelete(OrderTicket());

}

}

}

return (0);

}

//----------- Call functions

int ScanTrades()

{

int Tot = OrdersTotal();

int Numb = 0;

for(int cnt=0; cnt<=Tot-1; cnt++)

{

OrderSelect(cnt, SELECT_BY_POS);

if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) Numb++;

}

return(Numb);

}

double ProfitInPips()

{

RefreshRates();

double Prof=0;

int i;

int totalOrders=OrdersTotal();

for(i=0;i<totalOrders;i++)

{

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

if(OrderMagicNumber()==MagicNumber)

{

if(OrderType()==0)

{

Prof+=(MarketInfo(OrderSymbol(),MODE_BID)-OrderOpenPrice())/MarketInfo(OrderSymbol(),MODE_POINT);

}

if(OrderType()==1)

{

Prof+=(OrderOpenPrice()-MarketInfo(OrderSymbol(),MODE_ASK))/MarketInfo(OrderSymbol(),MODE_POINT);

}

}

}

return(Prof);

}

 

Disons que j'ai quelques ordres d'achat et de vente.

Ce que je veux faire est :

- Sortir tous les trades du "panier" à 5 pips de plus que le prix d'équilibre des trades ouverts.

Ce que j'essaie de faire dans la première boucle for est de trouver la valeur des transactions ouvertes + swap et de la convertir en pips, et c'est la partie où je suis bloqué.

J'ai essayé quelques idées mais je suis dans une impasse, je sais que le problème se trouve dans la première instruction for mais je n'arrive pas à le résoudre, toute aide est la bienvenue.

SymbolPL = 0;

OrdLots = 0;

Equity = 0;

MinPro = 5;

for(i = 0; i < OrdersTotal(); i++)

{OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

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

{if(OrderType() == OP_BUY) OrdLots += OrderLots();

if(OrderType() == OP_SELL) OrdLots -= OrderLots();

Equity += OrderProfit() + OrderSwap();

}

}

MinPro= MathRound (MathAbs(Equity /OrdLots)+MinPro);

//--- Count the open trades

int i;

int count=0;

for(i=0;i<OrdersTotal();i++)

{ if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;

if(OrderMagicNumber()==MagicNumber && OrderType()<2)

{ count++;

}

}

//--- find the profit in pips of the open trades

RefreshRates();

double profits=0,openPrice=0,points=0;

string sym="";

int i;

int totalOrders=OrdersTotal();

for(i=0;i<totalOrders;i++)

{

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

if(OrderMagicNumber()==MagicNumber)

{

sym=OrderSymbol();

openPrice=OrderOpenPrice();

if(OrderType()==0)

{

profits+=(MarketInfo(sym,MODE_BID)-openPrice)/MarketInfo(sym,MODE_POINT);

}

if(OrderType()==1)

{

profits+=(OrderOpenPrice()-MarketInfo(sym,MODE_ASK))/MarketInfo(sym,MODE_POINT);

}

}

}

//--- Close when the open trades are 5 pips more than the breakeven price

if (count>1 && profits>MinPro )

{

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

{

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

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

{

OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Plum);

}

}

}

 

Je pense que vous pouvez utiliser une constante "equity_per_lotpoint", qui serait calculée comme suit :

double equity_per_lotpoint = MarketInfo( Symbol(), MODE_TICKVALUE ) / MarketInfo( Symbol(), MODE_TICKSIZE );

[/PHP]

and then you'd have what you need after the first loop, with:

[PHP]if ( Equity > 5 * equity_per_lotpoint * MathAbs( OrdLots ) ) { ...

 

Merci Ralph, mais je manquerais le swap, et je veux inclure le profit/la perte du swap dans la décision de clôture des ordres.