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

Robot Moyennes Mobiles

  • deby

    Bonjour,
    Est ce que l'EA des Moyennes Mobiles de Forexagone etait disponible en robot car j'aimerais faire quelques test sur le long terme de cet indicateur.

    Merci
  • AliX

    Non désolé ... :/
  • tanger — en réponse à deby dans son message #59214

    deby, le 15/10/2012 dit :
    Bonjour, Est ce que l'EA des Moyennes Mobiles de Forexagone etait disponible en robot car j'aimerais faire quelques test sur le long terme de cet indicateur. Merci

    bonjour
    il suffit de chercher tu as déjà EA Moving Average dans mt4

    a mon avis tu devrais trader toi meme
  • stepaustras

    Moi je me l'était construit tout seul comme un grand lol mais les résultats sont pas si top que ça en back test il y a juste une différence c'est que pour les MA j'ai mis 5 et 20 au lieu de 5 et 10 tu pourra changer sans problème dans le code a deux endroits et j'utilise sinon le stochastique idem. J'ai aussi rajouté une tranche horaire qu'on peu régler pour l'ouverture de position.

    Code
    #include <stdlib.mqh> #include <WinUser32.mqh> // exported variables extern int HoursFrom26 = 0; extern int HoursTo26 = 24; extern double BuyLots8 = 0.1; extern int BuyStoploss8 = 0; extern int BuyTakeprofit8 = 0; extern double SellLots11 = 0.1; extern int SellStoploss11 = 0; extern int SellTakeprofit11 = 0; // local variables double PipValue=1; // this variable is here to support 5-digit brokers bool Terminated = false; string LF = "\n"; // use this in custom or utility blocks where you need line feeds int NDigits = 4; // used mostly for NormalizeDouble in Flex type blocks int ObjCount = 0; // count of all objects created on the chart, allows creation of objects with unique names int current = 0; int init() { NDigits = Digits; if (false) ObjectsDeleteAll(); // clear the chart Comment(""); // clear the chart } // Expert start int start() { if (Bars < 10) { Comment("Not enough bars"); return (0); } if (Terminated == true) { Comment("EA Terminated."); return (0); } OnEveryTick1(); } void OnEveryTick1() { if (true == false && true) PipValue = 10; if (true && (NDigits == 3 || NDigits == 5)) PipValue = 10; TechnicalAnalysis2(); TechnicalAnalysis4(); HoursFilter26(); } void TechnicalAnalysis2() { if (iMA(NULL, NULL,5,0,MODE_SMA,PRICE_CLOSE,1) > iMA(NULL, NULL,20,0,MODE_SMA,PRICE_CLOSE,1)) { IfOrderExists7(); } } void IfOrderExists7() { bool exists = false; for (int i=OrdersTotal()-1; i >= 0; i--) if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if (OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == 1) { exists = true; } } else { Print("OrderSelect() error - ", ErrorDescription(GetLastError())); } if (exists) { CloseOrder10(); } } void CloseOrder10() { int orderstotal = OrdersTotal(); int orders = 0; int ordticket[30][2]; for (int i = 0; i < orderstotal; i++) { OrderSelect(i, SELECT_BY_POS, MODE_TRADES); if (OrderType() != OP_SELL || OrderSymbol() != Symbol() || OrderMagicNumber() != 1) { continue; } ordticket[orders][0] = OrderOpenTime(); ordticket[orders][1] = OrderTicket(); orders++; } if (orders > 1) { ArrayResize(ordticket,orders); ArraySort(ordticket); } for (i = 0; i < orders; i++) { if (OrderSelect(ordticket[i][1], SELECT_BY_TICKET) == true) { bool ret = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 4, Red); if (ret == false) Print("OrderClose() error - ", ErrorDescription(GetLastError())); } } } void TechnicalAnalysis4() { if (iMA(NULL, NULL,5,0,MODE_SMA,PRICE_CLOSE,1) < iMA(NULL, NULL,20,0,MODE_SMA,PRICE_CLOSE,1)) { IfOrderExists9(); } } void IfOrderExists9() { bool exists = false; for (int i=OrdersTotal()-1; i >= 0; i--) if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if (OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == 1) { exists = true; } } else { Print("OrderSelect() error - ", ErrorDescription(GetLastError())); } if (exists) { CloseOrder12(); } } void CloseOrder12() { int orderstotal = OrdersTotal(); int orders = 0; int ordticket[30][2]; for (int i = 0; i < orderstotal; i++) { OrderSelect(i, SELECT_BY_POS, MODE_TRADES); if (OrderType() != OP_BUY || OrderSymbol() != Symbol() || OrderMagicNumber() != 1) { continue; } ordticket[orders][0] = OrderOpenTime(); ordticket[orders][1] = OrderTicket(); orders++; } if (orders > 1) { ArrayResize(ordticket,orders); ArraySort(ordticket); } for (i = 0; i < orders; i++) { if (OrderSelect(ordticket[i][1], SELECT_BY_TICKET) == true) { bool ret = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 4, Red); if (ret == false) Print("OrderClose() error - ", ErrorDescription(GetLastError())); } } } void HoursFilter26() { int datetime800 = TimeLocal(); int hour0 = TimeHour(datetime800); if ((HoursFrom26 < HoursTo26 && hour0 >= HoursFrom26 && hour0 < HoursTo26) || (HoursFrom26 > HoursTo26 && (hour0 < HoursTo26 || hour0 >= HoursFrom26))) { TechnicalAnalysis3x18(); TechnicalAnalysis3x3(); } } void TechnicalAnalysis3x18() { if ((iMA(NULL, NULL,5,0,MODE_SMA,PRICE_CLOSE,1) > iMA(NULL, NULL,20,0,MODE_SMA,PRICE_CLOSE,1)) && (iStochastic(NULL, NULL,14,3,3,MODE_SMA,1,MODE_SIGNAL,0) > 50) && (iRSI(NULL, NULL,14,PRICE_CLOSE,0) > 50)) { IfOrderDoesNotExist6(); } } void IfOrderDoesNotExist6() { bool exists = false; for (int i=OrdersTotal()-1; i >= 0; i--) if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if (OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == 1) { exists = true; } } else { Print("OrderSelect() error - ", ErrorDescription(GetLastError())); } if (exists == false) { BuyOrder8(); } } void BuyOrder8() { double SL = Ask - BuyStoploss8*PipValue*Point; if (BuyStoploss8 == 0) SL = 0; double TP = Ask + BuyTakeprofit8*PipValue*Point; if (BuyTakeprofit8 == 0) TP = 0; int ticket = -1; if (true) ticket = OrderSend(Symbol(), OP_BUY, BuyLots8, Ask, 3, 0, 0, "My Expert", 1, 0, Green); else ticket = OrderSend(Symbol(), OP_BUY, BuyLots8, Ask, 3, SL, TP, "My Expert", 1, 0, Green); if (ticket > -1) { if (true) { OrderSelect(ticket, SELECT_BY_TICKET); bool ret = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0, Green); if (ret == false) Print("OrderModify() error - ", ErrorDescription(GetLastError())); } } else { Print("OrderSend() error - ", ErrorDescription(GetLastError())); } } void TechnicalAnalysis3x3() { if ((iMA(NULL, NULL,5,0,MODE_SMA,PRICE_CLOSE,1) < iMA(NULL, NULL,20,0,MODE_SMA,PRICE_CLOSE,1)) && (iStochastic(NULL, NULL,14,3,3,MODE_SMA,1,MODE_SIGNAL,0) < 50) && (iRSI(NULL, NULL,14,PRICE_CLOSE,0) < 50)) { IfOrderDoesNotExist5(); } } void IfOrderDoesNotExist5() { bool exists = false; for (int i=OrdersTotal()-1; i >= 0; i--) if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if (OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == 1) { exists = true; } } else { Print("OrderSelect() error - ", ErrorDescription(GetLastError())); } if (exists == false) { SellOrder11(); } } void SellOrder11() { double SL = Bid + SellStoploss11*PipValue*Point; if (SellStoploss11 == 0) SL = 0; double TP = Bid - SellTakeprofit11*PipValue*Point; if (SellTakeprofit11 == 0) TP = 0; int ticket = -1; if (true) ticket = OrderSend(Symbol(), OP_SELL, SellLots11, Bid, 3, 0, 0, "My Expert", 1, 0, Red); else ticket = OrderSend(Symbol(), OP_SELL, SellLots11, Bid, 3, SL, TP, "My Expert", 1, 0, Red); if (ticket > -1) { if (true) { OrderSelect(ticket, SELECT_BY_TICKET); bool ret = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0, Red); if (ret == false) Print("OrderModify() error - ", ErrorDescription(GetLastError())); } } else { Print("OrderSend() error - ", ErrorDescription(GetLastError())); } } int deinit() { if (false) ObjectsDeleteAll(); }
  • lefeuvr3

    Parametres d'un backtest du 16.05.2012 a ce jour en UT 15 sur le CAC
    40
    On joue sur la periode des moyennes mobiles et sur le fait qu'elles soient simples ou exponentielles ou smotthed ou Weighted
    Code
    //+------------------------------------------------------------------+ //| This MQL is generated by Expert Advisor Builder | //| http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/ | //| | //| 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 = False; extern double Lots = 1.0; 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; extern int Period1 = 141; extern int Period2 = 440; extern int Method1 = 1; extern int Method2 = 2; extern int max_trade = 1; 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, Period1, 0, Method1, PRICE_CLOSE, Current + 0); double Buy1_2 = iMA(NULL, 0, Period2, 0, Method2, PRICE_CLOSE, Current + 0); double Buy2_1 = iMA(NULL, 0, Period1, 0, Method1, PRICE_CLOSE, Current + 1); double Buy2_2 = iMA(NULL, 0, Period2, 0, Method2, PRICE_CLOSE, Current + 1); double Sell1_1 = iMA(NULL, 0, Period1, 0, Method1, PRICE_CLOSE, Current + 0); double Sell1_2 = iMA(NULL, 0, Period2, 0, Method2, PRICE_CLOSE, Current + 0); double Sell2_1 = iMA(NULL, 0, Period1, 0, Method1, PRICE_CLOSE, Current + 1); double Sell2_2 = iMA(NULL, 0, Period2, 0, Method2, PRICE_CLOSE, Current + 1); double CloseBuy1_1 = iMA(NULL, 0, Period1, 0, Method1, PRICE_CLOSE, Current + 0); double CloseBuy1_2 = iMA(NULL, 0, Period2, 0, Method2, PRICE_CLOSE, Current + 0); double CloseBuy2_1 = iMA(NULL, 0, Period1, 0, Method1, PRICE_CLOSE, Current + 1); double CloseBuy2_2 = iMA(NULL, 0, Period2, 0, Method2, PRICE_CLOSE, Current + 1); double CloseSell1_1 = iMA(NULL, 0, Period1, 0, Method1, PRICE_CLOSE, Current + 0); double CloseSell1_2 = iMA(NULL, 0, Period2, 0, Method2, PRICE_CLOSE, Current + 0); double CloseSell2_1 = iMA(NULL, 0, Period1, 0, Method1, PRICE_CLOSE, Current + 1); double CloseSell2_2 = iMA(NULL, 0, Period2, 0, Method2, PRICE_CLOSE, Current + 1); //+------------------------------------------------------------------+ //| Variable End | //+------------------------------------------------------------------+ //Check position bool IsTrade = False; for (int i = max_trade-1; 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() < (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); } //+------------------------------------------------------------------+
  • lefeuvr3

    celui ci avec 4 moyennes mobiles qui se croisent

    sur la Même ut sutr le CA et sur la même periode
    Code
    //+------------------------------------------------------------------+ //| This MQL is generated by Expert Advisor Builder | //| http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/ | //| | //| 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 = False; extern double Lots = 1.0; 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; extern int PER1 = 128; extern int PER2 = 138; extern int PER3 = 40; extern int PER4 = 109; extern int Method1 = 2; extern int Method2 = 2; extern int Method3 = 0; extern int Method4 = 0; extern int Dec1 = 0; extern int Dec2 = 0; extern int Dec3 = 0; extern int Dec4 = 0; 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, PER1, Dec1, Method1, PRICE_CLOSE, Current + 0); double Buy1_2 = iMA(NULL, 0, PER2, Dec2, Method2, PRICE_CLOSE, Current + 0); double Buy2_1 = iMA(NULL, 0, PER1, Dec1, Method1, PRICE_CLOSE, Current + 1); double Buy2_2 = iMA(NULL, 0, PER2, Dec2, Method2, PRICE_CLOSE, Current + 1); double Sell1_1 = iMA(NULL, 0, PER3, Dec3, Method3, PRICE_CLOSE, Current + 0); double Sell1_2 = iMA(NULL, 0, PER4, Dec4, Method4, PRICE_CLOSE, Current + 0); double Sell2_1 = iMA(NULL, 0, PER3, Dec3, Method3, PRICE_CLOSE, Current + 1); double Sell2_2 = iMA(NULL, 0, PER4, Dec4, Method4, PRICE_CLOSE, Current + 1); double CloseBuy1_1 = iMA(NULL, 0, PER1, Dec1, Method1, PRICE_CLOSE, Current + 0); double CloseBuy1_2 = iMA(NULL, 0, PER2, Dec2, Method2, PRICE_CLOSE, Current + 0); double CloseBuy2_1 = iMA(NULL, 0, PER1, Dec1, Method1, PRICE_CLOSE, Current + 1); double CloseBuy2_2 = iMA(NULL, 0, PER2, Dec2, Method2, PRICE_CLOSE, Current + 1); double CloseSell1_1 = iMA(NULL, 0, PER3, Dec3, Method3, PRICE_CLOSE, Current + 0); double CloseSell1_2 = iMA(NULL, 0, PER4, Dec4, Method4, PRICE_CLOSE, Current + 0); double CloseSell2_1 = iMA(NULL, 0, PER3, Dec3, Method3, PRICE_CLOSE, Current + 1); double CloseSell2_2 = iMA(NULL, 0, PER4, Dec4, Method4, 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) | //+------------------------------------------------------------------+ 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() < (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); } //+------------------------------------------------------------------+
  • lefeuvr3

    avec 8 moyennes mobiles cela est plus beau mais se complique
    Code
    //+------------------------------------------------------------------+ //| This MQL is generated by Expert Advisor Builder | //| http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/ | //| | //| 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 = False; extern int StopLoss = 30; extern bool UseTakeProfit = False; extern int TakeProfit = 60; extern bool UseTrailingStop = False; extern int TrailingStop = 30; extern int PRICE = 0 ; extern int MODE1 = 0; extern int MODE2 = 0; extern int MODE3 = 0; extern int MODE4 = 0; extern int PERIODE1 = 274; extern int DecalageMODE1 = 0; extern int PERIODE2 =250; extern int DecalageMODE2 = 0; extern int PERIODE3 =498; extern int DecalageMODE3 = 0; extern int PERIODE4 = 392; extern int DecalageMODE4 = 0; extern int PERIODE5 = 268; extern int DecalageMODE5 = 0; extern int PERIODE6 = 148; extern int DecalageMODE6 = 0; extern int PERIODE7 =284; extern int DecalageMODE7 = 0; extern int PERIODE8 = 122; extern int DecalageMODE8 = 0; extern int Shift0 = 0; extern int Shift1 = 1; 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, PERIODE1, DecalageMODE1, MODE1, PRICE, Current + Shift1); double Buy1_2 = iMA(NULL, 0, PERIODE2, DecalageMODE2, MODE2, PRICE, Current + Shift1); double Buy2_1 = iMA(NULL, 0, PERIODE1, DecalageMODE1, MODE1, PRICE, Current + Shift0); double Buy2_2 = iMA(NULL, 0, PERIODE2, DecalageMODE2, MODE2, PRICE, Current + Shift0); double Sell1_1 = iMA(NULL, 0, PERIODE3, DecalageMODE5, MODE1, PRICE, Current + Shift1); double Sell1_2 = iMA(NULL, 0, PERIODE4, DecalageMODE6, MODE2, PRICE, Current + Shift1); double Sell2_1 = iMA(NULL, 0, PERIODE3, DecalageMODE5, MODE1, PRICE, Current + Shift0); double Sell2_2 = iMA(NULL, 0, PERIODE4, DecalageMODE6, MODE2, PRICE, Current + Shift0); double CloseBuy1_1 = iMA(NULL, 0, PERIODE5, DecalageMODE3, MODE1, PRICE, Current + Shift1); double CloseBuy1_2 = iMA(NULL, 0, PERIODE6, DecalageMODE4, MODE2, PRICE, Current + Shift1); double CloseBuy2_1 = iMA(NULL, 0, PERIODE5, DecalageMODE3, MODE1, PRICE, Current + Shift0); double CloseBuy2_2 = iMA(NULL, 0, PERIODE6, DecalageMODE4, MODE2, PRICE, Current + Shift0); double CloseSell1_1 = iMA(NULL, 0, PERIODE7, DecalageMODE7, MODE1, PRICE, Current + Shift1); double CloseSell1_2 = iMA(NULL, 0, PERIODE8, DecalageMODE8, MODE2, PRICE, Current + Shift1); double CloseSell2_1 = iMA(NULL, 0, PERIODE7, DecalageMODE7, MODE1, PRICE, Current + Shift0); double CloseSell2_2 = iMA(NULL, 0, PERIODE8, DecalageMODE8, MODE2, PRICE, Current + Shift0); //+------------------------------------------------------------------+ //| 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() < (1 * 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); } //+------------------------------------------------------------------+
  • lefeuvr3

    Petite variante sur le style des 8 moyennes mobiles tjs sur le CAC 40 en UT 15 du 16.05.2012 a ce jour
    Code
    //+------------------------------------------------------------------+ //| This MQL is generated by Expert Advisor Builder | //| http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/ | //| | //| 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 = False; extern double Lots = 1.0; 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; extern int PLT1 = 650; extern int PLT2 = 400; extern int PMT1 = 720; extern int PMT2 = 470 ; extern int PCT1 = 790; extern int PCT2 = 250; extern int PTCT1 = 750; extern int PTCT2 = 220; extern int SHIFT0 =0; extern int SHIFT1 =1; 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, PLT1, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT1); double Buy1_2 = iMA(NULL, 0, PLT2, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT1); double Buy2_1 = iMA(NULL, 0, PLT1, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT0); double Buy2_2 = iMA(NULL, 0, PLT2, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT0); double Buy3_1 = iMA(NULL, 0, PMT1, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT1); double Buy3_2 = iMA(NULL, 0, PMT2, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT1); double Buy4_1 = iMA(NULL, 0, PMT1, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT0); double Buy4_2 = iMA(NULL, 0, PMT2, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT0); double Buy5_1 = iMA(NULL, 0, PCT1, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT1); double Buy5_2 = iMA(NULL, 0, PCT2, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT1); double Buy6_1 = iMA(NULL, 0, PCT1, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT0); double Buy6_2 = iMA(NULL, 0, PCT2, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT0); double Buy7_1 = iMA(NULL, 0, PTCT1, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT1); double Buy7_2 = iMA(NULL, 0, PTCT2, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT1); double Buy8_1 = iMA(NULL, 0, PTCT1, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT0); double Buy8_2 = iMA(NULL, 0, PTCT2, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT0); double Sell1_1 = iMA(NULL, 0, PLT1, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT1); double Sell1_2 = iMA(NULL, 0, PLT2, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT1); double Sell2_1 = iMA(NULL, 0, PLT1, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT0); double Sell2_2 = iMA(NULL, 0, PLT2, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT0); double Sell3_1 = iMA(NULL, 0, PMT1, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT1); double Sell3_2 = iMA(NULL, 0, PMT2, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT1); double Sell4_1 = iMA(NULL, 0, PMT1, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT0); double Sell4_2 = iMA(NULL, 0, PMT2, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT0); double Sell5_1 = iMA(NULL, 0, PCT1, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT1); double Sell5_2 = iMA(NULL, 0, PCT2, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT1); double Sell6_1 = iMA(NULL, 0, PCT1, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT0); double Sell6_2 = iMA(NULL, 0, PCT2, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT0); double Sell7_1 = iMA(NULL, 0, PTCT1, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT1); double Sell7_2 = iMA(NULL, 0, PTCT2, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT1); double Sell8_1 = iMA(NULL, 0, PTCT1, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT0); double Sell8_2 = iMA(NULL, 0, PTCT2, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT0); double CloseBuy1_1 = iMA(NULL, 0, PLT1, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT1); double CloseBuy1_2 = iMA(NULL, 0, PLT2, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT1); double CloseBuy2_1 = iMA(NULL, 0, PLT1, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT0); double CloseBuy2_2 = iMA(NULL, 0, PLT2, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT0); double CloseBuy3_1 = iMA(NULL, 0, PMT1, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT1); double CloseBuy3_2 = iMA(NULL, 0, PMT2, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT1); double CloseBuy4_1 = iMA(NULL, 0, PMT1, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT0); double CloseBuy4_2 = iMA(NULL, 0, PMT2, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT0); double CloseBuy5_1 = iMA(NULL, 0, PCT1, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT1); double CloseBuy5_2 = iMA(NULL, 0, PCT2, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT1); double CloseBuy6_1 = iMA(NULL, 0, PCT1, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT0); double CloseBuy6_2 = iMA(NULL, 0, PCT2, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT0); double CloseBuy7_1 = iMA(NULL, 0, PTCT1, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT1); double CloseBuy7_2 = iMA(NULL, 0, PTCT2, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT1); double CloseBuy8_1 = iMA(NULL, 0, PTCT1, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT0); double CloseBuy8_2 = iMA(NULL, 0, PTCT2, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT0); double CloseSell1_1 = iMA(NULL, 0, PLT1, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT1); double CloseSell1_2 = iMA(NULL, 0, PLT2, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT1); double CloseSell2_1 = iMA(NULL, 0, PLT1, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT0); double CloseSell2_2 = iMA(NULL, 0, PLT2, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT0); double CloseSell3_1 = iMA(NULL, 0, PMT1, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT1); double CloseSell3_2 = iMA(NULL, 0, PMT2, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT1); double CloseSell4_1 = iMA(NULL, 0, PMT1, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT0); double CloseSell4_2 = iMA(NULL, 0, PMT2, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT0); double CloseSell5_1 = iMA(NULL, 0, PCT1, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT1); double CloseSell5_2 = iMA(NULL, 0, PCT2, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT1); double CloseSell6_1 = iMA(NULL, 0, PCT1, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT0); double CloseSell6_2 = iMA(NULL, 0, PCT2, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT0); double CloseSell7_1 = iMA(NULL, 0, PTCT1, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT1); double CloseSell7_2 = iMA(NULL, 0, PTCT2, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT1); double CloseSell8_1 = iMA(NULL, 0, PTCT1, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT0); double CloseSell8_2 = iMA(NULL, 0, PTCT2, 0, MODE_SMA, PRICE_CLOSE, Current + SHIFT0); //+------------------------------------------------------------------+ //| 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 || CloseBuy3_1 > CloseBuy3_2 && CloseBuy4_1 < CloseBuy4_2 || CloseBuy5_1 > CloseBuy5_2 && CloseBuy6_1 < CloseBuy6_2 || CloseBuy7_1 > CloseBuy7_2 && CloseBuy8_1 < CloseBuy8_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 || CloseSell3_1 < CloseSell3_2 && CloseSell4_1 > CloseSell4_2 || CloseSell5_1 < CloseSell5_2 && CloseSell6_1 > CloseSell6_2 || CloseSell7_1 < CloseSell7_2 && CloseSell8_1 > CloseSell8_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 || Buy3_1 < Buy3_2 && Buy4_1 > Buy4_2 || Buy5_1 < Buy5_2 && Buy6_1 > Buy6_2 || Buy7_1 < Buy7_2 && Buy8_1 > Buy8_2) Order = SIGNAL_BUY; if (Sell1_1 > Sell1_2 && Sell2_1 < Sell2_2 || Sell3_1 > Sell3_2 && Sell4_1 < Sell4_2 || Sell5_1 > Sell5_2 && Sell6_1 < Sell6_2 || Sell7_1 > Sell7_2 && Sell8_1 < Sell8_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); } //+------------------------------------------------------------------+
  • Rengou

    Bonjour. s'il vous plait aidez moi. jai besoin d'un code sourse pour un EA du 2 moyennes mobile. EMA9 et EMA25. sans stop loss et sans take profit. en bref, BUY if EMA9 > EMA25
    CLOSE if EMA9 = EMA25

    SELL if EMA9 < EMA25
    CLOSE if EMA9 = EMA25

    Jai essayé de coder mais au moment de compiler jai eu plein de message d'erreur. je suis nul en programmation. aidez moi s'il vous plait. merci. TIMEFRAME = CURRENT
  • lefeuvr3

    J'ai code au mieux de mes capacités cet EA....je ne l'ai pas back teste ….juste code d'après le cahier des charges .
    Si tu veux le refaire je te mets un lien qui permet un codage facile accessible a tous meme si on n'a aucune connaissance sur le codage.
    http://www.forexeadvisor.com/expert_generator.aspx

    Code
    //+------------------------------------------------------------------+ //| RENGOU MM.mq4 | //| QPG | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "QPG" #property link "https://www.mql5.com" #property version "1.00" #define SIGNAL_NONE 0 #define SIGNAL_BUY 1 #define SIGNAL_SELL 2 #define SIGNAL_CLOSEBUY 3 #define SIGNAL_CLOSESELL 4 extern int MagicNumber = 16102018; extern bool SignalMail = False; extern bool EachTickMode = False; extern double Lots = 0.01; extern int Slippage = 3; extern bool UseStopLoss = False; extern int StopLoss = 50; extern bool UseTakeProfit = False; extern int TakeProfit = 50; extern bool UseTrailingStop = False; extern int TrailingStop = 50; extern int Period1 = 9; extern int Period2 = 25; extern int Method1 = 1; extern int Method2 = 1; extern int max_trade = 1; 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, Period1, 0, Method1, PRICE_CLOSE, Current + 0); double Buy1_2 = iMA(NULL, 0, Period2, 0, Method2, PRICE_CLOSE, Current + 0); double Buy2_1 = iMA(NULL, 0, Period1, 0, Method1, PRICE_CLOSE, Current + 1); double Buy2_2 = iMA(NULL, 0, Period2, 0, Method2, PRICE_CLOSE, Current + 1); double Sell1_1 = iMA(NULL, 0, Period1, 0, Method1, PRICE_CLOSE, Current + 0); double Sell1_2 = iMA(NULL, 0, Period2, 0, Method2, PRICE_CLOSE, Current + 0); double Sell2_1 = iMA(NULL, 0, Period1, 0, Method1, PRICE_CLOSE, Current + 1); double Sell2_2 = iMA(NULL, 0, Period2, 0, Method2, PRICE_CLOSE, Current + 1); double CloseBuy1_1 = iMA(NULL, 0, Period1, 0, Method1, PRICE_CLOSE, Current + 0); double CloseBuy1_2 = iMA(NULL, 0, Period2, 0, Method2, PRICE_CLOSE, Current + 0); double CloseBuy2_1 = iMA(NULL, 0, Period1, 0, Method1, PRICE_CLOSE, Current + 1); double CloseBuy2_2 = iMA(NULL, 0, Period2, 0, Method2, PRICE_CLOSE, Current + 1); double CloseSell1_1 = iMA(NULL, 0, Period1, 0, Method1, PRICE_CLOSE, Current + 0); double CloseSell1_2 = iMA(NULL, 0, Period2, 0, Method2, PRICE_CLOSE, Current + 0); double CloseSell2_1 = iMA(NULL, 0, Period1, 0, Method1, PRICE_CLOSE, Current + 1); double CloseSell2_2 = iMA(NULL, 0, Period2, 0, Method2, PRICE_CLOSE, Current + 1); //+------------------------------------------------------------------+ //| Variable End | //+------------------------------------------------------------------+ //Check position bool IsTrade = False; for (int i = max_trade-1; i < Total; i ++) { if(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)))) { if(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) { if(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)))) { if(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() < (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); } //+------------------------------------------------------------------+
  • lefeuvr3

    Si tu aimes les moyennes mobiles
    J'en ai code un assez sympa qui marche assez bien sur l'EURUSD en 1 mn avec des lots qui s'ajustent au capital du moment
    Bonne journée
    Gerard
    Code
    //+------------------------------------------------------------------+ //| QPG MM OPEN CLOSE MTF ADX RSI.mq4 avec AMM.mq4 | //| EURUSD 1 MN /1HEURE VERSION 2 QPG | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "QPG" #property link "https://www.mql5.com" #property version "1.00" //#property strict //+------------------------------------------------------------------+ // 1 MINUTE EURUSD //+------------------------------------------------------------------+ extern int MagicNumber=02102018; double Lots ; double lot; extern double LotFactor=400; //lotsize factor extern double StopLoss=90; extern double TakeProfit=0; extern int TrailingStop=43; extern int Slippage=3; extern string Per="periode MM"; extern int PEROM1=3; extern int PERCM1=3; extern int PEROM15=5; extern int PERCM15=1; extern int PEROH1=1; extern int PERCH1=4; extern string mod="Mode MM"; //MODE_SMA=0 //Simple Moving Average //Equal weight is given to each price over the calculation period. Bias: Smooth (anti-noise) //MODE_EMA=1 Exponential Moving Average // More weight is given to recent prices in attempt to reduce lag. Bias: Speed (anti-lag) //MODE_SMMA=2 // Smoothed Moving Average // Similar to a SMA; however, rather than subtracting the oldest value, the previous smoothed average value is subtracted. Bias: Smooth (anti-noise) //MODE_LWMA=3 //Linear Weighted Moving Average //Designed to put more weight on recent data and less weight on past data. Bias: Speed (anti-lag) extern int MODEMA=1; extern int adxperiod =27; extern int adxthreshold =22; extern int v0=5; extern int v1=0; extern int shift0pen0 =1; extern int shift0pen1=0; extern int shiftClose0=0; extern int shiftClose1=1; double Timeframe=0; //+------------------------------------------------------------------+ // expert start function //+------------------------------------------------------------------+ int start() { double MyPoint=Point; if(Digits==3 || Digits==5) MyPoint=Point*10; double TheStopLoss=0; double TheTakeProfit=0; if( TotalOrdersCount()==0 ) { int result=0; // Here is your open buy rule if(iMA(NULL,PERIOD_M1,PEROM1,0,MODEMA,PRICE_OPEN,shift0pen0)>iMA(NULL,PERIOD_M1,PERCM1,0,MODEMA,PRICE_CLOSE,shiftClose0)&&iMA(NULL,PERIOD_M1,PEROM1,1,MODEMA,PRICE_OPEN,shift0pen1)<iMA(NULL,PERIOD_M1,PERCM1,1,MODEMA,PRICE_CLOSE,shiftClose1)&& iMA(NULL,PERIOD_M15,PEROM15,0,MODEMA,PRICE_OPEN,shift0pen0)>iMA(NULL,PERIOD_M15,PERCM15,0,MODEMA,PRICE_CLOSE,shiftClose0)&&iMA(NULL,PERIOD_M15,PEROM15,1,MODEMA,PRICE_OPEN,shift0pen1)<iMA(NULL,PERIOD_M15,PERCM15,1,MODEMA,PRICE_CLOSE,shiftClose1)&& iMA(NULL,PERIOD_H1,PEROH1,0,MODEMA,PRICE_OPEN,shift0pen0)>iMA(NULL,PERIOD_H1,PERCH1,0,MODEMA,PRICE_CLOSE,shiftClose0)&&iMA(NULL,PERIOD_H1,PEROH1,1,MODEMA,PRICE_OPEN,shift0pen1)<iMA(NULL,PERIOD_H1,PERCH1,1,MODEMA,PRICE_CLOSE,shiftClose1) // Here is your open buy rule &&(iADX(Symbol(),Timeframe,adxperiod,PRICE_CLOSE,MODE_MAIN,0)>adxthreshold )&&(Volume[v1]> Volume[v0]) // Here is your open buy rule ) { result=OrderSend(Symbol(),OP_BUY,AdvancedMM(),Ask,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",MagicNumber,0,Blue); if(result>0) { TheStopLoss=0; TheTakeProfit=0; if(TakeProfit>0) TheTakeProfit=Ask+TakeProfit*MyPoint; if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint; if(OrderSelect(result,SELECT_BY_TICKET)==true) bool modif1= OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green); } return(0); } // Here is your open Sell rule if(iMA(NULL,PERIOD_M1,PEROM1,0,MODEMA,PRICE_OPEN,shift0pen0)<iMA(NULL,PERIOD_M1,PERCM1,0,MODEMA,PRICE_CLOSE,shiftClose0)&&iMA(NULL,PERIOD_M1,PEROM1,1,MODEMA,PRICE_OPEN,shift0pen1)>iMA(NULL,PERIOD_M1,PERCM1,1,MODEMA,PRICE_CLOSE,shiftClose1)&& // Here is your open Sell rule iMA(NULL,PERIOD_M15,PEROM15,0,MODEMA,PRICE_OPEN,shift0pen0)<iMA(NULL,PERIOD_M15,PERCM15,0,MODEMA,PRICE_CLOSE,shiftClose0)&&iMA(NULL,PERIOD_M15,PEROM15,1,MODEMA,PRICE_OPEN,shift0pen1)>iMA(NULL,PERIOD_M15,PERCM15,1,MODEMA,PRICE_CLOSE,shiftClose1) &&iMA(NULL,PERIOD_H1,PEROH1,0,MODEMA,PRICE_OPEN,shift0pen0)<iMA(NULL,PERIOD_H1,PERCH1,0,MODEMA,PRICE_CLOSE,shiftClose0)&&iMA(NULL,PERIOD_H1,PEROH1,1,MODEMA,PRICE_OPEN,shift0pen1)>iMA(NULL,PERIOD_H1,PERCH1,1,MODEMA,PRICE_CLOSE,shiftClose1) &&(iADX(Symbol(),Timeframe,adxperiod,PRICE_CLOSE,MODE_MAIN,0)>adxthreshold )&&(Volume[v1]> Volume[v0]) ) { result=OrderSend(Symbol(),OP_SELL,AdvancedMM(),Bid,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",MagicNumber,0,Red); if(result>0) { TheStopLoss=0; TheTakeProfit=0; if(TakeProfit>0) TheTakeProfit=Bid-TakeProfit*MyPoint; if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint; if (OrderSelect(result,SELECT_BY_TICKET)==true) bool modif2= OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green); } return(0); } } for(int cnt=0;cnt<OrdersTotal();cnt++) { if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)==true) if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber ) { if(OrderType()==OP_BUY) { if(iMA(NULL,PERIOD_M1,PEROM1,0,MODEMA,PRICE_OPEN,shift0pen0)<iMA(NULL,PERIOD_M1,PERCM1,0,MODEMA,PRICE_CLOSE,shiftClose0)&&iMA(NULL,PERIOD_M1,PEROM1,1,MODEMA,PRICE_OPEN,shift0pen1)>iMA(NULL,PERIOD_M1,PERCM1,1,MODEMA,PRICE_CLOSE,shiftClose1)&& //here is your close buy rule iMA(NULL,PERIOD_M15,PEROM15,0,MODEMA,PRICE_OPEN,shift0pen0)<iMA(NULL,PERIOD_M15,PERCM15,0,MODEMA,PRICE_CLOSE,shiftClose0)&&iMA(NULL,PERIOD_M15,PEROM15,1,MODEMA,PRICE_OPEN,shift0pen1)>iMA(NULL,PERIOD_M15,PERCM15,1,MODEMA,PRICE_CLOSE,shiftClose1) &&iMA(NULL,PERIOD_H1,PEROH1,0,MODEMA,PRICE_OPEN,shift0pen0)<iMA(NULL,PERIOD_H1,PERCH1,0,MODEMA,PRICE_CLOSE,shiftClose0)&&iMA(NULL,PERIOD_H1,PEROH1,1,MODEMA,PRICE_OPEN,shift0pen1)>iMA(NULL,PERIOD_H1,PERCH1,1,MODEMA,PRICE_CLOSE,shiftClose1) //here is your close buy rule &&(iADX(Symbol(),Timeframe,adxperiod,PRICE_CLOSE,MODE_MAIN,0)>adxthreshold ) //here is your close buy rule ) { bool modif5= OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red); } if(TrailingStop>0) { if(Bid-OrderOpenPrice()>MyPoint*TrailingStop) { if(OrderStopLoss()<Bid-MyPoint*TrailingStop) { bool modif3= OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*MyPoint,OrderTakeProfit(),0,Green); return(0); } } } } else { if(iMA(NULL,PERIOD_M1,PEROM1,0,MODEMA,PRICE_OPEN,shift0pen0)>iMA(NULL,PERIOD_M1,PERCM1,0,MODEMA,PRICE_CLOSE,shiftClose0)&&iMA(NULL,PERIOD_M1,PEROM1,1,MODEMA,PRICE_OPEN,shift0pen1)<iMA(NULL,PERIOD_M1,PERCM1,1,MODEMA,PRICE_CLOSE,shiftClose1)&& // here is your close sell rule iMA(NULL,PERIOD_M15,PEROM15,0,MODEMA,PRICE_OPEN,shift0pen0)>iMA(NULL,PERIOD_M15,PERCM15,0,MODEMA,PRICE_CLOSE,shiftClose0)&&iMA(NULL,PERIOD_M15,PEROM15,1,MODEMA,PRICE_OPEN,shift0pen1)<iMA(NULL,PERIOD_M15,PERCM15,1,MODEMA,PRICE_CLOSE,shiftClose1) &&iMA(NULL,PERIOD_H1,PEROH1,0,MODEMA,PRICE_OPEN,shift0pen0)>iMA(NULL,PERIOD_H1,PERCH1,0,MODEMA,PRICE_CLOSE,shiftClose0)&&iMA(NULL,PERIOD_H1,PEROH1,1,MODEMA,PRICE_OPEN,shift0pen1)<iMA(NULL,PERIOD_H1,PERCH1,1,MODEMA,PRICE_CLOSE,shiftClose1) // here is your close sell rule &&(iADX(Symbol(),Timeframe,adxperiod,PRICE_CLOSE,MODE_MAIN,0)>adxthreshold ) // here is your close sell rule ) { bool modif6= OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red); } if(TrailingStop>0) { if((OrderOpenPrice()-Ask)>(MyPoint*TrailingStop)) { if((OrderStopLoss()>(Ask+MyPoint*TrailingStop)) || (OrderStopLoss()==0)) { bool modif4= OrderModify(OrderTicket(),OrderOpenPrice(),Ask+MyPoint*TrailingStop,OrderTakeProfit(),0,Red); return(0); } } } } } } return(0); } int TotalOrdersCount() { int result=0; for(int i=0;i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS ,MODE_TRADES)==true) if (OrderMagicNumber()==MagicNumber) result++; } return (result); } double AdvancedMM() { int i; double AdvancedMMLots = 0; bool profit1=false; int SystemHistoryOrders=0; for( i=0;i<OrdersHistoryTotal();i++) { if(OrderSelect(i,SELECT_BY_POS ,MODE_HISTORY)==true) if (OrderMagicNumber()==MagicNumber) SystemHistoryOrders++; } bool profit2=false; int LO=0; if(SystemHistoryOrders<2) return(NR(Lot_Volume())); for( i=OrdersHistoryTotal()-1;i>=0;i--) { if(OrderSelect(i,SELECT_BY_POS ,MODE_HISTORY)) if (OrderMagicNumber()==MagicNumber) { if(OrderProfit()>=0 && profit1) return(NR(Lot_Volume())); if( LO==0) { if(OrderProfit()>=0) profit1=true; if(OrderProfit()<0) return(OrderLots()); LO=1; } if(OrderProfit()>=0 && profit2) return(AdvancedMMLots); if(OrderProfit()>=0) profit2=true; if(OrderProfit()<0 ) { profit1=false; profit2=false; AdvancedMMLots+=OrderLots(); } } } return(AdvancedMMLots); } //+------------------------------------------------------------------+ //Calculates Lot Size based on balance and factor //+------------------------------------------------------------------+ double NR(double thelot) { double maxlots=MarketInfo(Symbol(),MODE_MAXLOT), minilot=MarketInfo(Symbol(),MODE_MINLOT), lstep=MarketInfo(Symbol(),MODE_LOTSTEP); double lots=lstep*NormalizeDouble(thelot/lstep,0); lots=MathMax(MathMin(maxlots,lots),minilot); return (lots); } //+------------------------------------------------------------------+ double Lot_Volume() { lot=AccountBalance() * 0.01 /LotFactor ; return(lot); }
  • Rengou

    bonjour leufeuvr3. merci . jai utilisé ton lien pour creer mes ea. mais a chaque fois que je compile, ca m'affiche une liste d'erreur
  • lefeuvr3

    En fait ceux sont des warnings qui n'empêchent pas l'EA de fonctionner mais si tu veux je peux te les corriger
    Mets ton programme ,en corrigeant les erreurs et en comparant les 2 programmes tu verra comment proceder .

    Modifié le 2018-10-17 16:17:36 par lefeuvr3
  • lefeuvr3

    Je mets un exemple

    Code
    remplacer OrderSelect(result,SELECT_BY_TICKET); par if(OrderSelect(result, SELECT_BY_TICKET)) ou if(OrderSelect(result,SELECT_BY_TICKET)==true)