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

Modification du Grid Template EA

  • lefeuvr3

    https://www.mql5.com/en/code/26718

    - Ajustement de la taille des lots en fonction de l' Equity
    - mise en place d'un Trailing stop
    //+------------------------------------------------------------------+
    Code
    //+------------------------------------------------------------------+ //| Grid_Template.mq4 | //| Copyright 2019, DKP Sweden,CS Robots | //| https://www.mql5.com/en/users/kenpar | //+------------------------------------------------------------------+ //-------------------------------------------------------------------- #property copyright "Copyright 2019,DKP Sweden | CS Robots" #property link "http://www.mql5.com/en/users/kenpar" #property version "1.00" #property description "Grid Template EA" #property strict //--External variables extern int MagicNumber = 987654321;//Magic number extern string EaComment = "Grid_Template";//Order comment extern bool trail=true; extern double TrailingStop=40; extern double TakeProfit = 100.;//Take Profit in pips extern double StopLoss = 80;//Stop loss in pips extern double PriceDistance = 12;//Distance from price in pips extern double GridStep = 4;//Step between grid orders in pips extern int GridOrders = 5;//Amount of grid orders int PendingExpiration = 4;//Pending expiration after xx hours extern int LotFactor =80; //--Internal variables double PriceB,PriceS,StopB,StopS, TakeB,TakeS,_points,PT,Lots; int LotDigits; datetime _e = 0; int Ticket = 0; //-- int OnInit() { //--Determine digits _points=MarketInfo(Symbol(),MODE_POINT); //-- if(Digits==5 || Digits==3) PT = _points*10; else PT = _points; //-- return(INIT_SUCCEEDED); } //-- void OnDeinit(const int reason) { } //-- void OnTick() { //If trade allowed and no positions exists by any chart - open a new set of grid orders if(IsTradeAllowed() && !IsTradeContextBusy()) if(trail) trail(); { if(PosSelect()==0) { GridPos(PriceDistance,TakeProfit,StopLoss);//Place grid } return; } } /////////////////////////////////////////////////////////// //Grid order send function void GridPos(double _Dist,double _Take,double _Stop) { int i; _e=TimeCurrent()+PendingExpiration*60*60; //-- for(i=0; i<GridOrders; i++) { PriceB = NormalizeDouble(Ask+(_Dist*PT)+(i*GridStep*PT),Digits); TakeB = PriceB + _Take * PT; StopB = PriceB - _Stop * PT; Ticket=OrderSend(Symbol(),OP_BUYSTOP,(AccountEquity() * 0.01 /LotFactor),PriceB,3,StopB,TakeB,EaComment,MagicNumber,_e,Green); //-- PriceS = NormalizeDouble(Bid-(_Dist*PT)-(i*GridStep*PT),Digits); TakeS = PriceS - _Take * PT; StopS = PriceS + _Stop * PT; Ticket=OrderSend(Symbol(),OP_SELLSTOP,(AccountEquity() * 0.01 /LotFactor),PriceS,3,StopS,TakeS,EaComment,MagicNumber,_e,Red); } if(Ticket<1) { Print("Order send error - errcode: ",GetLastError()); return; } else { Print("Grid placed successfully!"); } return; } ////////////////////////////////////////////////////////// //PositionSelector - Determines open positions int PosSelect() { int posi=0; for(int k = OrdersTotal() - 1; k >= 0; k--) { if(!OrderSelect(k, SELECT_BY_POS)) { Print("Order pos selection failed - errcode: ",GetLastError()); } if(OrderSymbol()!=Symbol()&&OrderMagicNumber()!=MagicNumber) { continue; } if(OrderCloseTime() == 0 && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) { if(OrderType() == OP_BUY) posi = 1; //Long position if(OrderType() == OP_SELL) posi = -1; //Short positon if(OrderType() == OP_BUYSTOP) posi = 1; //Pending Long position if(OrderType() == OP_SELLSTOP) posi = -1; //Pending Short positon } } return(posi); } //+----------------End of Grid Template EA-------------------+ //+------------------------------------------------------------------+ //| Trailing Stoploss après Breakeven | //+------------------------------------------------------------------+ void trail() { for (int i = OrdersTotal()-1; i >= 0; i --) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==Symbol()) { if(OrderType()==OP_BUY) { if(Bid - OrderOpenPrice() > TrailingStop *10* MarketInfo(OrderSymbol(),MODE_POINT)) { if(((OrderStopLoss() < Bid - TrailingStop *10* MarketInfo(OrderSymbol(), MODE_POINT))&& ((Bid-OrderOpenPrice())>(Point*TrailingStop)))|| (OrderStopLoss()==0)) { bool modify1=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*10*MarketInfo(OrderSymbol(),MODE_POINT),OrderTakeProfit(),clrGreenYellow); } } } else if(OrderType()==OP_SELL) { if(OrderOpenPrice()-Ask>TrailingStop*10*MarketInfo(OrderSymbol(),MODE_POINT)) { if(((OrderStopLoss()>Ask+TrailingStop*10*MarketInfo(OrderSymbol(),MODE_POINT))&& ((OrderOpenPrice()-Ask)>(Point*TrailingStop)))|| (OrderStopLoss()==0)) { bool modify2=OrderModify(OrderTicket(),OrderOpenPrice(), Ask+TrailingStop*10*MarketInfo(OrderSymbol(),MODE_POINT),OrderTakeProfit(),clrGreenYellow); } } } } } } //+------------------------------------------------------------------+
    Modifié le 2020-02-25 13:56:55 par lefeuvr3 : erreur sur balise
    lefeuvr3 a joint une image
    modification-du-grid-template-ea-12009
  • Matthieuw31

    Bonjour Lefeuvr3!

    Surprenant un si bon résultat de backtest pour une telle méthode. As-tu testé le programme en vrai? Si oui, as-tu de bons résultats?
    Combien de temps mets-tu pour simuler 1 an avec une précision au tick? Quand je backteste au tick, mon ordi passe 1h pour simuler 1 journée! (J'ai un vieil ordi de plus de 10 ans!)
  • lefeuvr3

    Le backtest a été effectué avec l'historique du broker ...il faut le refaire avec Tickstory pour avoir un modelage de 99.90%...A cette epoque ,je n'avais pas percu l'importance de ce critère tout comme pour l'ecart (spread) qui doit être au moins a 10
  • belgam

    Hello.

    25% modeling c’est trop peu pour se fier. Je vais recuperer ton code et le backtest avec tickstory.

    Peux tu me dire quel set tu veux que je test ?
    TF
    Paires
    Sur combien d’années.
  • lefeuvr3

    Salut Belgam
    Un Backtest sur 6 mois me suffit avec eurusd 1 minute
    Merci pour ta collaboration ...je vais essayer de l' ameliorer avec une douce martingale
  • lefeuvr3

    Nouvelle version avec martingale
    Cette nouvelle version me fait un peu peur
    Code
    //+------------------------------------------------------------------+ //| Grid_Template _Martingale.mq4 | //| Copyright 2020, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| Grid_Template.mq4 | //| Copyright 2019, DKP Sweden,CS Robots | //| https://www.mql5.com/en/users/kenpar | //+------------------------------------------------------------------+ //-------------------------------------------------------------------- #property copyright "Copyright 2019,DKP Sweden | CS Robots" #property link "http://www.mql5.com/en/users/kenpar" #property version "1.00" #property description "Grid Template EA" #property strict //--External variables extern int MagicNumber = 987654321;//Magic number extern string EaComment = "Grid_Template";//Order comment extern bool trail=true; extern double StopLoss=72; extern double TakeProfit=87; extern int TrailingStop=50; extern double martingale =2.6; double last_profit, last_lot; int last_tip; extern double LotFactor = 310; extern int Slippage=3; extern double PriceDistance = 26;//Distance from price in pips extern double GridStep = 3;//Step between grid orders in pips extern int GridOrders = 6;//Amount of grid orders int PendingExpiration = 4;//Pending expiration after xx hours //--Internal variables double PriceB,PriceS,StopB,StopS, TakeB,TakeS,_points,PT,Lots; int LotDigits; datetime _e = 0; int Ticket = 0; //-- int OnInit() { //--Determine digits _points=MarketInfo(Symbol(),MODE_POINT); //-- if(Digits==5 || Digits==3) PT = _points*10; else PT = _points; //-- return(INIT_SUCCEEDED); } //-- void OnDeinit(const int reason) { } //-- void OnTick() { //If trade allowed and no positions exists by any chart - open a new set of grid orders if(IsTradeAllowed() && !IsTradeContextBusy()) if(trail) trail(); { if(PosSelect()==0) { GridPos(PriceDistance,TakeProfit,StopLoss);//Place grid } return; } } /////////////////////////////////////////////////////////// //Grid order send function void GridPos(double _Dist,double _Take,double _Stop) { //============================================================================ double llots = (AccountBalance() * 0.01 /LotFactor); if( OrdersTotal() == 0 && OrdersHistoryTotal() == 0) llots =/* Lots*/(AccountBalance() * 0.01 /LotFactor); else if( OrdersTotal() == 0&& OrdersHistoryTotal() > 0 ) last_history_profit(); if( last_profit < 0 ) llots = martingale*last_lot; if( last_profit > 0 ) llots = (AccountBalance() * 0.01 /LotFactor); //============================================================================ int i; _e=TimeCurrent()+PendingExpiration*60*60; //-- for(i=0; i<GridOrders; i++) { PriceB = NormalizeDouble(Ask+(_Dist*PT)+(i*GridStep*PT),Digits); TakeB = PriceB + _Take * PT; StopB = PriceB - _Stop * PT; Ticket=OrderSend(Symbol(),OP_BUYSTOP,llots,PriceB,3,StopB,TakeB,EaComment,MagicNumber,_e,Green); //-- PriceS = NormalizeDouble(Bid-(_Dist*PT)-(i*GridStep*PT),Digits); TakeS = PriceS - _Take * PT; StopS = PriceS + _Stop * PT; Ticket=OrderSend(Symbol(),OP_SELLSTOP,llots,PriceS,3,StopS,TakeS,EaComment,MagicNumber,_e,Red); } if(Ticket<1) { Print("Order send error - errcode: ",GetLastError()); return; } else { Print("Grid placed successfully!"); } return; } ////////////////////////////////////////////////////////// //PositionSelector - Determines open positions int PosSelect() { int posi=0; for(int k = OrdersTotal() - 1; k >= 0; k--) { if(!OrderSelect(k, SELECT_BY_POS)) { Print("Order pos selection failed - errcode: ",GetLastError()); } if(OrderSymbol()!=Symbol()&&OrderMagicNumber()!=MagicNumber) { continue; } if(OrderCloseTime() == 0 && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) { if(OrderType() == OP_BUY) posi = 1; //Long position if(OrderType() == OP_SELL) posi = -1; //Short positon if(OrderType() == OP_BUYSTOP) posi = 1; //Pending Long position if(OrderType() == OP_SELLSTOP) posi = -1; //Pending Short positon } } return(posi); } //+----------------End of Grid Template EA-------------------+ //+------------------------------------------------------------------+ //| Trailing Stoploss après Breakeven | //+------------------------------------------------------------------+ void trail() { for (int i = OrdersTotal()-1; i >= 0; i --) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==Symbol()) { if(OrderType()==OP_BUY) { if(Bid - OrderOpenPrice() > TrailingStop *10* MarketInfo(OrderSymbol(),MODE_POINT)) { if(((OrderStopLoss() < Bid - TrailingStop *10* MarketInfo(OrderSymbol(), MODE_POINT))&& ((Bid-OrderOpenPrice())>(Point*TrailingStop)))|| (OrderStopLoss()==0)) { bool modify1=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*10*MarketInfo(OrderSymbol(),MODE_POINT),OrderTakeProfit(),clrGreenYellow); } } } else if(OrderType()==OP_SELL) { if(OrderOpenPrice()-Ask>TrailingStop*10*MarketInfo(OrderSymbol(),MODE_POINT)) { if(((OrderStopLoss()>Ask+TrailingStop*10*MarketInfo(OrderSymbol(),MODE_POINT))&& ((OrderOpenPrice()-Ask)>(Point*TrailingStop)))|| (OrderStopLoss()==0)) { bool modify2=OrderModify(OrderTicket(),OrderOpenPrice(), Ask+TrailingStop*10*MarketInfo(OrderSymbol(),MODE_POINT),OrderTakeProfit(),clrGreenYellow); } } } } } } //+------------------------------------------------------------------+ //============================================================================ double last_history_profit() { double cpte_profit = 0; //int Magik_No = -1; if( OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY) ) { if( OrderMagicNumber() == MagicNumber ) { last_profit = OrderProfit(); last_lot = OrderLots(); last_tip = OrderType(); } } return(0); } //
    lefeuvr3 a joint une image
    modification-du-grid-template-ea-12525
  • Mikiburger

    Ce type de stratégie peut être rentable mais il faut accepter le risque de crasher son compte de temps en temps.
    Un retrait d'argent régulier est a conseiller sur un compte réel.
    Une fois récupéré votre mise de départ et que vous ne traderez plus qu'avec l'argent gagné, vous serez plus serein.

    On peut diminuer le risque en évitant de trader lors des annonces importantes.
    Le moins risqué est de trader uniquement lors du marché asiatique. Mais ça gagne beaucoup moins aussi.
  • lefeuvr3

    Mikiburger , je suis tout a fait d'accord avec toi.
  • belgam

    Hello !

    période : 2020-06-18 // 2020-12-26
    1er : Modification Grid Template EA-M1-EURUSD-6mois
    2eme : Modification Grid Template EA Martingale-M1-EURUSD-6mois
    belgam a joint une image
    modification-du-grid-template-ea-12527
  • belgam

    2eme
    belgam a joint une image
    modification-du-grid-template-ea-12528