j'aissais en vain de faire foctionner cet EA mais à haque fois que j'aissais de le lancer rien ne se passe
l'EA
L'indicateur
l'EA
Code
//+------------------------------------------------------------------+
//| TribuForex V 1.1.mq4 |
//| |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, TribuForex"
// Déclaration des variables générales
extern string _____Paramètres_Principaux_____ = "_____TribuForex V1.1_____";
extern int TakeProfit = 0; // Niveau de Take Profit
extern double Lots = 0.1; // Taille des lots
extern int Stop = 15; // Niveau de Stop au dessus/dessous du SuperTrend
extern int StopSecours = 30; // Stop pour les ordres en attente
extern bool OrderStopOnly = False; // TRUE: Ne crée que des ordres Stop..
extern string __Heures_début_et_fin_trading__ = " ";
extern int HeureDeb = 00;
extern int MinutDeb = 00;
extern int HeureFin = 23;
extern int MinutFin = 59;
extern string ___Cloture_en_fin_de_trading___ = " ";
extern bool CloseEndDay = False; // si VRAI : Clôture des ordres en cours à l'heure de fin de trading
extern string ___Retournement_de_tendance____ = " ";
extern bool CloseReverse = False;
extern string ___Gestion_multi_timeframes____ = " ";
extern bool TimeFrame = False; // si VRAI : Ouvrir des ordres différents par Time Frame
extern string ________Password_usage_EA______ = "A préciser une seule fois par plateforme ";
extern int Password;
// Paramètres de trading
// Déclarations des variables internes à la routine start
static color EnterLongColor = Yellow;
static color EnterShortColor = Lime;
static color ExitLongColor = DarkOrange;
static color ExitShortColor = SpringGreen;
static string ExpertName = "TribuForex V1.1";
int Magic = 99900000; // Permet d'identifier les ordres gérés par cet EA.
int MagicNumber; // MagicNumber calculé par Timeframe
int Slippage; // Slippage autorisé
int Digit; // Nombre de décimales du cross traité
int StopLevel; // Niveau de stop autorisé pour le cross
double MinLot; // Lot minimal autorisé pour le cross
bool CadrageDigit; // Cadrage des montants en fonction du nombre de décimales si TRUE
// Variables résultant des Indicateurs utilisés
double TrendUp_C, TrendDown_C, Trend_C; // Positions courantes
double TrendUp_P, TrendDown_P, Trend_P; // Positions précédentes
int Multiplicateur = 3; // Multiplicateur utilisé par l'indicateur Super Trend (Valeur 2 ou 3)
string Inversion; // Booléens indiquant l'inversion du signal
// Variable de travail
int cnt, ticket, total;
string OpenTrade;
datetime timeprev = 0;
bool blocage = false;
int Iteration = 0;
//========================================================================================================================================================
// Routine d'initialisation de l'EA
int init()
{
//------------------------------------------------------------------------------------------------------------------------------------------------------
// Variables de suivi
Print("LotSize : ", MarketInfo(Symbol(),MODE_LOTSIZE));
MinLot = MarketInfo(Symbol(),MODE_MINLOT);
Print("MinLot : ", MarketInfo(Symbol(),MODE_MINLOT));
Print("LotStep : ", MarketInfo(Symbol(),MODE_LOTSTEP));
Print("MaxLot : ", MarketInfo(Symbol(),MODE_MAXLOT));
Print("Digit : ", MarketInfo(Symbol(),MODE_DIGITS));
// Contrôle d'habilitation
if (!IsDemo())
{
int Habilit = (AccountNumber()+597)*7 - 1343;
int Pass = GlobalVariableGet("TribuForex SuperTrend");
if (Password == 0 && Pass == 0) {Comment("Indiquez votre mot de passe dans les paramètres de l EA pour continuer. Merci"); return(0);}
if (Habilit != Password && Habilit != Pass) {Alert("Mot de passe incorrect, EA suspendu! - contacter TribuForex"); return(0);}
GlobalVariableSet("TribuForex SuperTrend", Habilit);
Comment("Autorisation EA : OK");
}
if (IsDemo())
{
int HabilitDemo = (AccountNumber()+193)*3 - 223;
int PassDemo = GlobalVariableGet("TribuForex SuperTrend Demo");
if (Password == 0 && PassDemo == 0) {Comment("Indiquez votre mot de passe dans les paramètres de l EA pour continuer. Merci"); return(0);}
if (HabilitDemo != Password && HabilitDemo != PassDemo) {Alert("Mot de passe Demo incorrect, EA suspendu! - contacter TribuForex"); return(0);}
GlobalVariableSet("TribuForex SuperTrend Demo", HabilitDemo);
Comment("Autorisation EA en Demo: OK");
}
//------------------------------------------------------------------------------------------------------------------------------------------------------
// Contrôles initiaux
// Contrôle de la valeur du stop
if (Stop < 5) {Comment("Le paramètre Stop ne peut être inférieur à 5. Merci de le changer !"); return(0);}
// Contrôle de la valeur du TimeFrame
// if (Period() == PERIOD_M1) {Comment("Utiliser un TimeFrame plus élevé, car M1 est incompatible avec cet EA. Merci"); return(0);}
// Contrôle syntaxique des heures début/fin
if ((HeureFin < HeureDeb) || (HeureFin == HeureDeb && MinutFin < MinutDeb)) {Comment("Heure/Minute de fin incorrects. Merci de les modifier".);}
// ------------------------------------------------------------------------------------------------------------------------------------------------------
// Valeurs par défaut des paramètres de trading
Slippage = MarketInfo(Symbol(), MODE_SPREAD)*2;
StopLevel = MarketInfo(Symbol(), MODE_STOPLEVEL) + MarketInfo(Symbol(), MODE_SPREAD);
// ------------------------------------------------------------------------------------------------------------------------------------------------------
// Prise en compte du Digit
Digit = MarketInfo(Symbol(), MODE_DIGITS);
if (Digit == 5 || Digit == 3) // Paires classiques et paires avec YEN
{if (TakeProfit < 100 && TakeProfit > 0) TakeProfit *= 10;
if (Stop < 100 && Stop > 0) Stop *= 10;
if (StopSecours < 100 && StopSecours > 0) StopSecours *= 10;
}
if (Digit < 5) CadrageDigit=True;
// Forçage valeur de stop
if (StopSecours < StopLevel && StopSecours > 0) StopSecours = StopLevel;
if (TakeProfit < StopLevel && TakeProfit > 0) TakeProfit = StopLevel;
// ------------------------------------------------------------------------------------------------------------------------------------------------------
// Forçage valeur du lot
if (Lots < MinLot) {Lots = MinLot; Comment ("Le lot est ramené à la valeur minimale autorisée : ", MinLot);}
// ------------------------------------------------------------------------------------------------------------------------------------------------------
// Variable itérative
Iteration = 0; // Permet de déterminer le début de scéance
// Calcul du MagicNumber selon le Time Frame si option choisie
MagicNumber = Magic + Period();
Print ("MagicNumber : ", DoubleToStr(MagicNumber,0));
}
// ------------------------------------------------------------------------------------------------------------------------------------------------------
//+------------------------------------------------------------------+
//| Routine Principale |
//+------------------------------------------------------------------+
int start()
{
// Check initial des données ---------------------------------------------------------------------------------------------------------------------
// Test du nombre de bougies
if(Bars<100)
{
Print("Moins de 100 bougies !");
return(0);
}
if (Stop < 0) {Comment ("Changez la valeur du paramètre Stop: il ne peut être négatif"); return(0);}
if ((HeureFin < HeureDeb) || (HeureFin == HeureDeb && MinutFin < MinutDeb)) {Comment("Heure/Minute de fin incorrects".);}
if (!IsExpertEnabled()) {Comment ("Expert ",ExpertName, " non autorisé actuellement !"); blocage=True; return(-1);}
if (!IsTradeAllowed()) {Comment ("Trading non autorisé !"); blocage=True; return(-1);}
if (IsTradeContextBusy()) {Comment ("Contexte saturé, pas de trading !"); blocage=True; return(-1);}
if (!IsConnected()) {Comment ("Pas de connexion !"); blocage=True; return(-1);}
if (IsStopped()) {Comment ("EA arrêté..."); blocage=True; return(-1);}
if (blocage) {Comment ("Trading autorisé depuis "+TimeToStr(TimeCurrent(),TIME_MINUTES)); blocage=False;}
//------------------------------------------------------------------------------------------------------------------------------------------------
// Fermeture des ordres à l'heure limite
VerifFinTrading();
// Temporisation selon la fréquence du timeframe
if(timeprev==Time[0]){return(0);}
timeprev = Time[0];
Print ("MagicNumber : ", DoubleToStr(MagicNumber,0));
//------------------------------------------------------------------------------------------------------------------------------------------------
// Calcul des indicateurs
TrendUp_C = 0;
TrendUp_P = 0;
TrendDown_C = 0;
TrendDown_P = 0;
// Valeur du Trend - Bougie - 1
Trend_C = iCustom(Symbol(),0,"SuperTrendTF",10,3,2,1);
// Valeur du SuperTrend à la hausse - Bougie - 1
if (Trend_C > 0) {TrendUp_C = iCustom(Symbol(),0,"SuperTrendTF",10,Multiplicateur,0,1);}
// Valeur du SuperTrend à la baisse - Bougie - 1
if (Trend_C < 0) {TrendDown_C = iCustom(Symbol(),0,"SuperTrendTF",10,Multiplicateur,1,1);}
// Valeur du Trend - Bougie - 2
Trend_P = iCustom(Symbol(),0,"SuperTrendTF",10,Multiplicateur,2,2);
// Valeur du SuperTrend à la hausse - Bougie - 1
if (Trend_P > 0) {TrendUp_P = iCustom(Symbol(),0,"SuperTrendTF",10,Multiplicateur,0,2);}
// Valeur du SuperTrend à la baisse - Bougie - 1
if (Trend_P < 0) {TrendDown_P = iCustom(Symbol(),0,"SuperTrendTF",10,Multiplicateur,1,2);}
Inversion = iif((Trend_P != Trend_C), "Oui", "Non");
Print ("TrendUp_C : ", TrendUp_C,", TrendUp_P : ", TrendUp_P, ", TrendDown_C : ", TrendDown_C, ", TrendDown_P : ", TrendDown_P, ", Trend_C : ", Trend_C, ", Trend_P : ", Trend_P,", Inversion : ", Inversion);
//------------------------------------------------------------------------------------------------------------------------------------------------
Comment ("\n"+ "Heure de référence : " + TimeToStr(timeprev,TIME_MINUTES) + "\n" +
"Ouvert : " + Ouvert() + "\n" + "\n" +
"Positions précédentes" + "\n" +
"TrendUp : " + DoubleToStr(TrendUp_P,Digit) + "\n" +
"TrendDown : " + DoubleToStr(TrendDown_P,Digit) + "\n" + "\n" +
"Positions courantes" + "\n" +
"TrendUp : " + DoubleToStr(TrendUp_C,Digit) + "\n" +
"TrendDown : " + DoubleToStr(TrendDown_C,Digit) + "\n" + "\n" +
"Inversion SuperTrend : " + Inversion + "\n" + "\n" + "\n" +
"Paramètres généraux" + "\n" +
"Lot : " + DoubleToStr(Lots,2) + "\n" +
"Stop : " + Stop + " pips" + "\n" +
"Digits " + Symbol() + " : " + Digit + " décimales"+ "\n");
//------------------------------------------------------------------------------------------------------------------------------------------------
// Procédure principale
MiseAjour();
if (TotalOrdre("ALL") == 0) Iteration=0;
if (Ouvert()== "Oui")
{
Iteration++;
VerifInversion();
// 1ère itération : ouverture de trade selon la tendance
if (Iteration == 1)
{
if ((TotalOrdre("ALL") == 2 && !OrderStopOnly) || (TotalOrdre("STOP") == 1 && OrderStopOnly))
{
Comment (Symbol(), " en", NomPeriode(),": Attention, des ordres résiduels gérés par TribuForex V1.1 sont présents : pas de création d ordre supplémentaire !");
return(0);
}
if (TotalOrdre("ALL") == 0)
{
Print ("Pas d ordre en cours");
if (Trend_C == 1) {OpenBuy() ; MiseAjour(); OpenSellStop(); return(0);}
if (Trend_C == -1) {OpenSell() ; MiseAjour(); OpenBuyStop() ; return(0);}
}
}
// enième itération : création d'un ordre en attente si nécessaire
if (Trend_C == 1 && TotalOrdre("BUY") == 1 && TotalOrdre("SELLSTOP") == 0) {OpenSellStop(); MiseAjour(); return(0);}
if (Trend_C == -1 && TotalOrdre("SELL") == 1 && TotalOrdre("BUYSTOP") == 0) {OpenBuyStop(); MiseAjour(); return(0);}
}
return(0);
}
// Fin de la procédure
//========================================================================================================================================================
void OpenBuy()
{
int TicketAchat, Erreur, Essai=0;
int NbOrdre;
double ValStopLoss=0;
double ValTakeProfit=0;
double PrixEntree;
double Commentaire;
if (OrderStopOnly) {return(0);}
NbOrdre = TotalOrdre("SELL");
if (NbOrdre > 0) {Alert (Symbol(), " : Déjà un ordre SELL en", NomPeriode(), "en cours... pas de hedge !");return(0);}
NbOrdre = TotalOrdre("BUY");
if (NbOrdre > 0) {Alert (Symbol(), " : Déjà un ordre BUY en", NomPeriode(), "en cours... Pas d ordre supplémentaire !");return(0);}
while (Essai < 10)
{
RefreshRates();
PrixEntree = NormalizeDouble(Ask, Digit);
TicketAchat=OrderSend(Symbol(),OP_BUY,Lots,PrixEntree,Slippage,0,0,ExpertName + NomPeriode(),MagicNumber,0,EnterLongColor);
PlaySound("Expert.wav");
Print(Symbol()," : Fonction OpenBuy executée , ticket ="+TicketAchat);
if(TicketAchat<=0)
{
Alert(Symbol(), " : Erreur survenue ==> ", GetLastError(), " ", ErrorDescription(GetLastError()), " Buy @ ", Ask);
Slippage++;
Essai++;
Sleep(2000);
}
else {Essai = 10;}
}
return(0);
}
//========================================================================================================================================================
void OpenSell()
{
int TicketVente, Erreur, Essai=0;
int NbOrdre;
double PrixEntree;
if (OrderStopOnly) {return(0);}
NbOrdre = TotalOrdre("BUY");
if (NbOrdre > 0) {Alert (Symbol(), " : Déjà un ordre BUY en", NomPeriode(),"en cours... Pas de hedge !");return(0);}
NbOrdre = TotalOrdre("SELL");
if (NbOrdre > 0) {Alert (Symbol(), " : Déjà un ordre SELL en", NomPeriode(),"en cours... Pas d ordre supplémentaire !");return(0);}
while (Essai < 10)
{
RefreshRates();
PrixEntree = NormalizeDouble(Bid, Digit);
TicketVente=OrderSend(Symbol(),OP_SELL,Lots,PrixEntree,Slippage,0,0,ExpertName + NomPeriode(),MagicNumber,0,EnterShortColor);
PlaySound("Expert.wav");
Print(Symbol()," : Fonction OpenSell executée , ticket ="+TicketVente);
if(TicketVente<=0)
{
Alert(Symbol(), " : Erreur survenue ==> (", GetLastError(), ") ", ErrorDescription(GetLastError()), " Sell @ ", Bid);
Slippage++;
Essai++;
Sleep(2000);
}
else {Essai = 10;}
}
return(0);
}
//========================================================================================================================================================
void OpenBuyStop()
{
int TicketAchatStop, Erreur, Essai=0;
double PrixEntree = NormalizeDouble(TrendDown_C + Stop*Point, Digit);
double ValStopLoss;
if (StopSecours > 0) {ValStopLoss = NormalizeDouble(PrixEntree - StopSecours*Point, Digit);}
while (Essai < 10)
{
TicketAchatStop=OrderSend(Symbol(),OP_BUYSTOP,Lots,PrixEntree,Slippage,ValStopLoss,0,ExpertName + NomPeriode(),MagicNumber,0,CLR_NONE);
Print(Symbol()," : Fonction OpenBuyStop executée , ticket ="+TicketAchatStop);
if(TicketAchatStop<=0)
{
Alert(Symbol()," : Erreur survenue ==> (", GetLastError(), ") ", ErrorDescription(GetLastError()), " BuyStop @ ", PrixEntree, " Stop ", ValStopLoss);
Slippage++;
Essai++;
Sleep(2000);
}
else {Essai = 10;}
}
return(0);
}
//========================================================================================================================================================
void OpenSellStop()
{
int TicketVenteStop, Erreur, Essai=0;
double PrixEntree = NormalizeDouble(TrendUp_C - Stop*Point, Digit);
double ValStopLoss;
if (StopSecours > 0) {ValStopLoss = NormalizeDouble(PrixEntree + StopSecours*Point, Digit);}
while (Essai < 10)
{
TicketVenteStop=OrderSend(Symbol(),OP_SELLSTOP,Lots,PrixEntree,Slippage,ValStopLoss,0,ExpertName + NomPeriode(),MagicNumber,0,CLR_NONE);
Print(Symbol()," : Fonction OpenSellStop executée , ticket ="+TicketVenteStop);
if(TicketVenteStop<=0)
{
Alert(Symbol(), " : Erreur survenue ==> (", GetLastError(), ") ", ErrorDescription(GetLastError()), " SellStop @ ", PrixEntree, " Stop ", ValStopLoss);
Slippage++;
Essai++;
Sleep(2000);
}
else {Essai = 10;}
}
return(0);
}
//========================================================================================================================================================
string Ouvert()
{
OpenTrade = "Non";
if ((Hour()==HeureDeb && Minute()>=MinutDeb) || Hour()>HeureDeb)
{
if ((Hour()==HeureFin && Minute()<=MinutFin) || Hour()<HeureFin)
{
OpenTrade = "Oui";
}
}
return(OpenTrade);
}
//========================================================================================================================================================
void MiseAjour()
{
double PrixOrdre, PrixStop, PrixProfit;
if (Stop != 0)
{
for(cnt = 0; cnt < OrdersTotal(); cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber)
{
switch (OrderType())
{
case OP_BUY:
if (TrendUp_C == 0) {return(0);}
if (CadrageDigit)
{
PrixOrdre = NormalizeDouble(OrderOpenPrice(), Digit);
if (Stop > 0) {PrixStop = NormalizeDouble(TrendUp_C - Stop*Point, Digit);}
if (TakeProfit > 0) {PrixProfit = NormalizeDouble(OrderOpenPrice() + TakeProfit*Point, Digit);}
}
else
{
PrixOrdre = OrderOpenPrice();
if (Stop > 0) {PrixStop = TrendUp_C - Stop*Point;}
if (TakeProfit > 0) {PrixProfit = OrderOpenPrice() + TakeProfit*Point;}
}
//if (PrixStop == OrderStopLoss()) {return(0);}
Print ("Modification SL/TP ordre BUY ", OrderTicket(), ", Prix stop : ", PrixStop, ", Prix profit :", PrixProfit);
OrderModify(OrderTicket(),PrixOrdre, PrixStop, PrixProfit, 0, CLR_NONE);
continue;
case OP_SELL:
if (TrendDown_C == 0) {return(0);}
if (CadrageDigit)
{
PrixOrdre = NormalizeDouble(OrderOpenPrice(), Digit);
if (Stop > 0) {PrixStop = NormalizeDouble(TrendDown_C + Stop*Point, Digit);}
if (TakeProfit > 0) {PrixProfit = NormalizeDouble(OrderOpenPrice() - TakeProfit*Point, Digit);}
}
else
{
PrixOrdre = OrderOpenPrice();
if (Stop > 0) {PrixStop = TrendDown_C + Stop*Point;}
if (TakeProfit > 0) {PrixProfit = OrderOpenPrice() - TakeProfit*Point;}
}
//if (PrixStop == OrderStopLoss()) {return(0);}
Print ("Modification SL/TP ordre SELL ", OrderTicket(), ", Prix stop : ", PrixStop, ", Prix profit :", PrixProfit);
OrderModify(OrderTicket(),PrixOrdre, PrixStop, PrixProfit, 0, CLR_NONE);
continue;
case OP_BUYSTOP:
if (TrendDown_C == 0) {return(0);}
if (CadrageDigit)
{
PrixOrdre = NormalizeDouble(TrendDown_C + Stop*Point, Digit);
if (StopSecours > 0) {PrixStop = NormalizeDouble(PrixOrdre - StopSecours*Point, Digit);}
}
else
{
PrixOrdre = TrendDown_C + Stop*Point;
if (StopSecours > 0) {PrixStop = PrixOrdre - StopSecours*Point;}
}
Print ("Modification prix entrée ordre BUYSTOP ", OrderTicket(), ", ", PrixOrdre, " stop ", PrixStop);
OrderModify(OrderTicket(),PrixOrdre, PrixStop, 0, 0, CLR_NONE);
continue;
case OP_SELLSTOP:
if (TrendUp_C == 0) {return(0);}
if (CadrageDigit)
{
PrixOrdre = NormalizeDouble(TrendUp_C - Stop*Point, Digit);
if (StopSecours > 0) {PrixStop = NormalizeDouble(PrixOrdre + StopSecours*Point, Digit);}
}
else
{
PrixOrdre = TrendUp_C - Stop*Point;
if (StopSecours > 0) {PrixStop = PrixOrdre + StopSecours*Point;}
}
Print ("Modification prix entrée ordre SELLSTOP ", OrderTicket(), ", ", PrixOrdre, " stop ", PrixStop);
OrderModify(OrderTicket(),PrixOrdre, PrixStop, 0, 0, CLR_NONE);
continue;
}
}
}
}
}
//========================================================================================================================================================
void CloseOrdre (string CategOrdre)
{
double PrixOrdre;
for(cnt = 0; cnt < OrdersTotal(); cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber)
{
if (CategOrdre == "STOP" || CategOrdre == "ALL")
{
if (OrderType() == OP_BUYSTOP || OrderType() == OP_SELLSTOP)
{
OrderDelete(OrderTicket(), CLR_NONE);
Print ("Fermeture ordre en attente ", OrderTicket());
continue;
}
}
if (CategOrdre == "BUY" || CategOrdre == "ALL")
{
if (OrderType() == OP_BUY)
{
PrixOrdre = Bid;
if (CadrageDigit) {PrixOrdre = NormalizeDouble(Bid, Digit);}
OrderClose(OrderTicket(),OrderLots(), PrixOrdre, Slippage, Red);
Print ("Fermeture ordre BUY ", OrderTicket(), " à ", Bid);
continue;
}
}
if (CategOrdre == "SELL" || CategOrdre == "ALL")
{
if (OrderType() == OP_SELL)
{
PrixOrdre = Ask;
if (CadrageDigit) {PrixOrdre = NormalizeDouble(Ask, Digit);}
OrderClose(OrderTicket(),OrderLots(), PrixOrdre, Slippage, Red);
Print ("Fermeture ordre SELL ", OrderTicket(), " à ", Ask);
continue;
}
}
if (CategOrdre == "SELLSTOP")
{
if (OrderType() == OP_SELLSTOP)
{
OrderDelete(OrderTicket(), CLR_NONE);
Print ("Fermeture ordre en attente ", OrderTicket());
continue;
}
}
if (CategOrdre == "BUYSTOP")
{
if (OrderType() == OP_BUYSTOP)
{
OrderDelete(OrderTicket(), CLR_NONE);
Print ("Fermeture ordre en attente ", OrderTicket());
continue;
}
}
}
}
}
//========================================================================================================================================================
int TotalOrdre (string CategOrdre)
{
int i;
for(cnt = 0; cnt < OrdersTotal(); cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber)
{
if (CategOrdre == "ALL")
{
if (OrderType() == OP_BUY || OrderType() == OP_SELL || OrderType() == OP_BUYSTOP || OrderType() == OP_SELLSTOP) {i++; continue;}
}
if (CategOrdre == "BUY")
{
if (OrderType() == OP_BUY) {i++; continue;}
}
if (CategOrdre == "SELL")
{
if (OrderType() == OP_SELL) {i++; continue;}
}
if (CategOrdre == "BUYSTOP")
{
if (OrderType() == OP_BUYSTOP) {i++; continue;}
}
if (CategOrdre == "SELLSTOP")
{
if (OrderType() == OP_SELLSTOP) {i++; continue;}
}
}
}
return(i);
}
//========================================================================================================================================================
string iif(bool Condition, string Vrai, string Faux)
{
if (Condition) {return (Vrai);}
return (Faux);
}
//========================================================================================================================================================
void VerifFinTrading ()
{
if (CloseEndDay && TotalOrdre("ALL") > 0)
{
if ((Hour() > HeureFin) || (Hour() == HeureFin && Minute() >= MinutFin))
{
Print("Clôture des ordres en cours");
CloseOrdre("ALL");
Iteration=0;
return(0);
}
}
if (TotalOrdre("ALL") > 0)
{
if ((Hour() > HeureFin) || (Hour() == HeureFin && Minute() >= MinutFin))
{
Print("Clôture des ordres en cours à ", Hour(),':',Minute());
CloseOrdre("STOP");
Iteration=0;
return(0);
}
}
}
//========================================================================================================================================================
void VerifInversion ()
{
if (CloseReverse && Inversion == "Non" )
{
if (Trend_C == -1 && TotalOrdre("BUY") > 0)
{
Print("Clôture des ordres en cours");
CloseOrdre("BUY");
CloseOrdre("SELLSTOP");
Sleep(50);
Print("Création des ordres inverses");
OpenSell();
Sleep(50);
OpenBuyStop() ;
return(0);
}
if (Trend_C == 1 && TotalOrdre("SELL") > 0)
{
Print("Clôture des ordres en cours");
CloseOrdre("SELL");
CloseOrdre("BUYSTOP");
Sleep(50);
Print("Création des ordres inverses");
OpenBuy();
Sleep(50);
OpenSellStop() ;
return(0);
}
}
}
//========================================================================================================================================================
string NomPeriode ()
{
if( Period() == 1 ) { return(" M1 " );}
else if( Period() == 5 ) { return(" M5 " );}
else if( Period() == 15 ) { return(" M15 ");}
else if( Period() == 30 ) { return(" M30 ");}
else if( Period() == 60 ) { return(" H1 " );}
else if( Period() == 240 ) { return(" H4 " );}
else if( Period() == 1440 ) { return(" D1 " );}
else if( Period() == 10080 ){ return(" W1 " );}
else if( Period() == 43200 ){ return(" MN " );}
}
//========================================================================================================================================================
//+------------------------------------------------------------------+
//| Return error description |
//+------------------------------------------------------------------+
string ErrorDescription(int error_code)
{
string error_string;
//----
switch(error_code)
{
//---- codes returned from trade server
case 0:
case 1: error_string="no error"; break;
case 2: error_string="common error"; break;
case 3: error_string="invalid trade parameters"; break;
case 4: error_string="trade server is busy"; break;
case 5: error_string="old version of the client terminal"; break;
case 6: error_string="no connection with trade server"; break;
case 7: error_string="not enough rights"; break;
case 8: error_string="too frequent requests"; break;
case 9: error_string="malfunctional trade operation"; break;
case 64: error_string="account disabled"; break;
case 65: error_string="invalid account"; break;
case 128: error_string="trade timeout"; break;
case 129: error_string="invalid price"; break;
case 130: error_string="invalid stops"; break;
case 131: error_string="invalid trade volume"; break;
case 132: error_string="market is closed"; break;
case 133: error_string="trade is disabled"; break;
case 134: error_string="not enough money"; break;
case 135: error_string="price changed"; break;
case 136: error_string="off quotes"; break;
case 137: error_string="broker is busy"; break;
case 138: error_string="requote"; break;
case 139: error_string="order is locked"; break;
case 140: error_string="long positions only allowed"; break;
case 141: error_string="too many requests"; break;
case 145: error_string="modification denied because order too close to market"; break;
case 146: error_string="trade context is busy"; break;
//---- mql4 errors
case 4000: error_string="no error"; break;
case 4001: error_string="wrong function pointer"; break;
case 4002: error_string="array index is out of range"; break;
case 4003: error_string="no memory for function call stack"; break;
case 4004: error_string="recursive stack overflow"; break;
case 4005: error_string="not enough stack for parameter"; break;
case 4006: error_string="no memory for parameter string"; break;
case 4007: error_string="no memory for temp string"; break;
case 4008: error_string="not initialized string"; break;
case 4009: error_string="not initialized string in array"; break;
case 4010: error_string="no memory for array\' string"; break;
case 4011: error_string="too long string"; break;
case 4012: error_string="remainder from zero divide"; break;
case 4013: error_string="zero divide"; break;
case 4014: error_string="unknown command"; break;
case 4015: error_string="wrong jump (never generated error)"; break;
case 4016: error_string="not initialized array"; break;
case 4017: error_string="dll calls are not allowed"; break;
case 4018: error_string="cannot load library"; break;
case 4019: error_string="cannot call function"; break;
case 4020: error_string="expert function calls are not allowed"; break;
case 4021: error_string="not enough memory for temp string returned from function"; break;
case 4022: error_string="system is busy (never generated error)"; break;
case 4050: error_string="invalid function parameters count"; break;
case 4051: error_string="invalid function parameter value"; break;
case 4052: error_string="string function internal error"; break;
case 4053: error_string="some array error"; break;
case 4054: error_string="incorrect series array using"; break;
case 4055: error_string="custom indicator error"; break;
case 4056: error_string="arrays are incompatible"; break;
case 4057: error_string="global variables processing error"; break;
case 4058: error_string="global variable not found"; break;
case 4059: error_string="function is not allowed in testing mode"; break;
case 4060: error_string="function is not confirmed"; break;
case 4061: error_string="send mail error"; break;
case 4062: error_string="string parameter expected"; break;
case 4063: error_string="integer parameter expected"; break;
case 4064: error_string="double parameter expected"; break;
case 4065: error_string="array as parameter expected"; break;
case 4066: error_string="requested history data in update state"; break;
case 4099: error_string="end of file"; break;
case 4100: error_string="some file error"; break;
case 4101: error_string="wrong file name"; break;
case 4102: error_string="too many opened files"; break;
case 4103: error_string="cannot open file"; break;
case 4104: error_string="incompatible access to a file"; break;
case 4105: error_string="no order selected"; break;
case 4106: error_string="unknown symbol"; break;
case 4107: error_string="invalid price parameter for trade function"; break;
case 4108: error_string="invalid ticket"; break;
case 4109: error_string="trade is not allowed"; break;
case 4110: error_string="longs are not allowed"; break;
case 4111: error_string="shorts are not allowed"; break;
case 4200: error_string="object is already exist"; break;
case 4201: error_string="unknown object property"; break;
case 4202: error_string="object is not exist"; break;
case 4203: error_string="unknown object type"; break;
case 4204: error_string="no object name"; break;
case 4205: error_string="object coordinates error"; break;
case 4206: error_string="no specified subwindow"; break;
default: error_string="unknown error";
}
//----
return(error_string);
}
//+------------------------------------------------------------------+
// Fin de l'EA
L'indicateur
Code
//+------------------------------------------------------------------+
//| SuperTrend.mq4 v1.2 |
//| Copyright © 2008, Jason Robinson (jnrtrading). |
//| http://www.spreadtrade2win.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Jason Robinson."
#property link "http://www.spreadtrade2win.com"
#property indicator_chart_window
#property indicator_color1 Lime
#property indicator_color2 Red
#property indicator_width1 2
#property indicator_width2 2
#property indicator_buffers 3
double TrendUp[], TrendDown[];
double TrendX[];
int changeOfTrend;
extern int Nbr_Periods = 10;
extern int Multiplier = 3;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexBuffer(0, TrendUp);
SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2);
SetIndexLabel(0, "Trend Up");
SetIndexBuffer(1, TrendDown);
SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2);
SetIndexLabel(1, "Trend Down");
SetIndexBuffer(2, TrendX);
SetIndexStyle(2, DRAW_NONE);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit, i, flag, flagh, trend[5000];
double up[5000], dn[5000], medianPrice, atr;
int counted_bars = IndicatorCounted();
//---- check for possible errors
if(counted_bars < 0) return(-1);
//---- last counted bar will be recounted
if(counted_bars > 0) counted_bars--;
limit=Bars-counted_bars;
//Print(limit);
//----
for (i = Bars; i >= 0; i--) {
TrendUp[i] = EMPTY_VALUE;
TrendDown[i] = EMPTY_VALUE;
atr = iATR(NULL, 0, Nbr_Periods, i);
//Print("atr: "+atr[i]);
medianPrice = (High[i]+Low[i])/2;
//Print("medianPrice: "+medianPrice[i]);
up[i]=medianPrice+(Multiplier*atr);
//Print("up: "+up[i]);
dn[i]=medianPrice-(Multiplier*atr);
//Print("dn: "+dn[i]);
trend[i]=1;
if (Close[i]>up[i+1]) {
trend[i]=1;
if (trend[i+1] == -1) changeOfTrend = 1;
//Print("trend: "+trend[i]);
}
else if (Close[i]<dn[i+1]) {
trend[i]=-1;
if (trend[i+1] == 1) changeOfTrend = 1;
//Print("trend: "+trend[i]);
}
else if (trend[i+1]==1) {
trend[i]=1;
changeOfTrend = 0;
}
else if (trend[i+1]==-1) {
trend[i]=-1;
changeOfTrend = 0;
}
TrendX[i] = trend[i];
//Print("TrendX["+i+"]: "+TrendX[i]);
if (trend[i]<0 && trend[i+1]>0) {
flag=1;
//Print("flag: "+flag);
}
else {
flag=0;
//Print("flagh: "+flag);
}
if (trend[i]>0 && trend[i+1]<0) {
flagh=1;
//Print("flagh: "+flagh);
}
else {
flagh=0;
//Print("flagh: "+flagh);
}
if (trend[i]>0 && dn[i]<dn[i+1])
dn[i]=dn[i+1];
if (trend[i]<0 && up[i]>up[i+1])
up[i]=up[i+1];
if (flag==1)
up[i]=medianPrice+(Multiplier*atr);
if (flagh==1)
dn[i]=medianPrice-(Multiplier*atr);
//-- Draw the indicator
if (trend[i]==1) {
TrendUp[i]=dn[i];
if (changeOfTrend == 1) {
TrendUp[i+1] = TrendDown[i+1];
changeOfTrend = 0;
}
}
else if (trend[i]==-1) {
TrendDown[i]=up[i];
if (changeOfTrend == 1) {
TrendDown[i+1] = TrendUp[i+1];
changeOfTrend = 0;
}
}
}
WindowRedraw();
//----
return(0);
}
//+------------------------------------------------------------------+