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

EA Macross Countertrend

  • Jerome

    Bonjour, je ne crois pas que le sujet corresponde aux critères mais je tente ^^

    J'ai trouvé sur un forum américain un ea qui me semble très prometteur achetant ou vendant au croisement des moyennes mobiles expo mais a contre tendance bien que cette dernière donnée soit paramétrable false/true.
    J'ai passé deux jours a lire le thread ...alors que mon anglais ressemble au berrichon d'un chinois enfin, victoire, j'ai réussi a l'installer !!!

    Je vous file mes paramètres :
    TP 160 TS : 20 SL : 70
    SL : False ( si je met true alors ça ne marche pas ..pas d'ordre envoyé et erreur 130 dans le journal)
    Short EMA : 10 long EMA : 80
    immediate trade : true
    reversarl : true
    Lot : 1
    MM : false
    account micro : false
    risk : 15 mais a l'origine c'était 10
    show setting : true

    Mon problème est le SL que je ne peux utiliser car il bug ...
    J'ai commencé le test en réel après des back-test très prometteurs dimanche 11 novembre (paix aux guerriers européens) et j'ai gagné depuis l'ouverture dimanche soir : 29e, 78e, 11e, 159e et 200e et j'ai actuellement deux ordres en cours 41e et 47e avec u capital virtuel de départ de 4800e.

    J'ai découvert le site américain samedi après midi en cherchant un EA moyenne mobile sur le net , prenez un graphique en H1 ou D1 sur usd/cad , posez deux EMA 10 et 80 et regardez le potentiel de pips ....absolument monstrueux et ça sans se prendre la tête
    Je pense que les EMA sont ce qu'il y a de mieux car simple et très utiliser (d'après ce que j'ai pu lire ici et là)
    je pose le code du robot ici car je ne sais pas comment le partager ...
    Code
    //+------------------------------------------------------------------+ //| EMA_CROSS_2.mq4 | //| Coders Guru | //| http://www.forex-tsd.com | //+------------------------------------------------------------------+ #property copyright "Coders Guru" #property link "http://www.forex-tsd.com" #define MAGICMA 20060301 //---- Trades limits extern double TakeProfit=160; extern double TrailingStop=20; extern double StopLoss=70; extern bool UseStopLoss = false; //---- EMAs paris extern int ShortEma = 10; extern int LongEma = 80; //---- Crossing options extern bool immediate_trade = true; //Open trades immediately or wait for cross. extern bool reversal = true; //Use the originally reversal crossing method or not //---- Money Management extern double Lots = 1; extern bool MM = false; //Use Money Management or not extern bool AccountIsMicro = false; //Use Micro-Account or not extern int Risk = 15; //10% extern bool Show_Settings = true; //---- Global varaibles static int TimeFrame = 0; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- if(Show_Settings) Print_Details(); else Comment(""); //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- TimeFrame=Period(); //Prevent counting the cross while the user changing the timeframe //---- return(0); } bool isNewSumbol(string current_symbol) { //loop through all the opened order and compare the symbols int total = OrdersTotal(); for(int cnt = 0 ; cnt < total ; cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); string selected_symbol = OrderSymbol(); if (current_symbol == selected_symbol) return (False); } return (True); } int Crossed (double line1 , double line2) { static int last_direction = 0; static int current_direction = 0; if(TimeFrame!=Period()) { TimeFrame=Period(); return (0); } if(line1>line2)current_direction = 1; //up if(line1<line2)current_direction = 2; //down if(immediate_trade==false) { if(last_direction == 0) //first use { last_direction = current_direction; return(0); } } if(current_direction != last_direction) //changed { last_direction = current_direction; return (last_direction); } else { return (0); //not changed } } //--- Bassed on Alex idea! More ideas are coming double LotSize() { double lotMM = MathCeil(AccountFreeMargin() * Risk / 1000) / 100; if(AccountIsMicro==false) //normal account { if (lotMM < 0.1) lotMM = Lots; if (lotMM > 1.0) lotMM = MathCeil(lotMM); if (lotMM > 100) lotMM = 100; } else //micro account { if (lotMM < 0.01) lotMM = Lots; if (lotMM > 1.0) lotMM = MathCeil(lotMM); if (lotMM > 100) lotMM = 100; } return (lotMM); } string BoolToStr ( bool value) { if(value) return ("True"); else return ("False"); } void Print_Details() { string sComment = ""; string sp = "----------------------------------------\n"; string NL = "\n"; sComment = sp; sComment = sComment + "TakeProfit=" + DoubleToStr(TakeProfit,0) + " | "; sComment = sComment + "TrailingStop=" + DoubleToStr(TrailingStop,0) + " | "; sComment = sComment + "StopLoss=" + DoubleToStr(StopLoss,0) + " | "; sComment = sComment + "UseStopLoss=" + BoolToStr(UseStopLoss) + NL; sComment = sComment + sp; sComment = sComment + "immediate_trade=" + BoolToStr(immediate_trade) + " | "; sComment = sComment + "reversal=" + BoolToStr(reversal) + NL; sComment = sComment + sp; sComment = sComment + "Lots=" + DoubleToStr(Lots,0) + " | "; sComment = sComment + "MM=" + BoolToStr(MM) + " | "; sComment = sComment + "Risk=" + DoubleToStr(Risk,0) + "%" + NL; sComment = sComment + sp; Comment(sComment); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- int cnt, ticket, total; double SEma, LEma; string comment = ""; if(reversal==true) comment = "EMA_CROSS_Counter-Trend"; if(reversal==false) comment = "EMA_CROSS_Trend-Following"; if(Bars<100) { Print("bars less than 100"); return(0); } if(TakeProfit<10) { Print("TakeProfit less than 10"); return(0); // check TakeProfit } SEma = iMA(NULL,0,ShortEma,0,MODE_EMA,PRICE_CLOSE,0); LEma = iMA(NULL,0,LongEma,0,MODE_EMA,PRICE_CLOSE,0); static int isCrossed = 0; isCrossed = Crossed (LEma,SEma); if(reversal==false) { if(isCrossed==1) isCrossed=2; if(isCrossed==2) isCrossed=1; } if(MM==true) Lots = LotSize(); //Adjust the lot size total = OrdersTotal(); if(total < 1 || isNewSumbol(Symbol())) { if(isCrossed == 1) { if(UseStopLoss) ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,comment,MAGICMA,0,Green); else ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,comment,MAGICMA,0,Green); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice()); } else Print("Error opening BUY order : ",GetLastError()); return(0); } if(isCrossed == 2) { if(UseStopLoss) ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,comment,MAGICMA,0,Red); else ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,comment,MAGICMA,0,Red); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice()); } else Print("Error opening SELL order : ",GetLastError()); return(0); } return(0); } for(cnt=0;cnt<total;cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if(OrderType()<=OP_SELL && OrderSymbol()==Symbol()) { if(OrderType()==OP_BUY) // long position is opened { // check for trailing stop if(TrailingStop>0) { if(Bid-OrderOpenPrice()>Point*TrailingStop) { if(OrderStopLoss()<Bid-Point*TrailingStop) { OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green); return(0); } } } } else // go to short position { // check for trailing stop if(TrailingStop>0) { if((OrderOpenPrice()-Ask)>(Point*TrailingStop)) { if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0)) { OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red); return(0); } } } } } } return(0); } //+------------------------------------------------------------------+

    Il vous suffit de faire F4 sur mt4 et de créer u nouveau expert et de coller ce code, redémarrer mt4 et lancer le robot
    Modifié le 2012-11-12 16:58:19 par AliX : lien caché, pas content..
    Jerome a joint une image
    ea-macross-countertrend-6008
  • Amin

    Je vois que toi-aussi tu fais parti des couches-tard ! Bienvenue au club :).

    Sinon, merci pour le partage. Je vais y jeter un coup d'oeil; mais je n'ai entendu que du bien des EMA, du moment qu'elles sont configurées sur de longues périodes.
    Le must serait d'obtenir, par l'EA, un % de probabilité concernant la réalisation du trade.

    A bientôt.
  • Jerome

    Il faut a mon avis utiliser l'angle de coupe entre les deux EMA ... supérieur a 15° enfin je sais pas d'ailleurs je serais incapable de coder quelque chose mais merci de t’intéresser a ce petit joujou qui ravira les grands comme les petits.
  • Jerome

    J'ai trouvé un EA intéressant :

    Code
    //+------------------------------------------------------------------+ //| EMAAngle.mq4 | //| jpkfox | //| | //| You can use this indicator to measure when the EMA angle is | //| "near zero". AngleTreshold determines when the angle for the | //| EMA is "about zero": This is when the value is between | //| [-AngleTreshold, AngleTreshold] (or when the histogram is red). | //| EMAPeriod: EMA period | //| AngleTreshold: The angle value is "about zero" when it is | //| between the values [-AngleTreshold, AngleTreshold]. | //| StartEMAShift: The starting point to calculate the | //| angle. This is a shift value to the left from the | //| observation point. Should be StartEMAShift > EndEMAShift. | //| EndEMAShift: The ending point to calculate the | //| angle. This is a shift value to the left from the | //| observation point. Should be StartEMAShift > EndEMAShift. | //| | //| Modified by MrPip | //| Red for down | //| Yellow for near zero | //| Green for up | //| 10/15/05 MrPip | //| Corrected problem with USDJPY and optimized code | //| | //+------------------------------------------------------------------+ //mod2008fxtsd ki #property copyright "jpkfox" #property link "http://www.strategybuilderfx.com/forums/showthread.php?t=15274&page=1&pp=8" //---- indicator settings #property indicator_separate_window #property indicator_buffers 4 #property indicator_color1 Green #property indicator_color2 Red #property indicator_color3 Gold #property indicator_color4 DeepSkyBlue #property indicator_width1 2 #property indicator_width2 2 #property indicator_width3 2 #property indicator_width4 1 #property indicator_level1 0.3 #property indicator_level2 -0.3 //#property indicator_level3 0 #property indicator_levelcolor RoyalBlue //---- indicator parameters extern int MAPeriod=34; extern int MA_MODE=1;//0 sma; 1 ema; 2 smma; 3 lwma extern int MA_PRICE=0; extern double AngleTreshold=0.2; extern int StartMAShift=6; extern int EndMAShift=0; extern int SigMA_Period = 9; extern int SigMA_mode = 1;//0 sma; 1 ema; 2 smma; 3 lwma extern string MA_Mode__= "0-sma; 1 ema; 2 smma; 3 lwma"; extern string MA_Price_= "0C 1O 2H 3L 4Md 5Tp 6WghC: Md(HL/2)4,Tp(HLC/3)5,Wgh(HLCC/4)6"; //---- indicator buffers double UpBuffer[]; double DownBuffer[]; double ZeroBuffer[]; double SigMABuffer[]; double fAngle1[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- 2 additional buffers are used for counting. IndicatorBuffers(5); //---- drawing settings SetIndexStyle(0,DRAW_HISTOGRAM); SetIndexStyle(1,DRAW_HISTOGRAM); SetIndexStyle(2,DRAW_HISTOGRAM); SetIndexStyle(3,DRAW_LINE); //---- 3 indicator buffers mapping if(!SetIndexBuffer(0,UpBuffer) && !SetIndexBuffer(1,DownBuffer) && !SetIndexBuffer(3,SigMABuffer) && !SetIndexBuffer(4,fAngle1) && !SetIndexBuffer(2,ZeroBuffer)) Print("cannot set indicator buffers!"); //---- name for DataWindow and indicator subwindow label IndicatorShortName("MA_AngleZero ("+MAPeriod+", "+DoubleToStr(AngleTreshold,2)+", "+SigMA_Period+")"); SetIndexLabel(0,""); SetIndexLabel(1,""); SetIndexLabel(2,""); SetIndexLabel(3,"SigL"); IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2); //---- initialization done return(0); } //+------------------------------------------------------------------+ //| The angle for EMA | //+------------------------------------------------------------------+ int start() { double fEndMA, fStartMA; double fAngle, mFactor, dFactor; int nLimit, i; int nCountedBars; double angle; int ShiftDif; if(EndMAShift >= StartMAShift) { Print("Error: EndEMAShift >= StartEMAShift"); StartMAShift = 6; EndMAShift = 0; } nCountedBars = IndicatorCounted(); //---- check for possible errors if(nCountedBars<0) return(-1); //---- last counted bar will be recounted if(nCountedBars>0) nCountedBars--; nLimit = Bars-nCountedBars; dFactor = 3.14159/180.0; mFactor = 10000.0; // if (Symbol() == "USDJPY") mFactor = 100.0; ShiftDif = StartMAShift-EndMAShift; mFactor /= ShiftDif; //---- main loop for(i=0; i<nLimit; i++) { fEndMA=iMA(NULL,0,MAPeriod,0,MA_MODE,MA_PRICE,i+EndMAShift); fStartMA=iMA(NULL,0,MAPeriod,0,MA_MODE,MA_PRICE,i+StartMAShift); // 10000.0 : Multiply by 10000 so that the fAngle is not too small // for the indicator Window. if(fStartMA!= 0) fAngle = mFactor * (fEndMA - fStartMA)/fStartMA; // fAngle = mFactor * (fEndMA - fStartMA); // fAngle = MathArctan(fAngle)/dFactor; fAngle1[i]=fAngle; DownBuffer[i] = 0.0; UpBuffer[i] = 0.0; ZeroBuffer[i] = 0.0; if(fAngle > AngleTreshold) UpBuffer[i] = fAngle; else if (fAngle < -AngleTreshold) DownBuffer[i] = fAngle; else ZeroBuffer[i] = fAngle; } // nLimit = Bars-nCountedBars+SigMA_Period; for(i=0; i<nLimit; i++) { SigMABuffer[i]=iMAOnArray(fAngle1,0,SigMA_Period,0,SigMA_mode,i); } return(0); } //+------------------------------------------------------------------+
  • belgam

    Salut Jérome !

    Merci pour le partage. Aurais-tu un MyFx stp ?
  • Jerome

    Non désolé je n'ai pas ça .
  • furynick

    Pour ton problème de SL sur le 1er EA, tu ne serais pas sur un broker à 5 digits par hasard qui n'autoriserai pas les SL à moins de 2 pips de la cotation courante ?

    Pour rappel, 20 pips sur un 5 digits c'est 200 points, il faut donc que tu multiplies toutes tes valeurs par 10 ... ou que tu ajoutes la conversion pips/points telle que je l'avais proposée ;)
  • Jerome

    Ah !! merci !!! d'où l'erreur 130 .... :)
  • furynick — en réponse à Jerome dans son message #61215

    Jerome, le 12/11/2012 dit :
    Ah !! merci !!! d'où l'erreur 130 .... :)


    Exact, le code 130 indique un TP/SL incorrect.
  • Jerome

    Merci pour tes conseils Furynick
    J'ai modifié le stop loss a 100 donc ça joue!
    J'ai aussi mis "reversal" false donc je trade dans la tendance
    Tp 100 mais je pourrais mettre plus après car pour l'instant je test la configuration et voir si l'Ea prend les ordres comme je le souhaite
    J'ai mis false pour "immediate trade" car l'EA prenait un trade lorsque la bougie du cours venait frappé l'EMA 80 et non lors du croisement avec l'EMA 10 mais je pense qu'il est souhaitable de mettre true lorsque l'on trade en D1 car TRES rarement l'EMA 10 frôle L'EMA 80
    Maintenant je test pendant la semaine

    ps : comment puis je poster l'EA pour le partager ?
  • belgam

    Pour ta derniere question, je dirais comme tu l'as fais précédement :)

    Un bon vieux copier/coller ! Merci en tout cas pour ton partage.
  • savabien

    merci pour la partage, j'attend sagement le futur post de Jérome avec ces modification apportées pour backtester tout cela...
  • Jerome

    aie, je n'ai pas réussi a intégrer l'angle de coupe car je ne sais pas comment faire ...
    Souvent l'ema 10 coupe l'ema 80 plusieurs fois en peu de temps ce qui me cause des pertes (SL) alors que si l'ordre d'achat était vérifié en paramétrant la valeur angulaire cela augmenterai significativement la fiabilité des prises de positions.
    Attendons le bon samaritain :)
  • Jerome

    Je tiens a préciser qu'en D1 le problème ne se pose pas