Mon compte
Déjà membre ? S'identifier
Non inscrit ? S'inscrire
 
+ Répondre à la discussion
Page 1 sur 2 1 2 DernièreDernière
Affichage des résultats 1 à 10 sur 19
  1. #1
    Membre lvl 5 matthieu21 est sur la route de la réputation...
    Date d'inscription
    November 2010
    Messages
    15
    Pouvoir de réputation
    3

    besoin d'aide sur un EA déjà fait besoin d'aide sur un EA déjà fait

    voici un EA que j'ai construit avec ce site : Expert Advisor Builder for metatrader 4

    Il marche parfaitement bien pour la taille du lot, pour l'entrée mais pour la sortie j'ai certaines fois des surprises.

    Il sort systèmatiquement dans la seconde suivant son entrée puis re-rentre (logique) et re-sort dans la seconde (pas logique). Du coup je perd chaque seconde le spread (ça va bien que je suis en démo). Par contre si je ferme MT4 et que je le rouvre il rentre normalement et sort normalement !!! Pouvez-vous me dire si j'ai loupé un épisode ou comment écrire le script sachant que je veux sortir à la fin de la bougie et que j'ai pas trouvé d'autres moyens pour cela que de lui dire de sortir si l'open shift 0 est >, = ou < que l'open shift -1 pour qu'à l'open suivant (donc à la clôture de ma bougie) le trade se clôture. Cela marche mais pas tout le temps et j'arrive pas à comprendre la raison.

    //+------------------------------------------------------------------+
    //| This MQL is generated by Expert Advisor Builder |
    //| Expert Advisor Builder for MetaTrader 4 |
    //| |
    //| In no event will author be liable for any damages whatsoever. |
    //| Use at your own risk. |
    //| |
    //+------------------- DO NOT REMOVE THIS HEADER --------------------+

    #define SIGNAL_NONE 0
    #define SIGNAL_BUY 1
    #define SIGNAL_SELL 2
    #define SIGNAL_CLOSEBUY 3
    #define SIGNAL_CLOSESELL 4

    #property copyright "Expert Advisor Builder"
    #property link "http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/"

    extern int MagicNumber = 0;
    extern bool SignalMail = False;
    extern bool EachTickMode = True;
    extern double Lots = 0.1;
    extern int Slippage = 3;
    extern bool UseStopLoss = False;
    extern int StopLoss = 30;
    extern bool UseTakeProfit = False;
    extern int TakeProfit = 60;
    extern bool UseTrailingStop = False;
    extern int TrailingStop = 30;

    int BarCount;
    int Current;
    bool TickCheck = False;
    //+------------------------------------------------------------------+
    //| expert initialization function |
    //+------------------------------------------------------------------+
    int init() {
    BarCount = Bars;

    if (EachTickMode) Current = 0; else Current = 1;

    return(0);
    }
    //+------------------------------------------------------------------+
    //| expert deinitialization function |
    //+------------------------------------------------------------------+
    int deinit() {
    return(0);
    }
    //+------------------------------------------------------------------+
    //| expert start function |
    //+------------------------------------------------------------------+
    int start() {
    int Order = SIGNAL_NONE;
    int Total, Ticket;
    double StopLossLevel, TakeProfitLevel;



    if (EachTickMode && Bars != BarCount) TickCheck = False;
    Total = OrdersTotal();
    Order = SIGNAL_NONE;

    //+------------------------------------------------------------------+
    //| Variable Begin |
    //+------------------------------------------------------------------+


    double Buy1_1 = iSAR(NULL, PERIOD_M15, 0.02, 0.2, Current + 0);
    double Buy1_2 = iOpen(NULL, PERIOD_M15, Current + 0);
    double Buy2_1 = iSAR(NULL, PERIOD_M15, 0.02, 0.2, Current + 1);
    double Buy2_2 = iOpen(NULL, PERIOD_M15, Current + 1);

    double Sell1_1 = iSAR(NULL, PERIOD_M15, 0.02, 0.2, Current + 0);
    double Sell1_2 = iOpen(NULL, PERIOD_M15, Current + 0);
    double Sell2_1 = iSAR(NULL, PERIOD_M15, 0.02, 0.2, Current + 1);
    double Sell2_2 = iOpen(NULL, PERIOD_M15, Current + 1);

    double CloseBuy1_1 = iOpen(NULL, PERIOD_M15, Current + 0);
    double CloseBuy1_2 = iOpen(NULL, PERIOD_M15, Current - 1);
    double CloseBuy2_1 = iOpen(NULL, PERIOD_M15, Current + 0);
    double CloseBuy2_2 = iOpen(NULL, PERIOD_M15, Current - 1);

    double CloseSell1_1 = iOpen(NULL, PERIOD_M15, Current + 0);
    double CloseSell1_2 = iOpen(NULL, PERIOD_M15, Current - 1);
    double CloseSell2_1 = iOpen(NULL, PERIOD_M15, Current + 0);
    double CloseSell2_2 = iOpen(NULL, PERIOD_M15, Current - 1);


    //+------------------------------------------------------------------+
    //| Variable End |
    //+------------------------------------------------------------------+

    //Check position
    bool IsTrade = False;

    for (int i = 0; i < Total; i ++) {
    OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
    if(OrderType() <= OP_SELL && OrderSymbol() == Symbol()) {
    IsTrade = True;
    if(OrderType() == OP_BUY) {
    //Close

    //+------------------------------------------------------------------+
    //| Signal Begin(Exit Buy) |
    //+------------------------------------------------------------------+

    if (CloseBuy1_1 >= CloseBuy1_2 || CloseBuy2_1 <= CloseBuy2_2) Order = SIGNAL_CLOSEBUY;


    //+------------------------------------------------------------------+
    //| Signal End(Exit Buy) |
    //+------------------------------------------------------------------+

    if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
    OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
    if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");
    if (!EachTickMode) BarCount = Bars;
    IsTrade = False;
    continue;
    }
    //Trailing stop
    if(UseTrailingStop && TrailingStop > 0) {
    if(Bid - OrderOpenPrice() > Point * TrailingStop) {
    if(OrderStopLoss() < Bid - Point * TrailingStop) {
    OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);
    if (!EachTickMode) BarCount = Bars;
    continue;
    }
    }
    }
    } else {
    //Close

    //+------------------------------------------------------------------+
    //| Signal Begin(Exit Sell) |
    //+------------------------------------------------------------------+

    if (CloseSell1_1 >= CloseSell1_2 || CloseSell2_1 <= CloseSell2_2) Order = SIGNAL_CLOSESELL;


    //+------------------------------------------------------------------+
    //| Signal End(Exit Sell) |
    //+------------------------------------------------------------------+

    if (Order == SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
    OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);
    if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");
    if (!EachTickMode) BarCount = Bars;
    IsTrade = False;
    continue;
    }
    //Trailing stop
    if(UseTrailingStop && TrailingStop > 0) {
    if((OrderOpenPrice() - Ask) > (Point * TrailingStop)) {
    if((OrderStopLoss() > (Ask + Point * TrailingStop)) || (OrderStopLoss() == 0)) {
    OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, DarkOrange);
    if (!EachTickMode) BarCount = Bars;
    continue;
    }
    }
    }
    }
    }
    }

    //+------------------------------------------------------------------+
    //| Signal Begin(Entry) |
    //+------------------------------------------------------------------+

    if (Buy1_1 < Buy1_2 && Buy2_1 > Buy2_2) Order = SIGNAL_BUY;

    if (Sell1_1 > Sell1_2 && Sell2_1 < Sell2_2) Order = SIGNAL_SELL;


    //+------------------------------------------------------------------+
    //| Signal End |
    //+------------------------------------------------------------------+

    //Buy
    if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
    if(!IsTrade) {
    //Check free margin
    if (AccountFreeMargin() < (0.00000000001 * Lots)) {
    Print("We have no money. Free Margin = ", AccountFreeMargin());
    return(0);
    }

    if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;
    if (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * Point; else TakeProfitLevel = 0.0;

    Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);
    if(Ticket > 0) {
    if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
    Print("BUY order opened : ", OrderOpenPrice());
    if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");
    } else {
    Print("Error opening BUY order : ", GetLastError());
    }
    }
    if (EachTickMode) TickCheck = True;
    if (!EachTickMode) BarCount = Bars;
    return(0);
    }
    }

    //Sell
    if (Order == SIGNAL_SELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
    if(!IsTrade) {
    //Check free margin
    if (AccountFreeMargin() < (0.00000000001 * Lots)) {
    Print("We have no money. Free Margin = ", AccountFreeMargin());
    return(0);
    }

    if (UseStopLoss) StopLossLevel = Bid + StopLoss * Point; else StopLossLevel = 0.0;
    if (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit * Point; else TakeProfitLevel = 0.0;

    Ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);
    if(Ticket > 0) {
    if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
    Print("SELL order opened : ", OrderOpenPrice());
    if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");
    } else {
    Print("Error opening SELL order : ", GetLastError());
    }
    }
    if (EachTickMode) TickCheck = True;
    if (!EachTickMode) BarCount = Bars;
    return(0);
    }
    }

    if (!EachTickMode) BarCount = Bars;

    return(0);
    }
    //+---------------------

    merci d'avance pour vos idées

  2. #2
    Membre Performance jeanjo est sur la route de la réputation...
    Date d'inscription
    November 2010
    Messages
    181
    Pouvoir de réputation
    3

    ppp ppp

    j'ai résolu ce problème de cette façon :


    Je ferme mes vente en premier*********Close Sell

    if (Close_sell == true || action == true || action2 == true)
    {

    while(Bars == standby) return; // Si on est dans la même bougie que le Open Sell, ne fais rien.

    //****Vente**************************

    if(Open_sell ==true && total ==0) //
    {
    vente = OrderSend(Symbol(),OP_SELL,Lots,Bid,0,0,0,NULL,222 650,0,Red);
    vendu = OrderSelect(vente,SELECT_BY_TICKET,MODE_TRADES);
    if(vendu == true) standby= Bars;

    ************************************************** *

    Je mets un flag Standby sur la Bars au moment de la vente, puis pour éviter qu'il ne revende dans la même bougie, je lui dis : si la Bars est la même return(0), ne fais rien

    if( Bars==standby) return(0)
    Dernière modification par jeanjo ; 15/12/2010 à 13h02.

  3. #3
    Membre Performance jeanjo est sur la route de la réputation...
    Date d'inscription
    November 2010
    Messages
    181
    Pouvoir de réputation
    3

    aa aa

    Il faut que tu mettes un flag quelque part, un bool qui doit être mis à false avant le Start().

    Puis si la vente est réalisé, flag = true.

    Puis pour éviter la revente, il faut dire :

    Si flag = true et si on est dans la même bougie, ne pas revendre.

    puis lorsque les conditions de Close Sell sont réalisée dans une autre bougie; et que la revente est effectué, flag = false, sinon il ne reprendra jamais d'ordre

  4. #4
    Membre lvl 5 matthieu21 est sur la route de la réputation...
    Date d'inscription
    November 2010
    Messages
    15
    Pouvoir de réputation
    3

    encore une petite aide encore une petite aide

    à quel endroit tu insérerez ce correctif ? peut-tu me dire à partir de quelle ligne ? merci encore

  5. #5
    Membre lvl 5 matthieu21 est sur la route de la réputation...
    Date d'inscription
    November 2010
    Messages
    15
    Pouvoir de réputation
    3

    suite suite

    merci pour ces précisions mais en fait je veux juste avoir un code de close pour fermer systématiquement à l'ouverture de la bougie M15 suivante. si cela fonctionne il ne devrait pas avoir besoin de lui interdire d'ouvrir plusieurs fois dans le même chandelier. tu comprends ma demande ? j'ai un peu de mal à l'exprimer

    en gros j'achète ou je vends selon les conditions définis dans la bougie 12h-12h15 et j'aimerais qu'il me ferme tout seul l'ordre à l'ouverture de la bougie 12h15-12h30 mais je n'y arrive pas ! lol

  6. #6
    Membre Performance jeanjo est sur la route de la réputation...
    Date d'inscription
    November 2010
    Messages
    181
    Pouvoir de réputation
    3

    Si tu veux vendre à l'ouverture d'une nouvelle bougie, il y a trois choses qui sont différentes a chaque ouverture de nouvelle bougie, le OpenTime, la Bars, et le volume.

    On peut dire

    if(volume[0] =0)
    {
    OrderClose e c t

    Le volume n'est à zéro qu'à l'ouverture de la bougie
    Dernière modification par jeanjo ; 15/12/2010 à 20h40.

  7. #7
    Membre Performance jeanjo est sur la route de la réputation...
    Date d'inscription
    November 2010
    Messages
    181
    Pouvoir de réputation
    3

    //+------------------------------------------------------------------+
    //| This MQL is generated by Expert Advisor Builder |
    //| Expert Advisor Builder for MetaTrader 4 |
    //| |
    //| In no event will author be liable for any damages whatsoever. |
    //| Use at your own risk. |
    //| |
    //+------------------- DO NOT REMOVE THIS HEADER --------------------+

    #define SIGNAL_NONE 0
    #define SIGNAL_BUY 1
    #define SIGNAL_SELL 2
    #define SIGNAL_CLOSEBUY 3
    #define SIGNAL_CLOSESELL 4

    #property copyright "Expert Advisor Builder"
    #property link "http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/"

    extern int MagicNumber = 0;
    extern bool SignalMail = False;
    extern bool EachTickMode = True;
    extern double Lots = 0.1;
    extern int Slippage = 3;
    extern bool UseStopLoss = False;
    extern int StopLoss = 30;
    extern bool UseTakeProfit = False;
    extern int TakeProfit = 60;
    extern bool UseTrailingStop = False;
    extern int TrailingStop = 30;

    int BarCount;
    int Current;
    bool TickCheck = False;
    //+------------------------------------------------------------------+
    //| expert initialization function |
    //+------------------------------------------------------------------+
    int init() {
    BarCount = Bars;

    if (EachTickMode) Current = 0; else Current = 1;

    return(0);
    }
    //+------------------------------------------------------------------+
    //| expert deinitialization function |
    //+------------------------------------------------------------------+
    int deinit() {
    return(0);
    }
    //+------------------------------------------------------------------+
    //| expert start function |
    //+------------------------------------------------------------------+
    int start() {
    int Order = SIGNAL_NONE;
    int Total, Ticket;
    double StopLossLevel, TakeProfitLevel;



    if (EachTickMode && Bars != BarCount) TickCheck = False;
    Total = OrdersTotal();
    Order = SIGNAL_NONE;

    //+------------------------------------------------------------------+
    //| Variable Begin | Critérion
    //+------------------------------------------------------------------+


    double Buy1_1 = iSAR(NULL, PERIOD_M15, 0.02, 0.2, Current + 0);
    double Buy1_2 = iOpen(NULL, PERIOD_M15, Current + 0);
    double Buy2_1 = iSAR(NULL, PERIOD_M15, 0.02, 0.2, Current + 1);
    double Buy2_2 = iOpen(NULL, PERIOD_M15, Current + 1);

    double Sell1_1 = iSAR(NULL, PERIOD_M15, 0.02, 0.2, Current + 0);
    double Sell1_2 = iOpen(NULL, PERIOD_M15, Current + 0);
    double Sell2_1 = iSAR(NULL, PERIOD_M15, 0.02, 0.2, Current + 1);
    double Sell2_2 = iOpen(NULL, PERIOD_M15, Current + 1);

    double CloseBuy1_1 = iOpen(NULL, PERIOD_M15, Current + 0);
    double CloseBuy1_2 = iOpen(NULL, PERIOD_M15, Current - 1);
    double CloseBuy2_1 = iOpen(NULL, PERIOD_M15, Current + 0);
    double CloseBuy2_2 = iOpen(NULL, PERIOD_M15, Current - 1);

    double CloseSell1_1 = iOpen(NULL, PERIOD_M15, Current + 0);
    double CloseSell1_2 = iOpen(NULL, PERIOD_M15, Current - 1);
    double CloseSell2_1 = iOpen(NULL, PERIOD_M15, Current + 0);
    double CloseSell2_2 = iOpen(NULL, PERIOD_M15, Current - 1);


    //+------------------------------------------------------------------+
    //| Variable End |// Selectionne les ordres pour voir s'il y a des ordres achat ou vente
    //+------------------------------------------------------------------+

    //Check position
    bool IsTrade = False;

    for (int i = 0; i < Total; i ++) {
    OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
    if(OrderType() <= OP_SELL && OrderSymbol() == Symbol()) {
    IsTrade = True;
    if(OrderType() == OP_BUY) {
    //Close

    //+------------------------------------------------------------------+
    /*| Signal Begin(Exit Buy) | S'il y a un ordre d'achat ET si les critères de vente sont réunis--> fermer = SIGNAL_CLOSEBUY*/
    //+------------------------------------------------------------------+

    if (CloseBuy1_1 >= CloseBuy1_2 || CloseBuy2_1 <= CloseBuy2_2) Order = SIGNAL_CLOSEBUY;


    //+------------------------------------------------------------------+
    //| Signal End(Exit Buy) | // lance l'ordre de close
    //+------------------------------------------------------------------+
    //LORSQUE L ORDRE DE FERMETURE EST PASSE, MET UN FLAG SUR LA BARS,
    // BarCount = Bars (= cette bougie à la n° de la Bars)
    // Ensuite dans les conditions de vente ou achat
    // if(Bars != BarCount) = Si cette Bars est différente de la Bars de fermeture, alors achat ou vente
    //LORSQU IL FERME LES ORDRES IL ENREGISTRE LE NUMERO DE LA BARS POUR EVITER QUE
    // LE PROGRAMME NE REPRENNE POSITION DIRECTEMENT APRES
    // LES CONDITIONS D OUVERTURE D ORDRE ETANT TOUJOURS VALIDES



    if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
    OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
    if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");
    if (!EachTickMode) BarCount = Bars; // Met un flag sur la Bars
    IsTrade = False;
    continue;
    }
    //Trailing stop
    if(UseTrailingStop && TrailingStop > 0) {
    if(Bid - OrderOpenPrice() > Point * TrailingStop) {
    if(OrderStopLoss() < Bid - Point * TrailingStop) {
    OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);
    if (!EachTickMode) BarCount = Bars; // Flag sur Bars
    continue;
    }
    }
    }
    } else {
    //Close

    //+------------------------------------------------------------------+
    /* /| Signal Begin(Exit Sell) | Même opération pour les fermeture des ventes; S'il y a un ordre de vente --> fermer = SIGNAL_CLOSESELL */
    //+------------------------------------------------------------------+

    if (CloseSell1_1 >= CloseSell1_2 || CloseSell2_1 <= CloseSell2_2) Order = SIGNAL_CLOSESELL;


    //+------------------------------------------------------------------+
    //| Signal End(Exit Sell) |
    //+------------------------------------------------------------------+

    if (Order == SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
    OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);
    if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");
    if (!EachTickMode) BarCount = Bars; //Flag sur Bars
    IsTrade = False;
    continue;
    }
    //Trailing stop
    if(UseTrailingStop && TrailingStop > 0) {
    if((OrderOpenPrice() - Ask) > (Point * TrailingStop)) {
    if((OrderStopLoss() > (Ask + Point * TrailingStop)) || (OrderStopLoss() == 0)) {
    OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, DarkOrange);
    if (!EachTickMode) BarCount = Bars;
    continue;
    }
    }
    }
    }
    }
    }

    //+------------------------------------------------------------------+
    //| Signal Begin(Entry) |
    //+------------------------------------------------------------------+

    if (Buy1_1 < Buy1_2 && Buy2_1 > Buy2_2) Order = SIGNAL_BUY;

    if (Sell1_1 > Sell1_2 && Sell2_1 < Sell2_2) Order = SIGNAL_SELL;


    //+------------------------------------------------------------------+
    //| Signal End |
    //+------------------------------------------------------------------+

    //Buy
    if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
    if(!IsTrade) {
    //Check free margin
    if (AccountFreeMargin() < (0.00000000001 * Lots)) {
    Print("We have no money. Free Margin = ", AccountFreeMargin());
    return(0);
    }

    if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;
    if (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * Point; else TakeProfitLevel = 0.0;

    Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);
    if(Ticket > 0) {
    if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
    Print("BUY order opened : ", OrderOpenPrice());
    if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");
    } else {
    Print("Error opening BUY order : ", GetLastError());
    }
    }
    if (EachTickMode) TickCheck = True;
    if (!EachTickMode) BarCount = Bars;
    return(0);
    }
    }

    //Sell
    if (Order == SIGNAL_SELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
    if(!IsTrade) {
    //Check free margin
    if (AccountFreeMargin() < (0.00000000001 * Lots)) {
    Print("We have no money. Free Margin = ", AccountFreeMargin());
    return(0);
    }

    if (UseStopLoss) StopLossLevel = Bid + StopLoss * Point; else StopLossLevel = 0.0;
    if (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit * Point; else TakeProfitLevel = 0.0;

    Ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);
    if(Ticket > 0) {
    if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
    Print("SELL order opened : ", OrderOpenPrice());
    if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");
    } else {
    Print("Error opening SELL order : ", GetLastError());
    }
    }
    if (EachTickMode) TickCheck = True;
    if (!EachTickMode) BarCount = Bars;
    return(0);
    }
    }

    if (!EachTickMode) BarCount = Bars;

    return(0);
    }
    Dernière modification par jeanjo ; 16/12/2010 à 13h00.

  8. #8
    Membre Performance jeanjo est sur la route de la réputation...
    Date d'inscription
    November 2010
    Messages
    181
    Pouvoir de réputation
    3

    //+------------------------------------------------------------------+
    //| This MQL is generated by Expert Advisor Builder |
    //| Expert Advisor Builder for MetaTrader 4 |
    //| |
    //| In no event will author be liable for any damages whatsoever. |
    //| Use at your own risk. |
    //| |
    //+------------------- DO NOT REMOVE THIS HEADER --------------------+

    #define SIGNAL_NONE 0
    #define SIGNAL_BUY 1
    #define SIGNAL_SELL 2
    #define SIGNAL_CLOSEBUY 3
    #define SIGNAL_CLOSESELL 4

    #property copyright "Expert Advisor Builder"
    #property link "http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/"

    extern int MagicNumber = 0;
    extern bool SignalMail = False;
    extern bool EachTickMode = True;
    extern double Lots = 0.1;
    extern int Slippage = 3;
    extern bool UseStopLoss = False;
    extern int StopLoss = 30;
    extern bool UseTakeProfit = False;
    extern int TakeProfit = 60;
    extern bool UseTrailingStop = False;
    extern int TrailingStop = 30;

    int BarCount;
    int Current;
    bool TickCheck = False;
    //+------------------------------------------------------------------+
    //| expert initialization function |
    //+------------------------------------------------------------------+
    int init() {
    BarCount = Bars;

    if (EachTickMode) Current = 0; else Current = 1;

    return(0);
    }
    //+------------------------------------------------------------------+
    //| expert deinitialization function |
    //+------------------------------------------------------------------+
    int deinit() {
    return(0);
    }
    //+------------------------------------------------------------------+
    //| expert start function |
    //+------------------------------------------------------------------+
    int start() {
    int Order = SIGNAL_NONE;
    int Total, Ticket;
    double StopLossLevel, TakeProfitLevel;



    if (EachTickMode && Bars != BarCount) TickCheck = False;
    Total = OrdersTotal();
    Order = SIGNAL_NONE;

    //+------------------------------------------------------------------+
    //| Variable Begin | Critérion
    //+------------------------------------------------------------------+


    double Buy1_1 = iSAR(NULL, PERIOD_M15, 0.02, 0.2, Current + 0);
    double Buy1_2 = iOpen(NULL, PERIOD_M15, Current + 0);
    double Buy2_1 = iSAR(NULL, PERIOD_M15, 0.02, 0.2, Current + 1);
    double Buy2_2 = iOpen(NULL, PERIOD_M15, Current + 1);

    double Sell1_1 = iSAR(NULL, PERIOD_M15, 0.02, 0.2, Current + 0);
    double Sell1_2 = iOpen(NULL, PERIOD_M15, Current + 0);
    double Sell2_1 = iSAR(NULL, PERIOD_M15, 0.02, 0.2, Current + 1);
    double Sell2_2 = iOpen(NULL, PERIOD_M15, Current + 1);

    double CloseBuy1_1 = iOpen(NULL, PERIOD_M15, Current + 0);
    double CloseBuy1_2 = iOpen(NULL, PERIOD_M15, Current - 1);
    double CloseBuy2_1 = iOpen(NULL, PERIOD_M15, Current + 0);
    double CloseBuy2_2 = iOpen(NULL, PERIOD_M15, Current - 1);

    double CloseSell1_1 = iOpen(NULL, PERIOD_M15, Current + 0);
    double CloseSell1_2 = iOpen(NULL, PERIOD_M15, Current - 1);
    double CloseSell2_1 = iOpen(NULL, PERIOD_M15, Current + 0);
    double CloseSell2_2 = iOpen(NULL, PERIOD_M15, Current - 1);


    //+------------------------------------------------------------------+
    //| Variable End |// Selectionne les ordres pour voir s'il y a des ordres achat ou vente
    //+------------------------------------------------------------------+

    //Check position
    bool IsTrade = False;

    for (int i = 0; i < Total; i ++) {
    OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
    if(OrderType() <= OP_SELL && OrderSymbol() == Symbol()) {
    IsTrade = True;
    if(OrderType() == OP_BUY) {
    //Close

    //+------------------------------------------------------------------+
    /*| Signal Begin(Exit Buy) | S'il y a un ordre d'achat ET si les critères de vente sont réunis--> fermer = SIGNAL_CLOSEBUY*/
    //+------------------------------------------------------------------+

    if (CloseBuy1_1 >= CloseBuy1_2 || CloseBuy2_1 <= CloseBuy2_2) Order = SIGNAL_CLOSEBUY;


    //+------------------------------------------------------------------+
    //| Signal End(Exit Buy) | // lance l'ordre de close
    //+------------------------------------------------------------------+

    if (Volume[0]==0) {
    OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
    if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");
    if (!EachTickMode) BarCount = Bars;
    IsTrade = False;
    continue;
    }
    //Trailing stop
    if(UseTrailingStop && TrailingStop > 0) {
    if(Bid - OrderOpenPrice() > Point * TrailingStop) {
    if(OrderStopLoss() < Bid - Point * TrailingStop) {
    OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);
    if (!EachTickMode) BarCount = Bars;
    continue;
    }
    }
    }
    } else {
    //Close

    //+------------------------------------------------------------------+
    /* /| Signal Begin(Exit Sell) | Même opération pour les fermeture des ventes; S'il y a un ordre de vente --> fermer = SIGNAL_CLOSESELL */
    //+------------------------------------------------------------------+

    if (CloseSell1_1 >= CloseSell1_2 || CloseSell2_1 <= CloseSell2_2) Order = SIGNAL_CLOSESELL;


    //+------------------------------------------------------------------+
    //| Signal End(Exit Sell) |
    //+------------------------------------------------------------------+

    if (Volume[0]==0) {
    OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);
    if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");
    if (!EachTickMode) BarCount = Bars;
    IsTrade = False;
    continue;
    }
    //Trailing stop
    if(UseTrailingStop && TrailingStop > 0) {
    if((OrderOpenPrice() - Ask) > (Point * TrailingStop)) {
    if((OrderStopLoss() > (Ask + Point * TrailingStop)) || (OrderStopLoss() == 0)) {
    OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, DarkOrange);
    if (!EachTickMode) BarCount = Bars;
    continue;
    }
    }
    }
    }
    }
    }

    //+------------------------------------------------------------------+
    //| Signal Begin(Entry) |
    //+------------------------------------------------------------------+

    if (Buy1_1 < Buy1_2 && Buy2_1 > Buy2_2) Order = SIGNAL_BUY;

    if (Sell1_1 > Sell1_2 && Sell2_1 < Sell2_2) Order = SIGNAL_SELL;


    //+------------------------------------------------------------------+
    //| Signal End |
    //+------------------------------------------------------------------+

    //Buy
    if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
    if(!IsTrade) {
    //Check free margin
    if (AccountFreeMargin() < (0.00000000001 * Lots)) {
    Print("We have no money. Free Margin = ", AccountFreeMargin());
    return(0);
    }

    if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;
    if (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * Point; else TakeProfitLevel = 0.0;

    Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);
    if(Ticket > 0) {
    if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
    Print("BUY order opened : ", OrderOpenPrice());
    if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");
    } else {
    Print("Error opening BUY order : ", GetLastError());
    }
    }
    if (EachTickMode) TickCheck = True;
    if (!EachTickMode) BarCount = Bars;
    return(0);
    }
    }

    //Sell
    if (Order == SIGNAL_SELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
    if(!IsTrade) {
    //Check free margin
    if (AccountFreeMargin() < (0.00000000001 * Lots)) {
    Print("We have no money. Free Margin = ", AccountFreeMargin());
    return(0);
    }

    if (UseStopLoss) StopLossLevel = Bid + StopLoss * Point; else StopLossLevel = 0.0;
    if (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit * Point; else TakeProfitLevel = 0.0;

    Ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);
    if(Ticket > 0) {
    if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
    Print("SELL order opened : ", OrderOpenPrice());
    if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");
    } else {
    Print("Error opening SELL order : ", GetLastError());
    }
    }
    if (EachTickMode) TickCheck = True;
    if (!EachTickMode) BarCount = Bars;
    return(0);
    }
    }

    if (!EachTickMode) BarCount = Bars;

    return(0);
    }

  9. #9
    Membre Performance jeanjo est sur la route de la réputation...
    Date d'inscription
    November 2010
    Messages
    181
    Pouvoir de réputation
    3

    iiiii iiiii

    Tu peux essayer le code ci-dessus; S'il ne fonctionne pas, il faut voir le journal dans le tester, en bas il y a une rubrique "journal"

    On ne peut pas changer la logique de l'EA sans tout modifier, j'ai juste changer les critères de fermeture de vente et d'achat en lui disant, si le volume est à zéro, (à l'ouverture de la nouvelle bougie il est toujours à zéro); alors ferme les achats et les ventes)

    Je crois qu'il faut mettre un nombre pour le magic number, (si ça ne marche pas avec 0):
    Dernière modification par jeanjo ; 16/12/2010 à 09h50.

  10. #10
    Membre lvl 5 matthieu21 est sur la route de la réputation...
    Date d'inscription
    November 2010
    Messages
    15
    Pouvoir de réputation
    3

    merci merci

    j'essaye cela et je te tiens au courant !! qu'est-ce je regrette de pas avoir écouter les cours de programmation au lycée -

Discussions similaires

  1. besoin d'aide
    Par dell dans le forum Novice sur le Forex
    Réponses: 2
    Dernier message: 31/08/2010, 18h28
  2. besoin d'aide svp
    Par jpgianna dans le forum Trading Divers
    Réponses: 4
    Dernier message: 08/10/2009, 08h31
  3. besoin d'aide sur un ea
    Par milou dans le forum Systèmes de Trading Auto
    Réponses: 10
    Dernier message: 07/10/2009, 14h08
  4. Besoin d'aide s-v-p...
    Par Satie dans le forum Systèmes de Trading Auto
    Réponses: 13
    Dernier message: 18/09/2009, 20h48
  5. besoin d'aide
    Par irnosimao dans le forum Présentation des membres
    Réponses: 4
    Dernier message: 05/03/2009, 12h32

Ajouter aux Favoris | Plan du site | Archives | Forex | Contact