Mon compte
Déjà membre ? S'identifier
Non inscrit ? S'inscrire
 
+ Répondre à la discussion
Affichage des résultats 1 à 6 sur 6
  1. #1
    Membre lvl 5 gollum est sur la route de la réputation...
    Date d'inscription
    April 2010
    Messages
    22
    Pouvoir de réputation
    4

    je cale... je cale...

    bonjour a tous, j'ai un problème pour créer une ligne de code pour un EA, je souhaiterais prendre position par exemple , a la hausse , lorsque le cours est au dessus de la M7 et arrive à 200 pips de la M7 et je n'ai aucune idée du code a utiliser....


    merci pour votre aide!!!!

  2. #2
    Membre lvl 5 gollum est sur la route de la réputation...
    Date d'inscription
    April 2010
    Messages
    22
    Pouvoir de réputation
    4

    pour preciser, lorsque par exemple la M14 monte, je rentre dés que le prix redescend 200 pips au dessus de la M14

    j'arrive a coder la M14 qui monte par contre le reste



    //+------------------------------------------------------------------+
    //| 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 = 1.0;
    extern int Slippage = 3;
    extern bool UseStopLoss = True;
    extern int StopLoss = 30;
    extern bool UseTakeProfit = True;
    extern int TakeProfit = 60;
    extern bool UseTrailingStop = True;
    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 = iMA(NULL, 0, 14, 0, MODE_SMA, PRICE_CLOSE, Current + 0);
    double Buy1_2 = iMA(NULL, 0, 14, 0, MODE_SMA, PRICE_CLOSE, Current + 1);

    double Sell1_1 = iMA(NULL, 0, 14, 0, MODE_SMA, PRICE_CLOSE, Current + 0);
    double Sell1_2 = iMA(NULL, 0, 14, 0, MODE_SMA, PRICE_CLOSE, 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) |
    //+------------------------------------------------------------------+



    //+------------------------------------------------------------------+
    //| 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) |
    //+------------------------------------------------------------------+



    //+------------------------------------------------------------------+
    //| 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) Order = SIGNAL_BUY;

    if (Sell1_1 < Sell1_2) Order = SIGNAL_SELL;


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

    //Buy
    if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
    if(!IsTrade) {
    //Check free margin
    if (AccountFreeMargin() < (1000 * 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() < (1000 * 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);
    }
    //+------------------------------------------------------------------+

  3. #3
    Membre lvl 5 atk-x est sur la route de la réputation...
    Date d'inscription
    July 2011
    Messages
    8
    Pouvoir de réputation
    3

    Citation Envoyé par gollum Voir le message
    pour preciser, lorsque par exemple la M14 monte, je rentre dés que le prix redescend 200 pips au dessus de la M14

    j'arrive a coder la M14 qui monte par contre le reste



    //+------------------------------------------------------------------+
    //| 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 = 1.0;
    extern int Slippage = 3;
    extern bool UseStopLoss = True;
    extern int StopLoss = 30;
    extern bool UseTakeProfit = True;
    extern int TakeProfit = 60;
    extern bool UseTrailingStop = True;
    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 = iMA(NULL, 0, 14, 0, MODE_SMA, PRICE_CLOSE, Current + 0);
    double Buy1_2 = iMA(NULL, 0, 14, 0, MODE_SMA, PRICE_CLOSE, Current + 1);

    double Sell1_1 = iMA(NULL, 0, 14, 0, MODE_SMA, PRICE_CLOSE, Current + 0);
    double Sell1_2 = iMA(NULL, 0, 14, 0, MODE_SMA, PRICE_CLOSE, 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) |
    //+------------------------------------------------------------------+



    //+------------------------------------------------------------------+
    //| 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) |
    //+------------------------------------------------------------------+



    //+------------------------------------------------------------------+
    //| 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) Order = SIGNAL_BUY;

    if (Sell1_1 < Sell1_2) Order = SIGNAL_SELL;


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

    //Buy
    if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
    if(!IsTrade) {
    //Check free margin
    if (AccountFreeMargin() < (1000 * 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() < (1000 * 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);
    }
    //+------------------------------------------------------------------+
    Salut , peux tu ré expliquer ton problème clairement parce que perso j'ai rien compris lol

    Tout se que je vois , s'est que tu prends position long quand la MA actuel est plus grande que la précédente et short quand c'est le contraire ...

    D'ailleurs je trouve ton code bien compliqué juste pour ça ...

    A+ Max

  4. #4
    Membre lvl 5 gollum est sur la route de la réputation...
    Date d'inscription
    April 2010
    Messages
    22
    Pouvoir de réputation
    4

    merci de t'interesser a mon cas
    par exemple lorsque la M7 se met a monter je souhaiterais rentrer en position lorsque le cours redescend a moins de 200 pips de la M7 ; je suis pas trés doué en programmation alors je fais mes EA avec expert advisor builder;
    peut etre un truc du style " Low>0,2 M7"

  5. #5
    Membre lvl 5 atk-x est sur la route de la réputation...
    Date d'inscription
    July 2011
    Messages
    8
    Pouvoir de réputation
    3

    Si j'ai bien compris , tu veux prendre position long quand le cours est 200 pips plus haut que la MA7 et short quand il est 200 pips plus bas ?

    Si c'est ça, il suffit de comparer la valeur de la MA7 avec le cours actuel ...

    Par exemple :

    double MA = iMA(NULL, 0, 7, 0, MODE_SMA, PRICE_CLOSE, Current + 0);

    if(Bid >= MA + (200 * Point))
    {
    LONG
    }
    else if(Bid <= MA - (200 * Point))
    {
    SHORT
    }

    A+ Max

  6. #6
    Membre lvl 5 gollum est sur la route de la réputation...
    Date d'inscription
    April 2010
    Messages
    22
    Pouvoir de réputation
    4

    c'est ca , grand merci pour ton aide!!!! reste a backtester tout ca....

Discussions similaires

  1. Qu'est ce qu'une Structure qui cale ?
    Par Edellion dans le forum Trading Divers
    Réponses: 0
    Dernier message: 03/06/2009, 02h38
  2. L'euro cale face au dollar apres le statu quo de la BCE
    Par AFP dans le forum Actualité Forex
    Réponses: 0
    Dernier message: 05/02/2009, 16h00
  3. Réponses: 0
    Dernier message: 14/07/2008, 16h12

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