Vous manquez des opportunités de trading :
- Applications de trading gratuites
- Plus de 8 000 signaux à copier
- Actualités économiques pour explorer les marchés financiers
Inscription
Se connecter
Vous acceptez la politique du site Web et les conditions d'utilisation
Si vous n'avez pas de compte, veuillez vous inscrire
Période de temps du graphique
Quel est le code permettant de connaître la période de temps du graphique ? Ainsi, je peux modifier les paramètres des variables pour chaque période de temps.
if( ?????) ...
Dave
Quel est le code permettant de savoir à quelle période de temps le graphique est exécuté ? Ainsi, je peux modifier les paramètres des variables pour chaque période de temps.
if( ?????) ...
Dave[/PHP]
or:
switch(Period())
{
case PERIOD_M1:
...
break;
case PERIOD_M5:
...
break;
...
}
[/PHP]
Sometime it maybe easier to work with indices:[PHP]
int tfIndex = ArrayBsearch({PERIOD_M1, PERIOD_M5, PERIOD_M15, ...}, Period());
Example : how to display the period by the string you want:[PHP]
int Periods[] = {PERIOD_M1, PERIOD_M5, PERIOD_M15, ...};
string sPeriods[] = {" M1", " M5", " M15", " M30", " Hourly", " 4 hours", " Daily", " Weekly"...};
int tfIndex = ArrayBsearch(Periods, Period());
comment(Symbol() + sPeriods[tfIndex]);
Merci Michel !
J'espère que cette EA que je suis en train de créer sera la bonne ! Votre aide est très appréciée !
Dave
Bonjour !
Est-ce que quelqu'un ici peut m'aider à ajouter cette fonction. Pour qu'elle ferme la transaction lorsque la barre est terminée ou en d'autres termes pour qu'elle ferme la transaction lorsque la prochaine barre apparaît (peu importe que la transaction soit un profit ou une perte).
extern int SystemMagicNumber=197 ;
extern double TakeProfit = 100 ;
extern double StopLoss = 500 ;
extern double Lots=0.1 ;
extern double TrailingStop = 0 ;
extern int MaxBuyTrades=5 ;
extern int MaxSellTrades=5 ;
int start()
{
if( HavePosThisBar(SystemMagicNumber)==false
&&iMA(NULL,0,5,0,MODE_SMA, PRICE_CLOSE,1)<iMA(NULL,0,15,0,MODE_EMA, PRICE_CLOSE,1)
&& iMA(NULL,0,5,0,MODE_SMA, PRICE_CLOSE,2)>iMA(NULL,0,15,0,MODE_EMA, PRICE_CLOSE,2)
&& SellPositionsCount()<MaxSellTrades
)
{
OrderSend(Symbol(),OP_SELL,Lots,Bid,0,Bid+StopLoss*Point,Bid-TakeProfit*Point,"",SystemMagicNumber,0,Red) ;
retour(0) ;
}
if( HavePosThisBar(SystemMagicNumber)==false
&& iMA(NULL,0,5,0,MODE_SMA, PRICE_CLOSE,1)>iMA(NULL,0,15,0,MODE_EMA, PRICE_CLOSE,1)
&& iMA(NULL,0,5,0,MODE_SMA, PRICE_CLOSE,2)<iMA(NULL,0,15,0,MODE_EMA, PRICE_CLOSE,2)
&& BuyPositionsCount()<MaxBuyTrades
)
{
OrderSend(Symbol(),OP_BUY,Lots,Ask,0,Ask-StopLoss*Point,Ask+TakeProfit*Point,"",SystemMagicNumber,0,Blue) ;
retour(0) ;
}
for(int cnt=OrdersTotal()-1;cnt>=0;cnt--)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES) ;
si (OrderSymbol() == Symbol())
{
si (OrderType()==OP_SELL)
{
si (TrailingStop>0){
si (OrderOpenPrice()-Ask>TrailingStop*Point)
{
si (OrderStopLoss() == 0 || OrderStopLoss()>(Ask+Point*TrailingStop))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Purple) ;
retour(0) ;
}
}
}
}
si (OrderType()==OP_BUY)
{
si (TrailingStop>0){
si (Bid-OrderOpenPrice()>TrailingStop*Point)
{
si (OrderStopLoss()<(Bid-Point*TrailingStop))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Yellow) ;
retour(0) ;
}
}
}
}
}
}
//----
retour(0) ;
}
//+------------------------------------------------------------------+
bool HavePosThisBar(int magic)
{
int cnt ;
bool Result=false ;
for(cnt=0 ; cnt<=OrdersHistoryTotal()-1 ; cnt++)
if(OrderSelect(cnt, SELECT_BY_POS, MODE_HISTORY))
if((OrderSymbol() == Symbol()) &&(OrderMagicNumber() == magic) && Time[0]<=OrderOpenTime())
{
Resultat=vrai ;
pause ;
}
for(cnt=0 ; cnt<=OrdersTotal()-1 ; cnt++)
if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
if((OrderSymbol() == Symbol()) &&(OrderMagicNumber() == magic) && Time[0]<=OrderOpenTime())
{
Resultat=vrai ;
pause ;
}
return(Resultat) ;
}
int BuyPositionsCount()
{
int Result=0 ;
for(int cnt=0 ; cnt<=OrdersTotal()-1 ; cnt++)
if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
if((OrderSymbol() == Symbol()) &&(OrderMagicNumber() == SystemMagicNumber) &&
(OrderType()==OP_BUY)
)
{
Résultat++ ;
}
return(Resultat) ;
}
int SellPositionsCount()
{
int Result=0 ;
for(int cnt=0 ; cnt<=OrdersTotal()-1 ; cnt++)
if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
if((OrderSymbol() == Symbol()) &&(OrderMagicNumber() == SystemMagicNumber) &&
(OrderType()==OP_SELL)
)
{
Résultat++ ;
}
return(Resultat) ;
}
Bonjour !
Est-ce que quelqu'un ici peut m'aider à ajouter cette fonction. Il faut qu'elle ferme la transaction lorsque la barre est terminée ou, en d'autres termes, qu'elle ferme la transaction lorsque la prochaine barre apparaît (peu importe que la transaction soit un profit ou une perte).
Pour détecter une nouvelle barre, il existe plusieurs solutions :
1)
2)
3)
Better, but again, restarting the terminal may produce wrong behaviors.
So my opinion is that the best is to write the lifetime max of each order into the order itself, using the "Comment" field :[PHP]OrderSend(..., ""+(Time[0] + Period()*60), ..);. C'est une bonne solution car si vous avez plusieurs ordres à fermer, vous avez tout le temps nécessaire pour le faire.
Merci Michel pour la réponse.
J'essaierai. Mais qu'est-ce que je dois mettre dans le commentaire, quelque chose que j'aime ?
merci michel pour la réponse. je vais essayer. mais que dois-je mettre dans le commentaire ? n'importe quoi que j'aime ?
Indiquez l'heure à laquelle vous souhaitez clôturer l'ordre. Le champ Commentaire doit être une chaîne de caractères, c'est pourquoi il y a ""+ devant la valeur. par exemple :
""+(Time[0] + Period()*60) // begin of the next bar on the current timeframe
""+(TimeCurrent() + 2*360 + 30*60) // 2 hours 30 minutes after the openning
""+(iTime(NULL,PERIOD_D1,0) + 23*360 + 45*60) // today at 23:45 (server time)
""+(iTime(NULL,PERIOD_W1,0) + (PERIOD_W1 - 10)*60) // next friday at 23:50Merci
Si nécessaire, vérifiez d'abord que vous êtes plus tard que 8 heures du matin :
Then, find the max and min of the current day. (if its ok for you, its easier than from 8 am): [PHP]double Max = iHigh(Symbol(), PERIOD_D1, 0);
double Min = iLow(Symbol(), PERIOD_D1, 0);
int Range = (Max - Min) / Point;
if(Range > 90) return;
...
Bonjour,
Je m'excuse de prendre autant de temps pour vous dire "merci".
J'apprécie votre aide.
Merci encore.
Shek
Pour détecter une nouvelle barre, il existe plusieurs solutions :
1)
2)
3)
So my opinion is that the best is to write the lifetime max of each order into the order itself, using the "Comment" field :
i got the error below.what does ot mean?
[PHP]'>' - different types in comparison F:\Program Files\MetaTrader - FXOpen\experts\EMA_10.mq4 (88, 22)
I make it like this
for the send order
[PHP]OrderSend(Symbol(),OP_BUY,Lots,Ask,0,Ask-25*Point,Ask+TakeProfit*Point, ""+(Time[0] + Period()*60),SystemMagicNumber,0,Blue);et pour l'ordre de clôture
[PHP]if(TimeCurrent() > OrderComment())
{
OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, CLR_NONE) ;
}et j'ai obtenu l'erreur indiquée ci-dessus.
Est-ce correct ?
Je me suis trompé, désolé.
Ça devrait marcher :