Rejoindre la communauté
banner_forum
Devenez membre de la plus grande
communauté francophone sur le Forex
Partagez, échangez et apprenez en gagnant des crédits sur votre compte de trading

Aide pour modification EA "Close Above Profit Level" sous MT4

  • Phil968

    Bonjour,
    J'utilise couramment l'EA "Close Above Profit Level" sous MT4.
    J'aimerais tout simplement modifier cet EA pour définir un niveau de perte en lieu et place du niveau de profit.
    C'est à dire créer un EA qui fait exactement le contraire de l'original.
    Le code ne me semble pas bien long, mais étant nul en langage de programmation, je ne sais pas apporter les modifications nécessaires !
    Une bonne âme pourrait-elle m'aider ?
    Ci-dessous, une copie du code original.
    Un grand merci !!

    // ---------------------------------------------------------------------------------- +
    // Mn Close above Profit level +
    // ---------------------------------------------------------------------------------- +
    #property copyright "Mn"
    #property show_confirm
    #property show_inputs

    extern int mSlippage = 3;
    extern string mCAP = "**** USE ENTIRELY AT OWN RISK *****";
    extern string mCAPx = "**** Profit level above which the order closes *****";
    extern double mProfit = 10.00;
    extern string mCAPxx = "** TAKE CARE SETTING THESE OPTIONS *****";
    extern string mCAPxxx = "** Set to 1 for all pairs : Set to 0 for CurrentChart Only *****";
    extern int mAllSymbol = 1;
    extern string mCAPxxxx = "** Set to 1 to close Longs in profit : 0 to ignore Longs *****";
    extern int mLong = 1;
    extern string mCAPxxxxx = "** Set to 1 to close Shorts in profit : 0 to ignore Shorts *****";
    extern int mShort = 1;

    // ---------------------------------------------------------------------------------- +
    int start()
    {
    int mType, mTotal = OrdersTotal();

    for(int i = mTotal-1; i>=0; i--)
    {
    OrderSelect(i, SELECT_BY_POS);
    mType = OrderType();
    bool mResult = false;

    if(OrderSymbol() == Symbol() || mAllSymbol == 1)
    {
    if(OrderProfit() >= mProfit)
    {
    switch(mType)
    {
    case OP_BUY :
    {
    if(mLong == 1)
    mResult = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, CLR_NONE );
    break;
    }
    case OP_SELL :
    {
    if(mShort == 1)
    mResult = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, CLR_NONE );
    break;
    }
    default :
    break;
    }

    if(mResult == false)
    {
    Alert("Order " , OrderTicket() , " Failed to close. Error:" , GetLastError() );
    Sleep(2000);
    }
    } // if(OrderTakeProfit
    } // if(OrderSymbol
    } // for i
    return(0);
    }
    // ---------------------------------------------------------------------------------- +
  • Combi13


    Losqu il y a perte la fonction Orderprofit doit rendre une valeur negative.

    Il doit falloir juste modifier la ligne

    If (orderprofit() >= mProfit )

    En.

    If (orderprofit()<= mProfit ). Et donner a mProfit une valeur negative

    Olivier
  • Phil968 — en réponse à Combi13 dans son message #54474

    Bonjour Olivier,

    Merci pour l'information. La modification est effectuée, et le résultat est parfait.
    Un grand merci.

    Philippe.
  • Combi13


    De rien, Philippe. Quand on peut aider
    Si ça te convient C'est parfait.

    Je crois que je vais utiliser aussi ce code petit code. Ca tombe bien.

    A+