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

Base simple pour fabriquer un Robot

  • lefeuvr3

    Il suffit d’insérer votre statégie à la place de... if((Bid>iOpen(Symbol(),0,0))) et de if((Bid<iOpen(Symbol(),0,0))) dans le programme qui suit :
    Ici le cours actuel [ Bid ] est supérieur au cours d'ouverture pour l'achat de la bougie en cours pour l'achat et le contraire pour la vente.
    Code
    //+------------------------------------------------------------------+ //| BASE SANS SORTIE SANS AMM.mq4 | //| Copyright 2019, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2019, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" //#property strict //+------------------------------------------------------------------+ extern int MagicNumber=10001; extern double Lots =0.1; extern double StopLoss=50; extern double TakeProfit=50; extern int TrailingStop=50; extern int Slippage=3; //+------------------------------------------------------------------+ // 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//Ici votre strategie d'achat if((Bid>iOpen(Symbol(),0,0))) //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ { result=OrderSend(Symbol(),OP_BUY,Lots,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)) bool modif1= OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green); } return(0); } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ // Here is your open Sell rule//Ici votre strategie de vente if((Bid<iOpen(Symbol(),0,0))) //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ { result=OrderSend(Symbol(),OP_SELL,Lots,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)) 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)) if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber ) { if(OrderType()==OP_BUY) { 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(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)) if (OrderMagicNumber()==MagicNumber) result++; } return (result); }

    Amusez vous bien ! :)
    Modifié le 2019-11-02 12:34:04 par lefeuvr3 : faute de frappe
  • lefeuvr3

    rappel ...pas de backtest le week end
  • lefeuvr3

    Si cela vous intérresse ,je peux mettre une base avec sortie symétrique ou avec avec "advanced money management"
  • lefeuvr3

    BASE AVEC SORTIE SANS AMM.....entrée et sortie se font par la stratégie plus que par les takeprofit,stoploss ou trailingstop

    Il suffit d’insérer votre statégie à la place de... if((Bid>iOpen(Symbol(),0,0))) , de if((Bid<iOpen(Symbol(),0,0))) ,dans le programme qui suit :
    Ici le cours actuel [ Bid ] est supérieur au cours d'ouverture pour l'achat de la bougie en cours pour l'achat et le contraire pour la vente.

    Code
    //+------------------------------------------------------------------+ //| BASE AVEC SORTIE SANS AMM.mq4 | //| Copyright 2019, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2019, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" //#property strict //+------------------------------------------------------------------+ extern int MagicNumber=10001; extern double Lots =0.1; extern double StopLoss=50; extern double TakeProfit=50; extern int TrailingStop=50; extern int Slippage=3; //+------------------------------------------------------------------+ // 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//Ici votre strategie d'achat if((Bid>iOpen(Symbol(),0,0))) //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ { result=OrderSend(Symbol(),OP_BUY,Lots,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)) bool modif1= OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green); } return(0); } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ // Here is your open Sell rule//Ici votre strategie de vente if((Bid<iOpen(Symbol(),0,0))) //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ { result=OrderSend(Symbol(),OP_SELL,Lots,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)) 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)) if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber ) { if(OrderType()==OP_BUY) { //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //here is your close buy rule//Ici strategie de fin d'achat if((Bid<iOpen(Symbol(),0,0))) //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ { bool modif3= OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red); } if(TrailingStop>0) { if(Bid-OrderOpenPrice()>MyPoint*TrailingStop) { if(OrderStopLoss()<Bid-MyPoint*TrailingStop) { bool modif4= OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*MyPoint,OrderTakeProfit(),0,Green); return(0); } } } } else { //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ // here is your close sell rule/Ici strategie de fin de vente if((Bid>iOpen(Symbol(),0,0))) //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ { bool modif5=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red); } if(TrailingStop>0) { if((OrderOpenPrice()-Ask)>(MyPoint*TrailingStop)) { if((OrderStopLoss()>(Ask+MyPoint*TrailingStop)) || (OrderStopLoss()==0)) { bool modif6= 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)) if (OrderMagicNumber()==MagicNumber) result++; } return (result); }
    Modifié le 2019-11-02 15:38:07 par lefeuvr3